接口: AssetSource
定义于: packages/draw/src/types.ts:34
素材来源接口。只声明 draw 用到的 getAsset;MaimaiDatabase(方法更多、 AssetType 更宽)可结构化直接传入,用户亦可自定义实现。
示例
从自己的 CDN 读取封面与头像
ts
const assets: AssetSource = {
async getAsset(type, id) {
const response = await fetch(`https://cdn.example.com/${type}/${id}.png`);
if (!response.ok) throw new Error(`asset HTTP ${response.status}`);
return new Uint8Array(await response.arrayBuffer());
},
};方法
getAsset()
ts
getAsset(type, id): Promise<Uint8Array<ArrayBufferLike>>;定义于: packages/draw/src/types.ts:36
按类型与 id 读取头像或封面原始字节。
参数
| 参数 | 类型 |
|---|---|
type | DrawAssetType |
id | number |
返回
Promise<Uint8Array<ArrayBufferLike>>
