UNPKG

@snap/camera-kit

Version:
21 lines 1.36 kB
import { __awaiter } from "tslib"; import { Injectable } from "@snap/ts-inject"; import { createArrayBufferParsingHandler } from "../../handlers/arrayBufferParsingHandler"; import { defaultFetchHandlerFactory } from "../../handlers/defaultFetchHandler"; import { HandlerChainBuilder } from "../../handlers/HandlerChainBuilder"; import { withRequestPriority } from "../../handlers/utils"; export const staticAssetLoaderFactory = Injectable("staticAssetLoader", [defaultFetchHandlerFactory.token], (fetchHandler) => { const handler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler; return ({ assetDescriptor: { assetId }, assetManifest, lowPriority }) => __awaiter(void 0, void 0, void 0, function* () { var _a; const assetUrl = (_a = assetManifest === null || assetManifest === void 0 ? void 0 : assetManifest.find((manifest) => manifest.id === assetId)) === null || _a === void 0 ? void 0 : _a.assetUrl; if (!assetUrl) { throw new Error(`Cannot load lens asset ${assetId}. Static asset URL could not be found.`); } const [buffer, response] = yield handler(assetUrl, withRequestPriority({ cache: "force-cache" }, lowPriority)); if (!response.ok) throw response; return buffer; }); }); //# sourceMappingURL=staticAssetLoader.js.map