Rename ProofHintFlags to MediaMetadata
Also, introduce the MediaInterventionFlags class to not send all metadata across, just the info needed for showing the intervention flags.
This commit is contained in:
parent
5fcbcb77fb
commit
1aff02c7d4
13 changed files with 101 additions and 90 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { ComputedRef, Ref } from "vue";
|
||||
import { Proof, ProofHintFlags } from "./proof";
|
||||
import { Proof, MediaMetadata } from "./proof";
|
||||
|
||||
export class UploadPromise<Type> {
|
||||
wrappedPromise: Promise<Type>;
|
||||
|
|
@ -58,7 +58,7 @@ export type Attachment = {
|
|||
useScaled: boolean;
|
||||
src?: string;
|
||||
proof?: Proof;
|
||||
proofHintFlags?: ProofHintFlags;
|
||||
mediaMetadata?: MediaMetadata;
|
||||
thumbnail?: AttachmentThumbnail;
|
||||
sendInfo: AttachmentSendInfo;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ import {
|
|||
import proofmode from "../plugins/proofmode";
|
||||
import imageResize from "image-resize";
|
||||
import { computed, ref, Ref, shallowReactive, unref } from "vue";
|
||||
import utils, { THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, CLIENT_EVENT_PROOF_HINT } from "@/plugins/utils";
|
||||
import { extractProofHintFlags } from "./proof";
|
||||
import utils, { THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, CLIENT_EVENT_MEDIA_INTERVENTION_FLAGS } from "@/plugins/utils";
|
||||
import { extractMediaMetadata } from "./proof";
|
||||
|
||||
export class AttachmentManager {
|
||||
matrixClient: MatrixClient;
|
||||
|
|
@ -118,7 +118,7 @@ export class AttachmentManager {
|
|||
}
|
||||
try {
|
||||
attachment.proof = await proofmode.proofCheckFile(file);
|
||||
attachment.proofHintFlags = extractProofHintFlags(attachment.proof);
|
||||
attachment.mediaMetadata = extractMediaMetadata(attachment.proof);
|
||||
|
||||
// Default to scaled version if the image does not contain Content Credentials
|
||||
//
|
||||
|
|
@ -220,7 +220,7 @@ export class AttachmentManager {
|
|||
|
||||
const fileSize = this.getSrcFileSize(event);
|
||||
|
||||
let proofHintFlags = event.getContent()[CLIENT_EVENT_PROOF_HINT];
|
||||
let mediaInterventionFlags = event.getContent()[CLIENT_EVENT_MEDIA_INTERVENTION_FLAGS];
|
||||
|
||||
const attachment: EventAttachment = {
|
||||
event: event,
|
||||
|
|
@ -229,7 +229,8 @@ export class AttachmentManager {
|
|||
srcProgress: -1,
|
||||
thumbnailProgress: -1,
|
||||
autoDownloadable: fileSize <= this.maxSizeAutoDownloads,
|
||||
proofHintFlags: proofHintFlags ? JSON.parse(proofHintFlags) : proofHintFlags,
|
||||
mediaInterventionFlags: mediaInterventionFlags ? JSON.parse(mediaInterventionFlags) : undefined,
|
||||
mediaMetadata: undefined,
|
||||
proof: undefined,
|
||||
loadSrc: () => Promise.reject("Not implemented"),
|
||||
loadThumbnail: () => Promise.reject("Not implemented"),
|
||||
|
|
@ -632,7 +633,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
eventId,
|
||||
attachment.dimensions,
|
||||
attachment.thumbnail,
|
||||
attachment.proofHintFlags
|
||||
attachment.mediaMetadata
|
||||
)
|
||||
.then((mediaEventId: string) => {
|
||||
// Look at last item rotation, flipping the sign on this, so looks more like a true stack
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { MatrixEvent, Room } from "matrix-js-sdk";
|
||||
import { AttachmentBatch } from "./attachment";
|
||||
import { Proof, ProofHintFlags } from "./proof";
|
||||
import { Proof, MediaMetadata } from "./proof";
|
||||
|
||||
export type KeanuEventExtension = {
|
||||
isMxThread?: boolean;
|
||||
|
|
@ -28,7 +28,8 @@ export type EventAttachment = {
|
|||
thumbnailPromise?: Promise<EventAttachmentUrlData>;
|
||||
autoDownloadable: boolean;
|
||||
proof?: Proof;
|
||||
proofHintFlags?: ProofHintFlags;
|
||||
mediaInterventionFlags?: MediaInterventionFlags;
|
||||
mediaMetadata?: MediaMetadata;
|
||||
loadSrc: () => Promise<EventAttachmentUrlData>;
|
||||
loadThumbnail: () => Promise<EventAttachmentUrlData>;
|
||||
loadBlob: () => Promise<{data: Blob}>;
|
||||
|
|
|
|||
|
|
@ -62,21 +62,29 @@ export type Proof = {
|
|||
ai?: { inferenceResult?: AIInferenceResult };
|
||||
};
|
||||
|
||||
export type ProofHintFlagsGenerator = "unknown" | "camera" | "screenshot" | "ai";
|
||||
export type ProofHintFlagSource = "c2pa" | "exif" | "metadata";
|
||||
export type MediaMetadataGenerator = "unknown" | "camera" | "screenshot" | "ai";
|
||||
export type MediaMetadataPropertySource = "c2pa" | "exif" | "metadata";
|
||||
|
||||
export type ProofHintFlagsEdit = {
|
||||
export type MediaMetadataEdit = {
|
||||
editor: string;
|
||||
date?: Date;
|
||||
}
|
||||
|
||||
export type ProofHintFlags = {
|
||||
export type MediaInterventionFlags = {
|
||||
creationDate?: Date;
|
||||
generator?: MediaMetadataGenerator;
|
||||
modified?: boolean;
|
||||
containsC2PA?: boolean;
|
||||
containsEXIF?: boolean;
|
||||
}
|
||||
|
||||
export type MediaMetadata = {
|
||||
device?: string;
|
||||
creationDate?: Date;
|
||||
creationDateSource?: ProofHintFlagSource;
|
||||
generator?: ProofHintFlagsGenerator;
|
||||
generatorSource?: ProofHintFlagSource;
|
||||
edits?: ProofHintFlagsEdit[];
|
||||
creationDateSource?: MediaMetadataPropertySource;
|
||||
generator?: MediaMetadataGenerator;
|
||||
generatorSource?: MediaMetadataPropertySource;
|
||||
edits?: MediaMetadataEdit[];
|
||||
containsC2PA?: boolean;
|
||||
containsEXIF?: boolean;
|
||||
};
|
||||
|
|
@ -371,10 +379,20 @@ const getFirstWithDataAsDate = (flagValues: FlagValue[], path: FlagMatchRulePath
|
|||
return undefined;
|
||||
};
|
||||
|
||||
export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined => {
|
||||
export const mediaMetadataToMediaInterventionFlags = (mediaMetadata: MediaMetadata): MediaInterventionFlags => {
|
||||
return {
|
||||
creationDate: mediaMetadata.creationDate,
|
||||
generator: mediaMetadata.generator,
|
||||
modified: mediaMetadata.edits && mediaMetadata.edits.length > 0,
|
||||
containsC2PA: mediaMetadata.containsC2PA,
|
||||
containsEXIF: mediaMetadata.containsEXIF
|
||||
}
|
||||
}
|
||||
|
||||
export const extractMediaMetadata = (proof?: Proof): MediaMetadata | undefined => {
|
||||
if (!proof) return undefined;
|
||||
|
||||
let edits: ProofHintFlagsEdit[] | undefined = undefined;
|
||||
let edits: MediaMetadataEdit[] | undefined = undefined;
|
||||
let valid = false;
|
||||
|
||||
try {
|
||||
|
|
@ -387,7 +405,7 @@ export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined
|
|||
|
||||
let source: string | undefined = undefined;
|
||||
let dateCreated: Date | undefined = undefined;
|
||||
let dateCreatedSource: ProofHintFlagSource | undefined = undefined;
|
||||
let dateCreatedSource: MediaMetadataPropertySource | undefined = undefined;
|
||||
|
||||
source = getFirstWithData(pathsC2PASource(), rootMatchPath);
|
||||
if (!source) {
|
||||
|
|
@ -405,8 +423,8 @@ export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined
|
|||
}
|
||||
|
||||
|
||||
let generator: ProofHintFlagsGenerator = "unknown";
|
||||
let generatorSource: ProofHintFlagSource | undefined = undefined;
|
||||
let generator: MediaMetadataGenerator = "unknown";
|
||||
let generatorSource: MediaMetadataPropertySource | undefined = undefined;
|
||||
|
||||
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)) {
|
||||
|
|
@ -460,7 +478,7 @@ export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const flags: ProofHintFlags = {
|
||||
const flags: MediaMetadata = {
|
||||
device: source,
|
||||
creationDate: dateCreated,
|
||||
creationDateSource: dateCreatedSource,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue