refactor: restructure
This commit is contained in:
parent
9767e82751
commit
ad68d92c57
|
@ -1,6 +1,7 @@
|
||||||
import type { ContentProvider } from "../types.js";
|
import type { ContentProvider } from "../types.js";
|
||||||
import * as nodePath from "path";
|
import * as nodePath from "path";
|
||||||
import { createClient } from "@lumeweb/kernel-s5-client";
|
import { createClient } from "@lumeweb/kernel-s5-client";
|
||||||
|
import { CID, CID_TYPES } from "@lumeweb/libs5";
|
||||||
|
|
||||||
export default class S5Provider implements ContentProvider {
|
export default class S5Provider implements ContentProvider {
|
||||||
private _client = createClient();
|
private _client = createClient();
|
||||||
|
@ -27,12 +28,9 @@ export default class S5Provider implements ContentProvider {
|
||||||
|
|
||||||
let file;
|
let file;
|
||||||
|
|
||||||
try {
|
switch (CID.decode(cid).type) {
|
||||||
|
case CID_TYPES.METADATA_WEBAPP:
|
||||||
const meta = await this._client.stat(cid);
|
const meta = await this._client.stat(cid);
|
||||||
if (meta.type !== "web_app") {
|
|
||||||
throw new Error("404");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parsedPath.base.length || !parsedPath.ext.length) {
|
if (!parsedPath.base.length || !parsedPath.ext.length) {
|
||||||
let found = false;
|
let found = false;
|
||||||
for (const indexFile of meta.tryFiles) {
|
for (const indexFile of meta.tryFiles) {
|
||||||
|
@ -55,8 +53,10 @@ export default class S5Provider implements ContentProvider {
|
||||||
throw new Error("404");
|
throw new Error("404");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
throw new Error(err);
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error("404");
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers: HeadersInit = {};
|
const headers: HeadersInit = {};
|
||||||
|
|
Loading…
Reference in New Issue