Some refactoring of C2PA code
This commit is contained in:
parent
5c559a98ad
commit
5f26534ed1
1 changed files with 18 additions and 62 deletions
|
|
@ -163,23 +163,6 @@ const getExifMakeModel = (ignoredvalue: any, match: FlagMatchRuleValue): string
|
||||||
return makeAndModel;
|
return makeAndModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ruleScreenshotC2PA = (): FlagMatchRule[] => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
field:
|
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/digitalSourceType",
|
|
||||||
match: [C2PASourceTypeScreenCapture],
|
|
||||||
description: "Screen capture",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field:
|
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType",
|
|
||||||
match: [C2PASourceTypeScreenCapture],
|
|
||||||
description: "Screen capture",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const ruleScreenshotMeta = (): FlagMatchRule[] => {
|
const ruleScreenshotMeta = (): FlagMatchRule[] => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
@ -191,40 +174,6 @@ const ruleScreenshotMeta = (): FlagMatchRule[] => {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const ruleCamera = (): FlagMatchRule[] => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
field:
|
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/digitalSourceType",
|
|
||||||
match: [C2PASourceTypeDigitalCapture, C2PASourceTypeComputationalCapture, C2PASourceTypeCompositeCapture],
|
|
||||||
description: "Captured by camera",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field:
|
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType",
|
|
||||||
match: [C2PASourceTypeDigitalCapture, C2PASourceTypeComputationalCapture, C2PASourceTypeCompositeCapture],
|
|
||||||
description: "Captured by camera",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const ruleAiGenerated = (): FlagMatchRule[] => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
field:
|
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/digitalSourceType",
|
|
||||||
match: [C2PASourceTypeTrainedAlgorithmicMedia, C2PASourceTypeCompositeWithTrainedAlgorithmicMedia],
|
|
||||||
description: "Generated by AI",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field:
|
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType",
|
|
||||||
match: [C2PASourceTypeTrainedAlgorithmicMedia, C2PASourceTypeCompositeWithTrainedAlgorithmicMedia],
|
|
||||||
description: "Generated by AI",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const ruleAiMeta = (): FlagMatchRule[] => {
|
const ruleAiMeta = (): FlagMatchRule[] => {
|
||||||
const knownAIServices = [
|
const knownAIServices = [
|
||||||
"ChatGPT",
|
"ChatGPT",
|
||||||
|
|
@ -422,25 +371,32 @@ export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let generator: ProofHintFlagsGenerator = matchFlag(ruleAiGenerated(), rootMatchPath).result ? "ai" : matchFlag(ruleScreenshotC2PA(), rootMatchPath).result ? "screenshot" : matchFlag(ruleCamera(), rootMatchPath).result ? "camera" : "unknown";
|
|
||||||
|
let generator: ProofHintFlagsGenerator = "unknown";
|
||||||
let generatorSource: ProofHintFlagSource | undefined = undefined;
|
let generatorSource: ProofHintFlagSource | undefined = undefined;
|
||||||
|
|
||||||
if (generator !== "unknown" && valid) {
|
let digitalSourceType = extractFlagValues("integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions|c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType", rootMatchPath)?.at(0)?.value as string;
|
||||||
|
if ([C2PASourceTypeScreenCapture].includes(digitalSourceType)) {
|
||||||
|
generator = "screenshot";
|
||||||
generatorSource = "c2pa";
|
generatorSource = "c2pa";
|
||||||
} else {
|
} else if ([C2PASourceTypeDigitalCapture, C2PASourceTypeComputationalCapture, C2PASourceTypeCompositeCapture].includes(digitalSourceType)) {
|
||||||
if (matchFlag(ruleScreenshotMeta(), rootMatchPath).result) {
|
generator = "camera";
|
||||||
generator = "screenshot";
|
generatorSource = "c2pa";
|
||||||
generatorSource = "metadata";
|
} else if ([C2PASourceTypeTrainedAlgorithmicMedia, C2PASourceTypeCompositeWithTrainedAlgorithmicMedia].includes(digitalSourceType)) {
|
||||||
} else if (matchFlag(ruleAiMeta(), rootMatchPath).result) {
|
generator = "ai";
|
||||||
generator = "ai";
|
generatorSource = "c2pa";
|
||||||
generatorSource = "metadata";
|
} else if (matchFlag(ruleScreenshotMeta(), rootMatchPath).result) {
|
||||||
}
|
generator = "screenshot";
|
||||||
|
generatorSource = "metadata";
|
||||||
|
} else if (matchFlag(ruleAiMeta(), rootMatchPath).result) {
|
||||||
|
generator = "ai";
|
||||||
|
generatorSource = "metadata";
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error("PROOF", proof);
|
console.error("PROOF", proof);
|
||||||
|
|
||||||
const c2paEdits = extractFlagValues(
|
const c2paEdits = extractFlagValues(
|
||||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[!!action=c2pa.created]",
|
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions|c2pa.actions.v2]/data/actions[!!action=c2pa.created]",
|
||||||
rootMatchPath
|
rootMatchPath
|
||||||
);
|
);
|
||||||
if (c2paEdits.length > 0) {
|
if (c2paEdits.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue