diff --git a/proto/icon/v1.proto b/proto/icon/v1.proto index 364595e..6014244 100644 --- a/proto/icon/v1.proto +++ b/proto/icon/v1.proto @@ -31,9 +31,14 @@ message Icon_1 { png = 1; } + message BlobVersionId { + bytes coreDiscoveryKey = 1; + int32 index = 2; + } + Size size = 1 [(required) = true]; PixelDensity pixelDensity = 2 [(required) = true]; - bytes blobVersionId = 3 [(required) = true]; + BlobVersionId blobVersionId = 3 [(required) = true]; MimeType mimeType = 4 [(required) = true]; } diff --git a/schema/icon/v1.json b/schema/icon/v1.json index 1fde761..28c1cd6 100644 --- a/schema/icon/v1.json +++ b/schema/icon/v1.json @@ -27,6 +27,7 @@ "enum": [1,2,3] }, "blobVersionId": { + "description": "Version id of the icon blob. Each id is id (hex-encoded 32 byte buffer) and index number, separated by '/'", "type": "string" }, "mimeType": { diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index b7b0e1c..11eca04 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -206,8 +206,11 @@ export const convertIcon: ConvertFunction<'icon'> = (message, versionObj) => { function convertIconVariant(variant: Icon_1_IconVariant) { const { blobVersionId, mimeType, size, pixelDensity } = variant + if (!blobVersionId) { + throw new Error('Missing required property `blobVersionId`') + } return { - blobVersionId: blobVersionId.toString('hex'), + blobVersionId: getVersionId(blobVersionId), mimeType: convertIconMimeType(mimeType), size: size === 'UNRECOGNIZED' ? 'medium' : size, pixelDensity: convertIconPixelDensity(pixelDensity), diff --git a/src/lib/encode-conversions.ts b/src/lib/encode-conversions.ts index 95594ac..447e16a 100644 --- a/src/lib/encode-conversions.ts +++ b/src/lib/encode-conversions.ts @@ -147,7 +147,7 @@ function convertIconVariants(variants: Icon['variants']): Icon_1_IconVariant[] { return variants.map((variant) => { const { blobVersionId, mimeType, size, pixelDensity } = variant return { - blobVersionId: Buffer.from(blobVersionId, 'hex'), + blobVersionId: parseVersionId(blobVersionId), mimeType: convertIconMimeType(mimeType), size, pixelDensity: convertIconPixelDensity(pixelDensity), diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index 3de85c2..45a8def 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -215,13 +215,13 @@ export const goodDocsCompleted = [ { size: 'small', pixelDensity: 1, - blobVersionId: randomBytes(32).toString('hex'), + blobVersionId: randomBytes(32).toString('hex') + '/0', mimeType: 'image/png', }, { size: 'large', pixelDensity: 3, - blobVersionId: randomBytes(32).toString('hex'), + blobVersionId: randomBytes(32).toString('hex') + '/0', mimeType: 'image/svg+xml', }, ], diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index 748de0e..3ce92ac 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -148,7 +148,7 @@ export const goodDocsMinimal = [ { size: 'small', pixelDensity: 1, - blobVersionId: randomBytes(32).toString('hex'), + blobVersionId: randomBytes(32).toString('hex') + '/0', mimeType: 'image/png', }, ],