All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m22s
- 将GraphQL移至server/assets,在构建后会被写入server中 - 在server端通过storage读取数据
25 lines
607 B
TypeScript
25 lines
607 B
TypeScript
/**
|
|
* 将存储中的资源作为字符串加载
|
|
*
|
|
* @param storage - 存储名称
|
|
* @param path - 资源路径
|
|
*
|
|
* ---
|
|
* @example
|
|
* const content = await loadAssetAsString('myStorage', 'path/to/asset.txt');
|
|
* // typeof content === 'string'
|
|
*/
|
|
export async function loadAssetAsString(
|
|
storage: string,
|
|
path: string
|
|
): Promise<string> {
|
|
const data = await useStorage(storage).getItem(path);
|
|
if (data instanceof Uint8Array) {
|
|
return Buffer.from(data).toString('utf-8');
|
|
}
|
|
if (typeof data === 'string') {
|
|
return data;
|
|
}
|
|
throw new Error(`Invalid asset type for ${path}`);
|
|
}
|