Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions v2 #156

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@contentauth/toolkit",
"comment": "Add types for c2pa.actions.v2",
"type": "patch"
}
],
"packageName": "@contentauth/toolkit"
}
10 changes: 10 additions & 0 deletions common/changes/c2pa/actions-v2_2024-04-05-16-41.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "c2pa",
"comment": "Add support for c2pa.actions.v2 in selectEditsAndActivity",
"type": "patch"
}
],
"packageName": "c2pa"
}
16 changes: 12 additions & 4 deletions packages/c2pa/src/selectors/selectEditsAndActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
* it.
*/

import { ActionV1, C2paActionsAssertion } from '@contentauth/toolkit';
import {
ActionV1,
ActionV2,
C2paActionsAssertion,
C2paActionsAssertionV2,
} from '@contentauth/toolkit';
import debug from 'debug';
import each from 'lodash/each';
import compact from 'lodash/fp/compact';
Expand Down Expand Up @@ -127,7 +132,10 @@ export async function selectEditsAndActivity(
manifest.assertions.get('com.adobe.dictionary')[0] ??
manifest.assertions.get('adobe.dictionary')[0];

const [actionAssertion] = manifest.assertions.get('c2pa.actions');
const [actionsV2] = manifest.assertions.get('c2pa.actions.v2');
const [actionsV1] = manifest.assertions.get('c2pa.actions');

const actionAssertion = actionsV2 ?? actionsV1;

if (!actionAssertion) {
return null;
Expand All @@ -146,7 +154,7 @@ export async function selectEditsAndActivity(
}

async function getPhotoshopCategorizedActions(
actions: ActionV1[],
actions: ActionV1[] | ActionV2[],
dictionaryUrl: string,
locale = DEFAULT_LOCALE,
iconVariant: IconVariant = 'dark',
Expand Down Expand Up @@ -196,7 +204,7 @@ interface OverrideActionMap {
* @returns List of translated action categories
*/
export function getC2paCategorizedActions(
actionsAssertion: C2paActionsAssertion,
actionsAssertion: C2paActionsAssertion | C2paActionsAssertionV2,
locale: string = DEFAULT_LOCALE,
): TranslatedDictionaryCategory[] {
const actions = actionsAssertion.data.actions as AdobeCompatAction[];
Expand Down
36 changes: 36 additions & 0 deletions packages/toolkit/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export type C2paActionsAssertion = Assertion<
}
>;

export type C2paActionsAssertionV2 = Assertion<
'c2pa.actions.v2',
{
actions: ActionV2[];
}
>;

export type C2paHashDataAssertion = Assertion<
'c2pa.hash.data',
{
Expand Down Expand Up @@ -130,10 +137,39 @@ export type Web3Assertion = Assertion<

export type ManifestAssertion =
| C2paActionsAssertion
| C2paActionsAssertionV2
| C2paHashDataAssertion
| CreativeWorkAssertion
| Web3Assertion;

export interface ActionV2 {
action: string;
softwareAgent?: GeneratorInfoMap | string;
description?: string;
digitalSourceType?: string;
when?: string;
changes?: Change[];
actors?: Actor[];
related?: ActionV2[];
reason?: string;
parameters?: ParametersV2;
}
interface ParametersV2 {
ingredient?: HashedUri;
description?: string;
[key: string]: any;
}

interface Change {
[key: string]: any;
}

interface GeneratorInfoMap {
name: string;
version: string;
[key: string]: any;
}

export interface ActionV1 {
action: string;
softwareAgent?: string;
Expand Down
Loading