|
const StringUtil = require('./string-util'); |
|
|
|
class AssetUtil { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static getByMd5ext(runtime, zip, assetType, md5ext) { |
|
const storage = runtime.storage; |
|
const idParts = StringUtil.splitFirst(md5ext, '.'); |
|
const md5 = idParts[0]; |
|
const ext = idParts[1].toLowerCase(); |
|
|
|
if (zip) { |
|
|
|
let file = zip.file(md5ext); |
|
|
|
|
|
|
|
if (!file) { |
|
const fileMatch = new RegExp(`^([^/]*/)?${md5ext}$`); |
|
file = zip.file(fileMatch)[0]; |
|
} |
|
|
|
if (file) { |
|
return file.async('uint8array').then(data => runtime.storage.createAsset( |
|
assetType, |
|
ext, |
|
data, |
|
md5, |
|
false |
|
)); |
|
} |
|
} |
|
|
|
return storage.load(assetType, md5, ext); |
|
} |
|
} |
|
|
|
module.exports = AssetUtil; |