Update mediaName derivation to hex encoding
This commit is contained in:
parent
5173b3d01a
commit
0433264eed
5 changed files with 44 additions and 24 deletions
|
@ -271,7 +271,7 @@ export function deriveMediaIdFromMediaName(
|
|||
BACKUP_MEDIA_ID_LEN,
|
||||
Buffer.from(backupKey),
|
||||
Buffer.from(BACKUP_MEDIA_ID_INFO),
|
||||
Buffer.from(Bytes.fromBase64(mediaName))
|
||||
Buffer.from(mediaName, 'utf8')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,13 +42,13 @@ export function getMediaNameForAttachment(attachment: AttachmentType): string {
|
|||
return attachment.backupLocator.mediaName;
|
||||
}
|
||||
strictAssert(attachment.digest, 'Digest must be present');
|
||||
return attachment.digest;
|
||||
return Bytes.toHex(Bytes.fromBase64(attachment.digest));
|
||||
}
|
||||
|
||||
export function getMediaNameForAttachmentThumbnail(
|
||||
fullsizeMediaName: string
|
||||
): string {
|
||||
return Bytes.toBase64(Bytes.fromString(`${fullsizeMediaName}_thumbnail`));
|
||||
return `${fullsizeMediaName}_thumbnail`;
|
||||
}
|
||||
|
||||
export function getBytesFromMediaIdString(mediaId: string): Uint8Array {
|
||||
|
|
|
@ -77,6 +77,10 @@ describe('backup/attachments', () => {
|
|||
return Bytes.toBase64(Bytes.fromString(str));
|
||||
}
|
||||
|
||||
function digestToMediaName(digestBase64: string): string {
|
||||
return Bytes.toHex(Bytes.fromBase64(digestBase64));
|
||||
}
|
||||
|
||||
function composeAttachment(
|
||||
index: number,
|
||||
overrides?: Partial<AttachmentType>
|
||||
|
@ -169,7 +173,9 @@ describe('backup/attachments', () => {
|
|||
'thumbnail',
|
||||
'uploadTimestamp',
|
||||
]),
|
||||
backupLocator: { mediaName: attachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(attachment.digest),
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
@ -201,7 +207,9 @@ describe('backup/attachments', () => {
|
|||
'thumbnail',
|
||||
'uploadTimestamp',
|
||||
]),
|
||||
backupLocator: { mediaName: attachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(attachment.digest),
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
@ -271,7 +279,9 @@ describe('backup/attachments', () => {
|
|||
'thumbnail',
|
||||
'uploadTimestamp',
|
||||
]),
|
||||
backupLocator: { mediaName: attachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(attachment.digest),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -332,7 +342,9 @@ describe('backup/attachments', () => {
|
|||
'thumbnail',
|
||||
'uploadTimestamp',
|
||||
]),
|
||||
backupLocator: { mediaName: attachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(attachment.digest),
|
||||
},
|
||||
},
|
||||
isProfile: false,
|
||||
},
|
||||
|
@ -417,7 +429,9 @@ describe('backup/attachments', () => {
|
|||
'uploadTimestamp',
|
||||
'thumbnail',
|
||||
]),
|
||||
backupLocator: { mediaName: attachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(attachment.digest),
|
||||
},
|
||||
},
|
||||
contentType: VIDEO_MP4,
|
||||
},
|
||||
|
@ -468,7 +482,9 @@ describe('backup/attachments', () => {
|
|||
'uploadTimestamp',
|
||||
'thumbnail',
|
||||
]),
|
||||
backupLocator: { mediaName: existingAttachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(existingAttachment.digest),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -483,7 +499,9 @@ describe('backup/attachments', () => {
|
|||
// been downloaded
|
||||
thumbnail: {
|
||||
...omit(quoteAttachment, ['iv', 'path', 'uploadTimestamp']),
|
||||
backupLocator: { mediaName: quoteAttachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(quoteAttachment.digest),
|
||||
},
|
||||
},
|
||||
contentType: VIDEO_MP4,
|
||||
},
|
||||
|
@ -563,7 +581,7 @@ describe('backup/attachments', () => {
|
|||
key,
|
||||
digest,
|
||||
backupLocator: {
|
||||
mediaName: digest,
|
||||
mediaName: digestToMediaName(digest),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
@ -635,7 +653,7 @@ describe('backup/attachments', () => {
|
|||
key,
|
||||
digest,
|
||||
backupLocator: {
|
||||
mediaName: digest,
|
||||
mediaName: digestToMediaName(digest),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
@ -716,7 +734,9 @@ describe('backup/attachments', () => {
|
|||
'thumbnail',
|
||||
'uploadTimestamp',
|
||||
]),
|
||||
backupLocator: { mediaName: attachment.digest },
|
||||
backupLocator: {
|
||||
mediaName: digestToMediaName(attachment.digest),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
|
|
@ -161,6 +161,9 @@ describe('convertFilePointerToAttachment', () => {
|
|||
});
|
||||
});
|
||||
|
||||
const defaultDigest = Bytes.fromBase64('digest');
|
||||
const defaultMediaName = Bytes.toHex(defaultDigest);
|
||||
|
||||
function composeAttachment(
|
||||
overrides: Partial<AttachmentType> = {}
|
||||
): AttachmentType {
|
||||
|
@ -171,7 +174,7 @@ function composeAttachment(
|
|||
cdnNumber: 2,
|
||||
path: 'path/to/file.png',
|
||||
key: 'key',
|
||||
digest: 'digest',
|
||||
digest: Bytes.toBase64(defaultDigest),
|
||||
iv: 'iv',
|
||||
width: 100,
|
||||
height: 100,
|
||||
|
@ -202,17 +205,16 @@ const defaultAttachmentLocator = new Backups.FilePointer.AttachmentLocator({
|
|||
cdnKey: 'cdnKey',
|
||||
cdnNumber: 2,
|
||||
key: Bytes.fromBase64('key'),
|
||||
digest: Bytes.fromBase64('digest'),
|
||||
digest: defaultDigest,
|
||||
size: 100,
|
||||
uploadTimestamp: Long.fromNumber(1234),
|
||||
});
|
||||
|
||||
const defaultMediaName = 'digest';
|
||||
const defaultBackupLocator = new Backups.FilePointer.BackupLocator({
|
||||
mediaName: defaultMediaName,
|
||||
cdnNumber: null,
|
||||
key: Bytes.fromBase64('key'),
|
||||
digest: Bytes.fromBase64('digest'),
|
||||
digest: defaultDigest,
|
||||
size: Long.fromNumber(100),
|
||||
transitCdnKey: 'cdnKey',
|
||||
transitCdnNumber: 2,
|
||||
|
@ -455,7 +457,7 @@ describe('getFilePointerForAttachment', () => {
|
|||
...defaultBackupLocator,
|
||||
key: newKey,
|
||||
digest: newDigest,
|
||||
mediaName: Bytes.toBase64(newDigest),
|
||||
mediaName: Bytes.toHex(newDigest),
|
||||
transitCdnKey: undefined,
|
||||
transitCdnNumber: undefined,
|
||||
}),
|
||||
|
@ -497,7 +499,7 @@ describe('getFilePointerForAttachment', () => {
|
|||
...defaultBackupLocator,
|
||||
key: newKey,
|
||||
digest: newDigest,
|
||||
mediaName: Bytes.toBase64(newDigest),
|
||||
mediaName: Bytes.toHex(newDigest),
|
||||
transitCdnKey: undefined,
|
||||
transitCdnNumber: undefined,
|
||||
}),
|
||||
|
@ -590,14 +592,14 @@ describe('getBackupJobForAttachmentAndFilePointer', async () => {
|
|||
getBackupCdnInfo: notInBackupCdn,
|
||||
}),
|
||||
{
|
||||
mediaName: 'digest',
|
||||
mediaName: Bytes.toHex(defaultDigest),
|
||||
receivedAt: 100,
|
||||
type: 'standard',
|
||||
data: {
|
||||
path: 'path/to/file.png',
|
||||
contentType: IMAGE_PNG,
|
||||
keys: 'key',
|
||||
digest: 'digest',
|
||||
digest: Bytes.toBase64(defaultDigest),
|
||||
iv: 'iv',
|
||||
size: 100,
|
||||
localKey: attachment.localKey,
|
||||
|
|
|
@ -343,9 +343,7 @@ describe('AttachmentBackupManager/JobManager', function attachmentBackupManager(
|
|||
jobForNonVisualAttachment
|
||||
);
|
||||
|
||||
const thumbnailMediaName = Bytes.toBase64(
|
||||
Bytes.fromString(`${jobForVisualAttachment.mediaName}_thumbnail`)
|
||||
);
|
||||
const thumbnailMediaName = `${jobForVisualAttachment.mediaName}_thumbnail`;
|
||||
const allJobs = await getAllSavedJobs();
|
||||
assert.strictEqual(allJobs.length, 3);
|
||||
assert.sameMembers(
|
||||
|
|
Loading…
Reference in a new issue