Skip to content

Commit fc7ecbe

Browse files
authored
Update manifest-tasks.mdx
Add JavaScript
1 parent 79228a2 commit fc7ecbe

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs/manifest/manifest-tasks.mdx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,43 @@ import TabItem from '@theme/TabItem';
1111
<Tabs groupId="programming-lang">
1212

1313
<TabItem value="js" label="JavaScript" default>
14-
This is how to read a manifest using JavaScript.
14+
15+
If the input provided to [`c2pa.read`](../../js-sdk/api/c2pa.c2pa#methods) has a C2PA manifest and was processed without errors, the returned [`c2paReadResult`](../../js-sdk/api/c2pa.c2pareadresult) contains a [`manifestStore`](../../js-sdk/api/c2pa.c2pareadresult.manifeststore).
16+
17+
The [`manifestStore`](../../js-sdk/api/c2pa.c2pareadresult.manifeststore) object contains a few properties:
18+
19+
- **manifests**: An object containing _all_ manifests found in an asset, keyed by UUID.
20+
- **activeManifest**: A pointer to the latest [`manifest`](../../js-sdk/api/c2pa.manifest) in the manifest store. Effectively the "parent" manifest, this is the likely starting point when inspecting an asset's C2PA data.
21+
- **validationStatus**: A list of any validation errors the library generated when processing an asset. See [Validation](./validation) for more information.
22+
23+
[`Manifest`](../../js-sdk/api/c2pa.manifest) objects contain properties pertaining to an asset's provenance, along with convenient interfaces for [accessing assertion data](../../js-sdk/api/c2pa.assertionaccessor) and [generating a thumbnail](../../js-sdk/api/c2pa.thumbnail).
24+
25+
```js
26+
const { manifestStore, source } = await c2pa.read(sampleImage);
27+
const activeManifest = manifestStore?.activeManifest;
28+
if (activeManifest) {
29+
// Get thumbnail
30+
// Note: You would normally call `dispose()` when working with a
31+
// component-based UI library (e.g. on component un-mount)
32+
// @ts-expect-error noUnusedLocals
33+
const { url, dispose } = source.thumbnail.getUrl();
34+
35+
// Get properties
36+
const properties: Record<string, string | undefined> = {
37+
title: activeManifest.title,
38+
format: activeManifest.format,
39+
claimGenerator: activeManifest.claimGenerator.split('(')[0]?.trim(),
40+
producer: selectProducer(activeManifest)?.name ?? 'Unknown',
41+
thumbnail: `<img src="${url}" class="thumbnail" />`,
42+
ingredients: (activeManifest.ingredients ?? [])
43+
.map((i) => i.title)
44+
.join(', '),
45+
signatureIssuer: activeManifest.signatureInfo?.issuer,
46+
signatureDate: activeManifest.signatureInfo?.time
47+
? parseISO(activeManifest.signatureInfo.time).toString()
48+
: 'No date available',
49+
};
50+
```
1551
</TabItem>
1652
1753
<TabItem value="python" label="Python">

0 commit comments

Comments
 (0)