diff --git a/proto/observation/v5.proto b/proto/observation/v5.proto index dd807e29..fe154b83 100644 --- a/proto/observation/v5.proto +++ b/proto/observation/v5.proto @@ -32,6 +32,7 @@ message Observation_5 { bytes driveId = 1; string name = 2; AttachmentType type = 3; + bytes hash = 4; } repeated Attachment attachments = 8; diff --git a/schema/observation/v5.json b/schema/observation/v5.json index 912e7f40..318860a6 100644 --- a/schema/observation/v5.json +++ b/schema/observation/v5.json @@ -100,9 +100,13 @@ "UNRECOGNIZED": "future attachment type" }, "enum": ["photo", "video", "audio", "UNRECOGNIZED"] + }, + "hash": { + "type": "string", + "description": "SHA256 hash of the attachment" } }, - "required": ["driveId", "name", "type"] + "required": ["driveId", "name", "type", "hash"] } }, "tags": { diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 9bd50e65..81fb63aa 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -55,8 +55,8 @@ export const convertObservation: ConvertFunction<'observation'> = ( ...jsonSchemaCommon, ...rest, refs: message.refs?.map(({ id }) => ({ id: id.toString('hex') })), - attachments: message.attachments?.map(({ driveId, name, type }) => { - return { driveId: driveId.toString('hex'), name, type } + attachments: message.attachments?.map(({ driveId, name, type, hash }) => { + return { driveId: driveId.toString('hex'), name, type, hash: hash.toString('hex') } }), tags: convertTags(message.tags), metadata: message.metadata || {}, diff --git a/src/lib/encode-converstions.ts b/src/lib/encode-converstions.ts index 15f85ad2..c95fc58a 100644 --- a/src/lib/encode-converstions.ts +++ b/src/lib/encode-converstions.ts @@ -83,6 +83,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( driveId: Buffer.from(attachment.driveId, 'hex'), name: attachment.name, type: attachment.type, + hash: Buffer.from(attachment.hash, 'hex'), } }) diff --git a/test/fixtures/cached.js b/test/fixtures/cached.js index 58c5b950..63a4363d 100644 --- a/test/fixtures/cached.js +++ b/test/fixtures/cached.js @@ -10,7 +10,10 @@ export const cachedValues = { coreId: randomBytes(32).toString('hex'), createdAt: date, updatedAt: date, - attachments: { driveId: randomBytes(32).toString('hex') }, + attachments: { + driveId: randomBytes(32).toString('hex'), + hash: randomBytes(32).toString('hex'), + }, metadata: { position: { timestamp: date, diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index f48f1116..f0927a2c 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -25,6 +25,7 @@ export const goodDocsCompleted = [ name: 'myFile', type: 'photo', driveId: cachedValues.attachments.driveId, + hash: cachedValues.attachments.hash, }, ], tags: {