More work on sending/reading proof hint flags
This commit is contained in:
parent
dd76692640
commit
66eef037e0
9 changed files with 267 additions and 219 deletions
|
|
@ -60,6 +60,9 @@ export type Proof = {
|
|||
};
|
||||
|
||||
export type ProofHintFlags = {
|
||||
valid: boolean;
|
||||
source?: string;
|
||||
creationDate?: Date;
|
||||
aiGenerated?: boolean;
|
||||
aiEdited?: boolean;
|
||||
screenshot?: boolean;
|
||||
|
|
@ -150,10 +153,11 @@ const matchFlag = (rules: FlagMatchRule[], file: any) => {
|
|||
values.forEach((v) => {
|
||||
re.forEach((r) => {
|
||||
if (r.test(v.value)) {
|
||||
resultInfo.push({ field: v.path, value: v.value, re: r.source })
|
||||
result = true;
|
||||
resultInfo.push({ field: v.path, value: v.value, re: r.source });
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Invalid RE", e);
|
||||
}
|
||||
|
|
@ -162,7 +166,12 @@ const matchFlag = (rules: FlagMatchRule[], file: any) => {
|
|||
};
|
||||
|
||||
const extractFlagValues = (flagPath: string, file: any): FlagMatchRuleValue[] => {
|
||||
const getValues = (path: string[], objectPath: any[], actualPath: string, o: any): FlagMatchRuleValue[] | undefined => {
|
||||
const getValues = (
|
||||
path: string[],
|
||||
objectPath: any[],
|
||||
actualPath: string,
|
||||
o: any
|
||||
): FlagMatchRuleValue[] | undefined => {
|
||||
if (path.length == 0 || o == undefined) return undefined;
|
||||
let part = path[0];
|
||||
const lastBracket = part.lastIndexOf("[");
|
||||
|
|
@ -189,7 +198,7 @@ const extractFlagValues = (flagPath: string, file: any): FlagMatchRuleValue[] =>
|
|||
return strings.map((s, i) => ({ path: actualPath + "/" + part + "[" + i + "]", value: s }));
|
||||
} else {
|
||||
return opart.reduce((res: FlagMatchRuleValue[] | undefined, o: any, i: number) => {
|
||||
const newObjectPaths = [o, ...objectPath];
|
||||
const newObjectPaths = [o, ...objectPath];
|
||||
let matches = getValues(path.slice(1), newObjectPaths, actualPath + "/" + part + "[" + i + "]", o);
|
||||
if (matches) {
|
||||
const r2 = res || [];
|
||||
|
|
@ -237,19 +246,34 @@ export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined
|
|||
if (results) {
|
||||
valid = results.failure.length == 0 && results.success.length > 0;
|
||||
}
|
||||
if (valid) {
|
||||
|
||||
const dateCreated = extractFlagValues("integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/../../../../signature_info/time", proof);
|
||||
console.log("DATE CREATED", dateCreated);
|
||||
const source = extractFlagValues(
|
||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/softwareAgent",
|
||||
proof
|
||||
);
|
||||
|
||||
const flags: ProofHintFlags = {
|
||||
aiGenerated: matchFlag(ruleAiGenerated(), proof).result,
|
||||
aiEdited,
|
||||
screenshot: matchFlag(ruleScreenshot(), proof).result,
|
||||
camera: matchFlag(ruleCamera(), proof).result,
|
||||
};
|
||||
return flags;
|
||||
const dateCreated = extractFlagValues(
|
||||
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/../../../../signature_info/time",
|
||||
proof
|
||||
);
|
||||
let date: Date | undefined = undefined;
|
||||
if (dateCreated && dateCreated.length == 1) {
|
||||
try {
|
||||
date = new Date(Date.parse(dateCreated[0].value));
|
||||
} catch (error) {}
|
||||
}
|
||||
console.log("DATE CREATED", date);
|
||||
|
||||
const flags: ProofHintFlags = {
|
||||
valid: valid,
|
||||
source: source && source.length == 1 ? source[0].value : undefined,
|
||||
creationDate: date,
|
||||
aiGenerated: matchFlag(ruleAiGenerated(), proof).result,
|
||||
aiEdited,
|
||||
screenshot: matchFlag(ruleScreenshot(), proof).result,
|
||||
camera: matchFlag(ruleCamera(), proof).result,
|
||||
};
|
||||
return flags;
|
||||
} catch (error) {}
|
||||
return undefined;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue