mirror of
https://github.com/scratchfoundation/scratch-storage.git
synced 2025-08-28 22:39:11 -04:00
Add Asset
and AssetType
to storage instance
Actually, to the prototype. This allows consumers of this module to access `Asset` and `AssetType` without having to `require` the storage module itself.
This commit is contained in:
parent
cde04d43a9
commit
c742a74a52
4 changed files with 35 additions and 23 deletions
|
@ -1,3 +1,5 @@
|
|||
const Asset = require('./Asset');
|
||||
const AssetType = require('./AssetType');
|
||||
const BuiltinHelper = require('./BuiltinHelper');
|
||||
const LocalHelper = require('./LocalHelper');
|
||||
const WebHelper = require('./WebHelper');
|
||||
|
@ -95,4 +97,9 @@ class ScratchStorage {
|
|||
}
|
||||
}
|
||||
|
||||
Object.assign(ScratchStorage.prototype, {
|
||||
Asset,
|
||||
AssetType
|
||||
});
|
||||
|
||||
module.exports = ScratchStorage;
|
||||
|
|
|
@ -7,6 +7,15 @@ const ScratchStorage = require('./ScratchStorage');
|
|||
* @type {ScratchStorage}
|
||||
*/
|
||||
module.exports = Object.assign(ScratchStorage, {
|
||||
/**
|
||||
* Please use the `Asset` member of a storage instance instead.
|
||||
* @deprecated
|
||||
*/
|
||||
Asset: Asset,
|
||||
|
||||
/**
|
||||
* Please use the `AssetType` member of a storage instance instead.
|
||||
* @deprecated
|
||||
*/
|
||||
AssetType: AssetType
|
||||
});
|
||||
|
|
|
@ -2,8 +2,13 @@ const crypto = require('crypto');
|
|||
const test = require('tap').test;
|
||||
|
||||
const ScratchStorage = require('../../dist/node/scratch-storage');
|
||||
const Asset = ScratchStorage.Asset;
|
||||
const AssetType = ScratchStorage.AssetType;
|
||||
|
||||
var storage;
|
||||
test('constructor', t => {
|
||||
storage = new ScratchStorage();
|
||||
t.type(storage, ScratchStorage);
|
||||
t.end();
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -14,43 +19,36 @@ const AssetType = ScratchStorage.AssetType;
|
|||
*/
|
||||
const testAssets = [
|
||||
{
|
||||
type: AssetType.Project,
|
||||
type: storage.AssetType.Project,
|
||||
id: '117504922',
|
||||
md5: null // don't check MD5 for project without revision ID
|
||||
},
|
||||
{
|
||||
type: AssetType.Project,
|
||||
type: storage.AssetType.Project,
|
||||
id: '117504922.d6ae1ffb76f2bc83421cd3f40fc4fd57',
|
||||
md5: '1225460702e149727de28bff4cfd9e23'
|
||||
},
|
||||
{
|
||||
type: AssetType.ImageVector,
|
||||
type: storage.AssetType.ImageVector,
|
||||
id: 'f88bf1935daea28f8ca098462a31dbb0', // cat1-a
|
||||
md5: 'f88bf1935daea28f8ca098462a31dbb0'
|
||||
},
|
||||
{
|
||||
type: AssetType.ImageBitmap,
|
||||
type: storage.AssetType.ImageBitmap,
|
||||
id: '7e24c99c1b853e52f8e7f9004416fa34', // squirrel
|
||||
md5: '7e24c99c1b853e52f8e7f9004416fa34'
|
||||
},
|
||||
{
|
||||
type: AssetType.Sound,
|
||||
type: storage.AssetType.Sound,
|
||||
id: '83c36d806dc92327b9e7049a565c6bff', // meow
|
||||
md5: '83c36d806dc92327b9e7049a565c6bff' // wat
|
||||
}
|
||||
];
|
||||
|
||||
var storage;
|
||||
test('constructor', t => {
|
||||
storage = new ScratchStorage();
|
||||
t.type(storage, ScratchStorage);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('addWebSource', t => {
|
||||
t.doesNotThrow(() => {
|
||||
storage.addWebSource(
|
||||
[AssetType.Project],
|
||||
[storage.AssetType.Project],
|
||||
asset => {
|
||||
const idParts = asset.assetId.split('.');
|
||||
return idParts[1] ?
|
||||
|
@ -60,7 +58,7 @@ test('addWebSource', t => {
|
|||
});
|
||||
t.doesNotThrow(() => {
|
||||
storage.addWebSource(
|
||||
[AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound],
|
||||
[storage.AssetType.ImageVector, storage.AssetType.ImageBitmap, storage.AssetType.Sound],
|
||||
asset => `https://cdn.assets.scratch.mit.edu/internalapi/asset/${asset.assetId}.${asset.assetType.runtimeFormat}/get/`
|
||||
);
|
||||
});
|
||||
|
@ -78,7 +76,7 @@ test('load', t => {
|
|||
promises.push(promise);
|
||||
|
||||
promise.then(asset => {
|
||||
t.type(asset, Asset);
|
||||
t.type(asset, storage.Asset);
|
||||
t.strictEqual(asset.assetId, assetInfo.id);
|
||||
t.strictEqual(asset.assetType, assetInfo.type);
|
||||
t.ok(asset.data.length);
|
||||
|
|
|
@ -2,11 +2,6 @@ const crypto = require('crypto');
|
|||
const test = require('tap').test;
|
||||
|
||||
const ScratchStorage = require('../../dist/node/scratch-storage');
|
||||
const Asset = ScratchStorage.Asset;
|
||||
const AssetType = ScratchStorage.AssetType;
|
||||
|
||||
const defaultAssetTypes = [AssetType.ImageBitmap, AssetType.ImageVector, AssetType.Sound];
|
||||
const defaultIds = {};
|
||||
|
||||
var storage;
|
||||
test('constructor', t => {
|
||||
|
@ -15,6 +10,9 @@ test('constructor', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
const defaultAssetTypes = [storage.AssetType.ImageBitmap, storage.AssetType.ImageVector, storage.AssetType.Sound];
|
||||
const defaultIds = {};
|
||||
|
||||
test('getDefaultAssetId', t => {
|
||||
for (var i = 0; i < defaultAssetTypes.length; ++i) {
|
||||
const assetType = defaultAssetTypes[i];
|
||||
|
@ -37,7 +35,7 @@ test('load', t => {
|
|||
promises.push(promise);
|
||||
|
||||
promise.then(asset => {
|
||||
t.type(asset, Asset);
|
||||
t.type(asset, storage.Asset);
|
||||
t.strictEqual(asset.assetId, id);
|
||||
t.strictEqual(asset.assetType, assetType);
|
||||
t.ok(asset.data.length);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue