Compare commits

..

No commits in common. "d7243596222f033fe86ea1ec16da408c0070b6e0" and "b9652ab261def57c79db60dba82e8926f54aa6bd" have entirely different histories.

2 changed files with 38 additions and 125 deletions

View File

@ -1,126 +1,39 @@
import {SdkProvider} from "~/data/sdk-provider.js"; import type { DataProvider } from "@refinedev/core";
import {S5Client} from "@lumeweb/s5-js"; import { SdkProvider } from "~/data/sdk-provider.js";
import {PROTOCOL_S5} from "@lumeweb/portal-sdk";
import {Multihash} from "@lumeweb/libs5/lib/multihash.js";
import {AxiosProgressEvent} from "axios";
import {CancelablePromise} from "@lumeweb/s5-js/lib/axios.js";
import {MetadataResult} from "@lumeweb/s5-js/lib/options/download.js";
import {metadataMagicByte, Unpacker, CID, METADATA_TYPES, CID_TYPES} from "@lumeweb/libs5";
async function getIsManifest(s5: S5Client, hash: string): Promise<boolean | number> { export const fileProvider = {
getList: () => {
let type: number | null; console.log("Not implemented");
try { return Promise.resolve({
const resp = s5.downloadData(hash, { data: [],
onDownloadProgress: (progressEvent: AxiosProgressEvent) => { total: 0,
if (progressEvent.loaded >= 10) { });
resp.cancel(); },
} getOne: () => {
}, console.log("Not implemented");
}) as CancelablePromise<ArrayBuffer>; return Promise.resolve({
data: {
const data = await resp; id: 1
const unpacker = Unpacker.fromPacked(Buffer.from(data)); },
try { });
const magic = unpacker.unpackInt(); },
update: () => {
if (magic !== metadataMagicByte) { console.log("Not implemented");
return false; return Promise.resolve({
} data: {},
});
type = unpacker.unpackInt(); },
create: () => {
if (!type || !Object.values(METADATA_TYPES).includes(type)) { console.log("Not implemented");
return false; return Promise.resolve({
} data: {},
} catch (e) { });
return false; },
} deleteOne: () => {
console.log("Not implemented");
} catch (e) { return Promise.resolve({
return false; data: {},
} });
},
switch (type) { getApiUrl: () => "",
case METADATA_TYPES.DIRECTORY:
return CID_TYPES.DIRECTORY;
case METADATA_TYPES.WEBAPP:
return CID_TYPES.METADATA_WEBAPP;
case METADATA_TYPES.MEDIA:
return CID_TYPES.METADATA_MEDIA;
case METADATA_TYPES.USER_IDENTITY:
return CID_TYPES.USER_IDENTITY;
}
return 0;
}
export interface FileItem {
cid: string;
type: string;
mimeType: string;
}
export const fileProvider: SdkProvider = {
sdk: undefined,
async getList() {
const items: FileItem[] = [];
try {
const s5 = fileProvider.sdk?.protocols().get<S5Client>(PROTOCOL_S5)!.getSdk()!;
const pinList = await s5.accountPins();
for (const pin of pinList!.pins) {
const manifest = await getIsManifest(s5, pin.hash) as number;
if (manifest) {
items.push({
cid: CID.fromHash(pin.hash, pin.size, manifest).toString(),
type: "manifest",
mimeType: "application/octet-stream",
});
} else {
items.push({
cid: CID.fromHash(pin.hash, pin.size, CID_TYPES.RAW).toString(),
type: "raw",
mimeType: pin.mime_type,
});
}
}
} catch (e) {
return Promise.reject(e);
}
return {
data: items,
total: items.length,
};
},
getOne() {
console.log("Not implemented");
return Promise.resolve({
data: {
id: 1
},
});
},
update() {
console.log("Not implemented");
return Promise.resolve({
data: {},
});
},
create() {
console.log("Not implemented");
return Promise.resolve({
data: {},
});
},
deleteOne() {
console.log("Not implemented");
return Promise.resolve({
data: {},
});
},
getApiUrl() {
return "";
},
} satisfies SdkProvider; } satisfies SdkProvider;

View File

@ -16,7 +16,7 @@
"@conform-to/react": "^1.0.2", "@conform-to/react": "^1.0.2",
"@conform-to/zod": "^1.0.2", "@conform-to/zod": "^1.0.2",
"@fontsource-variable/manrope": "^5.0.19", "@fontsource-variable/manrope": "^5.0.19",
"@lumeweb/portal-sdk": "0.0.0-20240321172104", "@lumeweb/portal-sdk": "0.0.0-20240321171622",
"@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-dialog": "^1.0.5",