mirror of
https://github.com/status-im/metro.git
synced 2025-01-12 03:54:21 +00:00
Verify the everstore_handles hash against the file one
Reviewed By: jeanlauliac Differential Revision: D7994855 fbshipit-source-id: b51c6923b6cc87fbef84001367ffe45546979131
This commit is contained in:
parent
082f070c22
commit
814182edb1
@ -31,11 +31,26 @@ describe('Util', () => {
|
||||
const remoteFileMap = {
|
||||
'/foo/bar': {
|
||||
'my-asset': {
|
||||
1: 'GCRaTwHwaI1plCgBAAAAAAC5oAcJbnsvAAAZ',
|
||||
1.5: 'GAdeUAEMbQH8hyQGAAAAAAC9H193bnsvAAAZ',
|
||||
2: 'GMsbUgHQlgBGbPsCAAAAAAABXchsbnsvAAAZ',
|
||||
3: 'GMEgUgG9llQL8EUBAAAAAAB2uXdrbnsvAAAZ',
|
||||
4: 'GFleUAEiuVDxD5wGAAAAAAZWLd1dbnsvAAAZ',
|
||||
1: {
|
||||
handle: 'GCRaTwHwaI1plCgBAAAAAAC5oAcJbnsvAAAZ',
|
||||
hash: 'baa06e3fa558fe7f246b3f3e5ee33bc86357c879',
|
||||
},
|
||||
1.5: {
|
||||
handle: 'GAdeUAEMbQH8hyQGAAAAAAC9H193bnsvAAAZ',
|
||||
hash: '7e5c0190b0fab299dab0351a5079368a91a372fe',
|
||||
},
|
||||
2: {
|
||||
handle: 'GMsbUgHQlgBGbPsCAAAAAAABXchsbnsvAAAZ',
|
||||
hash: '328184a20a8a938b378153280bc636182b9136ac',
|
||||
},
|
||||
3: {
|
||||
handle: 'GMEgUgG9llQL8EUBAAAAAAB2uXdrbnsvAAAZ',
|
||||
hash: '4b41f231da982f153257e8384663fae20c7c607d',
|
||||
},
|
||||
4: {
|
||||
handle: 'GFleUAEiuVDxD5wGAAAAAAZWLd1dbnsvAAAZ',
|
||||
hash: 'd022de9b8d34bb1b621ef357f1da7573d5a4205d',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -21,7 +21,10 @@ import type {Ast} from '@babel/core';
|
||||
export type RemoteFileMap = {
|
||||
[string]: {
|
||||
[string]: {
|
||||
[number]: string,
|
||||
[number]: {
|
||||
handle: string,
|
||||
hash: string,
|
||||
},
|
||||
},
|
||||
},
|
||||
__proto__: null,
|
||||
@ -101,11 +104,16 @@ function generateRemoteAssetCodeFileAst(
|
||||
|
||||
const file = remoteFileMap[assetDescriptor.fileSystemLocation];
|
||||
const descriptor = file && file[assetDescriptor.name];
|
||||
const data = {};
|
||||
|
||||
if (!descriptor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const scale in descriptor) {
|
||||
data[+scale] = descriptor[+scale].handle;
|
||||
}
|
||||
|
||||
// require('AssetSourceResolver')
|
||||
const requireCall = t.callExpression(t.identifier('require'), [
|
||||
t.stringLiteral(assetSourceResolverPath),
|
||||
@ -125,10 +133,10 @@ function generateRemoteAssetCodeFileAst(
|
||||
]);
|
||||
|
||||
// {2: 'path/to/image@2x', 3: 'path/to/image@3x', ...}
|
||||
const data = babylon.parseExpression(JSON.stringify(descriptor));
|
||||
const astData = babylon.parseExpression(JSON.stringify(data));
|
||||
|
||||
// ({2: '...', 3: '...'})[require(...).pickScale(...)]
|
||||
const handler = t.memberExpression(data, call, true);
|
||||
const handler = t.memberExpression(astData, call, true);
|
||||
|
||||
// 'https://remote.server.com/' + ({2: ...})[require(...).pickScale(...)]
|
||||
const uri = t.binaryExpression('+', t.stringLiteral(remoteServer), handler);
|
||||
|
Loading…
x
Reference in New Issue
Block a user