diff --git a/src/backend/providers/s5.ts b/src/backend/providers/s5.ts index 6a1d22e..683584c 100644 --- a/src/backend/providers/s5.ts +++ b/src/backend/providers/s5.ts @@ -1,6 +1,7 @@ import type { ContentProvider } from "../types.js"; import * as nodePath from "path"; import { createClient } from "@lumeweb/kernel-s5-client"; +import { CID, CID_TYPES } from "@lumeweb/libs5"; export default class S5Provider implements ContentProvider { private _client = createClient(); @@ -27,36 +28,35 @@ export default class S5Provider implements ContentProvider { let file; - try { - const meta = await this._client.stat(cid); - if (meta.type !== "web_app") { + switch (CID.decode(cid).type) { + case CID_TYPES.METADATA_WEBAPP: + const meta = await this._client.stat(cid); + if (!parsedPath.base.length || !parsedPath.ext.length) { + let found = false; + for (const indexFile of meta.tryFiles) { + urlPath = nodePath.join(urlPath, indexFile); + if (urlPath.startsWith("/")) { + urlPath = urlPath.substring(1); + } + if (urlPath in meta.paths) { + found = true; + break; + } + } + + if (!found) { + throw new Error("404"); + } + file = meta.paths[urlPath]; + } else { + if (!(urlPath in meta.paths)) { + throw new Error("404"); + } + } + + break; + default: throw new Error("404"); - } - - if (!parsedPath.base.length || !parsedPath.ext.length) { - let found = false; - for (const indexFile of meta.tryFiles) { - urlPath = nodePath.join(urlPath, indexFile); - if (urlPath.startsWith("/")) { - urlPath = urlPath.substring(1); - } - if (urlPath in meta.paths) { - found = true; - break; - } - } - - if (!found) { - throw new Error("404"); - } - file = meta.paths[urlPath]; - } else { - if (!(urlPath in meta.paths)) { - throw new Error("404"); - } - } - } catch (e) { - throw new Error(err); } const headers: HeadersInit = {};