Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: iconVersionId wrong encode decode #156

Merged
merged 12 commits into from
Oct 10, 2023
7 changes: 6 additions & 1 deletion proto/icon/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
1 change: 1 addition & 0 deletions schema/icon/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ export const convertIcon: ConvertFunction<'icon'> = (message, versionObj) => {

function convertIconVariant(variant: Icon_1_IconVariant) {
const { blobVersionId, mimeType, size, pixelDensity } = variant
tomasciccola marked this conversation as resolved.
Show resolved Hide resolved
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),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/encode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/good-docs-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
Expand Down
Loading