From bec75e63eef7adf9a4f0ae4270d4b0fb2543e8ca Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 15:26:24 -0400 Subject: [PATCH 01/38] refactor: fix handling of check by creating a handleCheckResponse wrapper to translate success to authenticated --- app/data/auth-provider.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index 25acbc6..d6d38eb 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -54,6 +54,10 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { successCb?: () => void; } + interface CheckResponseResult extends ResponseResult { + authenticated?: boolean; + } + const handleResponse = (result: ResponseResult): AuthActionResponse => { if (result.ret) { if (result.ret instanceof Error) { @@ -79,6 +83,17 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { } } + const handleCheckResponse = (result: CheckResponseResult): CheckResponse => { + const response = handleResponse(result); + const success = response.success; + delete response.success; + + return { + ...response, + authenticated: success + } + } + return { async login(params: AuthFormRequest): Promise { const ret = await sdk.account().login({ @@ -105,7 +120,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { async check(params?: any): Promise { const ret = await sdk.account().ping(); - return handleResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth}); + return handleCheckResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth}); }, async onError(error: any): Promise { From 64e2216a3645fee133a81df78dd3a498dd441bea Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 15:42:35 -0400 Subject: [PATCH 02/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a50c58..8ba6d3e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240320165911", + "@lumeweb/portal-sdk": "0.0.0-20240320194338", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 81d52d25243eae79671348a562915433d6396a0b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 16:08:40 -0400 Subject: [PATCH 03/38] refactor: ret should now satisfy HttpError --- app/data/account-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/data/account-provider.ts b/app/data/account-provider.ts index 45cb5ac..23276b1 100644 --- a/app/data/account-provider.ts +++ b/app/data/account-provider.ts @@ -30,7 +30,7 @@ export const accountProvider: SdkProvider = { if (ret) { if (ret instanceof Error) { - return Promise.reject(ret) + return Promise.reject(ret satisfies HttpError) } } else { return Promise.reject(); From 6ce3b02dc621d34957ccacd08bd4fd79c13968f7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 16:21:37 -0400 Subject: [PATCH 04/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ba6d3e..3cf9bcd 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240320194338", + "@lumeweb/portal-sdk": "0.0.0-20240320201908", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 9332598627c60e9902bffcf7e5820d31f47b244b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 16:21:56 -0400 Subject: [PATCH 05/38] refactor: pass ret as a HttpError --- app/data/auth-provider.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index d6d38eb..3f696ed 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -1,4 +1,4 @@ -import type {AuthProvider, UpdatePasswordFormTypes} from "@refinedev/core" +import type {AuthProvider, HttpError, UpdatePasswordFormTypes} from "@refinedev/core" import type { AuthActionResponse, @@ -8,10 +8,9 @@ import type { SuccessNotificationResponse // @ts-ignore } from "@refinedev/core/dist/interfaces/bindings/auth" -import {Sdk} from "@lumeweb/portal-sdk"; +import {Sdk, AccountError} from "@lumeweb/portal-sdk"; import type {AccountInfoResponse} from "@lumeweb/portal-sdk"; -; export type AuthFormRequest = { email: string; @@ -60,10 +59,10 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { const handleResponse = (result: ResponseResult): AuthActionResponse => { if (result.ret) { - if (result.ret instanceof Error) { + if (result.ret instanceof AccountError) { return { success: false, - error: result.ret, + error: result.ret satisfies HttpError, redirectTo: result.redirectToError } } From bba7ce59d3abe936cba846b9c5224f75f0bb4f17 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 16:22:06 -0400 Subject: [PATCH 06/38] refactor: nop on onError --- app/data/auth-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index 3f696ed..b3a56fe 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -123,7 +123,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { }, async onError(error: any): Promise { - return {logout: true}; + return {}; }, async register(params: RegisterFormRequest): Promise { From 2d0609c95c7a4e05616b99372daa5918839a9279 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 08:49:05 -0400 Subject: [PATCH 07/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3cf9bcd..82d7b42 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240320201908", + "@lumeweb/portal-sdk": "0.0.0-20240321124505", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 82b4f9f4fc8a4bf70d8853721f1a25ba4ade90c4 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 08:49:29 -0400 Subject: [PATCH 08/38] fix: need to pass currentPassword --- app/routes/account.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/routes/account.tsx b/app/routes/account.tsx index dedf176..6b6318c 100644 --- a/app/routes/account.tsx +++ b/app/routes/account.tsx @@ -313,7 +313,7 @@ const ChangePasswordSchema = z }); const ChangePasswordForm = () => { - const { mutate: updatePassword } = useUpdatePassword<{ password: string }>(); + const { mutate: updatePassword } = useUpdatePassword(); const [form, fields] = useForm({ id: "login", constraint: getZodConstraint(ChangePasswordSchema), @@ -327,6 +327,7 @@ const ChangePasswordForm = () => { const data = Object.fromEntries(new FormData(e.currentTarget).entries()); updatePassword({ + currentPassword: data.currentPassword.toString(), password: data.newPassword.toString(), }); }, From 214eb1458336d627ee1b99b9a8c6a4777d496475 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 10:28:38 -0400 Subject: [PATCH 09/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82d7b42..197d098 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321124505", + "@lumeweb/portal-sdk": "0.0.0-20240321142755", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 8fecd31e4322a66438325c15272124fee817870b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 10:50:44 -0400 Subject: [PATCH 10/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 197d098..2f5c8be 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321142755", + "@lumeweb/portal-sdk": "0.0.0-20240321144958", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 02b712793e7660633fa6943ed95cc8d18875d64d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 10:58:18 -0400 Subject: [PATCH 11/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2f5c8be..cf47938 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321144958", + "@lumeweb/portal-sdk": "0.0.0-20240321145732", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From adf306b0741c89b39c230849186f85ffc1554e22 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 11:03:55 -0400 Subject: [PATCH 12/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf47938..8f10455 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321145732", + "@lumeweb/portal-sdk": "0.0.0-20240321150330", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 583a95e68a82f7a8b479894bbf966d87942a00d6 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 11:39:40 -0400 Subject: [PATCH 13/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f10455..7e46bc2 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321150330", + "@lumeweb/portal-sdk": "0.0.0-20240321153723", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 51e8cfef76cd2ac2ce332f7fc0a9ae978cb53c34 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 11:42:26 -0400 Subject: [PATCH 14/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e46bc2..fd85f30 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321153723", + "@lumeweb/portal-sdk": "0.0.0-20240321153859", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From d4ad64bf88f6353bc6cbc20ef61aae89ae467282 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 12:13:02 -0400 Subject: [PATCH 15/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd85f30..66d3214 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321153859", + "@lumeweb/portal-sdk": "0.0.0-20240321161237", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From d326881f9b1bd0792cdd9aec0626552a8994ed85 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 12:15:55 -0400 Subject: [PATCH 16/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 66d3214..aeb170f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321161237", + "@lumeweb/portal-sdk": "0.0.0-20240321161526", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 7bd2ecdc829c907b3989d94e053f05c22b7ef68b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 12:21:52 -0400 Subject: [PATCH 17/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aeb170f..61188a2 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321161526", + "@lumeweb/portal-sdk": "0.0.0-20240321162119", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From be31f0db046777096b74c3da648d3ab9f7c7c786 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 12:41:05 -0400 Subject: [PATCH 18/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61188a2..a774eee 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321162119", + "@lumeweb/portal-sdk": "0.0.0-20240321163942", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 335e982ab0e7ad743e33a4e1212e7ee24ac7ee7d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 12:56:25 -0400 Subject: [PATCH 19/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a774eee..8a48986 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321163942", + "@lumeweb/portal-sdk": "0.0.0-20240321165606", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 184b3d9a0e3b514545b2c38af4341a4c392e4ce0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 13:08:52 -0400 Subject: [PATCH 20/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8a48986..8627f0a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321165606", + "@lumeweb/portal-sdk": "0.0.0-20240321170958", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From b9652ab261def57c79db60dba82e8926f54aa6bd Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 13:16:42 -0400 Subject: [PATCH 21/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8627f0a..d0bad7d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321170958", + "@lumeweb/portal-sdk": "0.0.0-20240321171622", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 39ac3467fc1a0ea9a6a88a2288837f6219ae39f9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 13:21:22 -0400 Subject: [PATCH 22/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0bad7d..77eade4 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321171622", + "@lumeweb/portal-sdk": "0.0.0-20240321172104", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From d7243596222f033fe86ea1ec16da408c0070b6e0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 13:24:13 -0400 Subject: [PATCH 23/38] feat: initial very basic file listing --- app/data/file-provider.ts | 161 +++++++++++++++++++++++++++++--------- 1 file changed, 124 insertions(+), 37 deletions(-) diff --git a/app/data/file-provider.ts b/app/data/file-provider.ts index dc6528a..8719b6f 100644 --- a/app/data/file-provider.ts +++ b/app/data/file-provider.ts @@ -1,39 +1,126 @@ -import type { DataProvider } from "@refinedev/core"; -import { SdkProvider } from "~/data/sdk-provider.js"; +import {SdkProvider} from "~/data/sdk-provider.js"; +import {S5Client} from "@lumeweb/s5-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"; -export const fileProvider = { - getList: () => { - console.log("Not implemented"); - return Promise.resolve({ - data: [], - total: 0, - }); - }, - 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: () => "", +async function getIsManifest(s5: S5Client, hash: string): Promise { + + let type: number | null; + try { + const resp = s5.downloadData(hash, { + onDownloadProgress: (progressEvent: AxiosProgressEvent) => { + if (progressEvent.loaded >= 10) { + resp.cancel(); + } + }, + }) as CancelablePromise; + + const data = await resp; + const unpacker = Unpacker.fromPacked(Buffer.from(data)); + try { + const magic = unpacker.unpackInt(); + + if (magic !== metadataMagicByte) { + return false; + } + + type = unpacker.unpackInt(); + + if (!type || !Object.values(METADATA_TYPES).includes(type)) { + return false; + } + } catch (e) { + return false; + } + + } catch (e) { + return false; + } + + switch (type) { + 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(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; From 3162d4dcd6b9db0e57848d7dee91ad70ec381d29 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 14:30:11 -0400 Subject: [PATCH 24/38] fix: pass all providers --- app/root.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/root.tsx b/app/root.tsx index 5f17966..26300e4 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -45,7 +45,7 @@ export default function App() { authProvider={providers.auth} routerProvider={routerProvider} notificationProvider={notificationProvider} - dataProvider={providers.default} + dataProvider={providers} resources={resources} options={{disableTelemetry: true}} > From a7ef0b4773011dbb647f96ca95a4826cf4cb6782 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 14:34:55 -0400 Subject: [PATCH 25/38] fix: update resource name --- app/components/data-table.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/data-table.tsx b/app/components/data-table.tsx index 79f9b5b..7059bde 100644 --- a/app/components/data-table.tsx +++ b/app/components/data-table.tsx @@ -27,7 +27,7 @@ export function DataTable({ const table = useTable({ columns, refineCoreProps: { - resource: "files" + resource: "file" } }) From 61b70ffa2edc4bff8ff385a58749b90cd8f32aa9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 15:04:19 -0400 Subject: [PATCH 26/38] fix: use Authenticated component --- app/routes/file-manager/index.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/routes/file-manager/index.tsx b/app/routes/file-manager/index.tsx index 96a5777..31e3a3a 100644 --- a/app/routes/file-manager/index.tsx +++ b/app/routes/file-manager/index.tsx @@ -1,14 +1,16 @@ -import { GeneralLayout } from "~/components/general-layout"; -import { FileCard, FileCardList, FileTypes } from "~/components/file-card"; -import { DataTable } from "~/components/data-table"; -import { columns } from "./columns"; -import { Input } from "~/components/ui/input"; -import { Button } from "~/components/ui/button"; -import { AddIcon } from "~/components/icons"; +import {GeneralLayout} from "~/components/general-layout"; +import {FileCard, FileCardList, FileTypes} from "~/components/file-card"; +import {DataTable} from "~/components/data-table"; +import {columns} from "./columns"; +import {Input} from "~/components/ui/input"; +import {Button} from "~/components/ui/button"; +import {AddIcon} from "~/components/icons"; +import {Authenticated} from "@refinedev/core"; export default function FileManager() { return ( - + +

File Manager

+
); } From b42a04ebc31ecfe264af56975285c91ec676990e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 15:17:45 -0400 Subject: [PATCH 27/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77eade4..1acecee 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321172104", + "@lumeweb/portal-sdk": "0.0.0-20240321191714", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 3a5cd0ae32d053da36f5b86578ddc37d35d95dde Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 15:32:39 -0400 Subject: [PATCH 28/38] refactor: split app to App and Root and store the sdk context in the root for app to use --- app/root.tsx | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/root.tsx b/app/root.tsx index 26300e4..6d099b6 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -7,15 +7,16 @@ import type {LinksFunction} from "@remix-run/node"; import '@fontsource-variable/manrope'; import {Refine} from "@refinedev/core"; import routerProvider from "@refinedev/remix-router"; -import { notificationProvider } from "~/data/notification-provider"; -import {SdkContextProvider} from "~/components/lib/sdk-context"; -import { Toaster } from "~/components/ui/toaster"; +import {notificationProvider} from "~/data/notification-provider"; +import {SdkContextProvider, useSdk} from "~/components/lib/sdk-context"; +import {Toaster} from "~/components/ui/toaster"; import {getProviders} from "~/data/providers.js"; import {Sdk} from "@lumeweb/portal-sdk"; import resources from "~/data/resources.js"; +import {useMemo} from "react"; export const links: LinksFunction = () => [ - { rel: "stylesheet", href: stylesheet }, + {rel: "stylesheet", href: stylesheet}, ]; export function Layout({children}: { children: React.ReactNode }) { @@ -29,7 +30,7 @@ export function Layout({children}: { children: React.ReactNode }) { {children} - + @@ -37,9 +38,9 @@ export function Layout({children}: { children: React.ReactNode }) { ); } -export default function App() { - const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL) - const providers = getProviders(sdk); +function App() { + const sdk = useSdk(); + const providers = useMemo(() => getProviders(sdk as Sdk), [sdk]); return ( - - - + ); } +export default function Root() { + const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL) + return ( + + + + ); +} + export function HydrateFallback() { return

Loading...

; } From 6cdf8e40b9283e4dad0b205c73c526008a8a3464 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:13:35 -0400 Subject: [PATCH 29/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1acecee..474cd40 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321191714", + "@lumeweb/portal-sdk": "0.0.0-20240321201246", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From f7a760051f641effc4b0b3fcefe4e976fffdb239 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:15:04 -0400 Subject: [PATCH 30/38] refactor: use our own abort controller --- app/data/file-provider.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/data/file-provider.ts b/app/data/file-provider.ts index 8719b6f..448f441 100644 --- a/app/data/file-provider.ts +++ b/app/data/file-provider.ts @@ -11,13 +11,17 @@ async function getIsManifest(s5: S5Client, hash: string): Promise { if (progressEvent.loaded >= 10) { - resp.cancel(); + abort.abort(); } }, - }) as CancelablePromise; + httpConfig: { + signal: abort.signal, + }, + }); const data = await resp; const unpacker = Unpacker.fromPacked(Buffer.from(data)); From 0c304b20dbd6ba699a5d735db01c034b2eb26004 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:20:37 -0400 Subject: [PATCH 31/38] refactor: use new CID with the multihash --- app/data/file-provider.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/data/file-provider.ts b/app/data/file-provider.ts index 448f441..136d462 100644 --- a/app/data/file-provider.ts +++ b/app/data/file-provider.ts @@ -76,14 +76,15 @@ export const fileProvider: SdkProvider = { const manifest = await getIsManifest(s5, pin.hash) as number; if (manifest) { + const mHash = Multihash.fromBase64Url(pin.hash); items.push({ - cid: CID.fromHash(pin.hash, pin.size, manifest).toString(), + cid: new CID(manifest, mHash, pin.size).toString(), type: "manifest", mimeType: "application/octet-stream", }); } else { items.push({ - cid: CID.fromHash(pin.hash, pin.size, CID_TYPES.RAW).toString(), + cid: new CID(CID_TYPES.RAW, Multihash.fromBase64Url(pin.hash), pin.size).toString(), type: "raw", mimeType: pin.mime_type, }); From 20d8905a673d7b667616e56288a1cc0975172390 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:32:23 -0400 Subject: [PATCH 32/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 474cd40..caa7b2c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321201246", + "@lumeweb/portal-sdk": "0.0.0-20240321203143", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From 7ea4af13465d4ea631874de000c44c9157ec64e1 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:37:25 -0400 Subject: [PATCH 33/38] dep: update portal-sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index caa7b2c..90ad8ef 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@conform-to/react": "^1.0.2", "@conform-to/zod": "^1.0.2", "@fontsource-variable/manrope": "^5.0.19", - "@lumeweb/portal-sdk": "0.0.0-20240321203143", + "@lumeweb/portal-sdk": "0.0.0-20240321203634", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", From ea395df49495f26e7a05717e72984f263613bd66 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:45:06 -0400 Subject: [PATCH 34/38] refactor: add pinned property for date --- app/data/file-provider.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/data/file-provider.ts b/app/data/file-provider.ts index 136d462..a9b3b1e 100644 --- a/app/data/file-provider.ts +++ b/app/data/file-provider.ts @@ -3,9 +3,7 @@ import {S5Client} from "@lumeweb/s5-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"; +import {CID, CID_TYPES, METADATA_TYPES, metadataMagicByte, Unpacker} from "@lumeweb/libs5"; async function getIsManifest(s5: S5Client, hash: string): Promise { @@ -63,6 +61,7 @@ export interface FileItem { cid: string; type: string; mimeType: string; + pinned: string; } export const fileProvider: SdkProvider = { @@ -81,12 +80,14 @@ export const fileProvider: SdkProvider = { cid: new CID(manifest, mHash, pin.size).toString(), type: "manifest", mimeType: "application/octet-stream", + pinned: pin.pinned_at, }); } else { items.push({ cid: new CID(CID_TYPES.RAW, Multihash.fromBase64Url(pin.hash), pin.size).toString(), type: "raw", mimeType: pin.mime_type, + pinned: pin.pinned_at, }); } } From 23cc02b26e626b81fd6f8e3e6b7cac9abdb3d264 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:45:20 -0400 Subject: [PATCH 35/38] dep: add date-fns --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 90ad8ef..8acf6d0 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@visx/visx": "^3.10.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", + "date-fns": "^3.6.0", "react": "^18.2.0", "react-dom": "^18.2.0", "tailwind-merge": "^2.2.1", From 6252979d28417ad0c134787af65dafaf3d95eeb9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:46:02 -0400 Subject: [PATCH 36/38] refactor: update columns --- app/routes/file-manager/columns.tsx | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/routes/file-manager/columns.tsx b/app/routes/file-manager/columns.tsx index b4a1f2b..4812ccb 100644 --- a/app/routes/file-manager/columns.tsx +++ b/app/routes/file-manager/columns.tsx @@ -4,15 +4,8 @@ import { FileIcon, MoreIcon } from "~/components/icons"; import { Checkbox } from "~/components/ui/checkbox"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "~/components/ui/dropdown-menu"; import { cn } from "~/utils"; - -// This type is used to define the shape of our data. -// You can use a Zod schema here if you want. -export type File = { - name: string; - cid: string; - size: string; - createdOn: string; -}; +import {FileItem} from "~/data/file-provider.js"; +import {format} from "date-fns/fp"; declare module '@tanstack/table-core' { interface TableMeta { @@ -20,13 +13,13 @@ declare module '@tanstack/table-core' { } } -export const columns: ColumnDef[] = [ +export const columns: ColumnDef[] = [ { id: "select", size: 20, header: ({ table }) => ( [] = [ header: "Size", }, { - accessorKey: "createdOn", + accessorKey: "pinnedOn", size: 200, - header: "Created On", + header: "Pinned On", cell: ({ row }) => (
- {row.getValue("createdOn")} + {format(row.getValue("pinned")) as unknown as string} [] = [
) } -]; \ No newline at end of file +]; From 4619f9709ce56a6a2b018a313e8cdcc1794c7107 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:49:14 -0400 Subject: [PATCH 37/38] fix: size is missing --- app/data/file-provider.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/data/file-provider.ts b/app/data/file-provider.ts index a9b3b1e..4206821 100644 --- a/app/data/file-provider.ts +++ b/app/data/file-provider.ts @@ -60,6 +60,7 @@ async function getIsManifest(s5: S5Client, hash: string): Promise Date: Thu, 21 Mar 2024 17:00:30 -0400 Subject: [PATCH 38/38] fix: wrong accessorKey --- app/routes/file-manager/columns.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes/file-manager/columns.tsx b/app/routes/file-manager/columns.tsx index 4812ccb..5bd1aa0 100644 --- a/app/routes/file-manager/columns.tsx +++ b/app/routes/file-manager/columns.tsx @@ -57,7 +57,7 @@ export const columns: ColumnDef[] = [ header: "Size", }, { - accessorKey: "pinnedOn", + accessorKey: "pinned", size: 200, header: "Pinned On", cell: ({ row }) => (