diff --git a/apps/core/src/components/affine/create-workspace-modal/index.tsx b/apps/core/src/components/affine/create-workspace-modal/index.tsx index 34712ec244..e9eb1803ae 100644 --- a/apps/core/src/components/affine/create-workspace-modal/index.tsx +++ b/apps/core/src/components/affine/create-workspace-modal/index.tsx @@ -139,7 +139,6 @@ const SetDBLocationContent = ({ if (result?.filePath) { onConfirmLocation(result.filePath); } else if (result?.error) { - // @ts-expect-error: result.error is dynamic so the type is unknown toast(t[result.error]()); } })().catch(err => { @@ -273,7 +272,6 @@ export const CreateWorkspaceModal = ({ setStep('set-syncing-mode'); } else if (result.error || result.canceled) { if (result.error) { - // @ts-expect-error: result.error is dynamic so the type is unknown toast(t[result.error]()); } onClose(); diff --git a/apps/core/src/components/affine/new-workspace-setting-detail/export.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/export.tsx index fa31d40832..7ee0c63e31 100644 --- a/apps/core/src/components/affine/new-workspace-setting-detail/export.tsx +++ b/apps/core/src/components/affine/new-workspace-setting-detail/export.tsx @@ -36,7 +36,6 @@ export const ExportPanel: FC<{ await syncBlobsToSqliteDb(workspace); const result = await window.apis?.dialog.saveDBFileAs(workspaceId); if (result?.error) { - // @ts-expect-error: result.error is dynamic toast(t[result.error]()); } else if (!result?.canceled) { toast(t['Export success']()); diff --git a/apps/core/src/components/affine/new-workspace-setting-detail/storage.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/storage.tsx index 0a819e71cc..269dee42d2 100644 --- a/apps/core/src/components/affine/new-workspace-setting-detail/storage.tsx +++ b/apps/core/src/components/affine/new-workspace-setting-detail/storage.tsx @@ -55,7 +55,6 @@ export const StoragePanel: FC<{ if (!result?.error && !result?.canceled) { toast(t['Move folder success']()); } else if (result?.error) { - // @ts-expect-error: result.error is dynamic toast(t[result.error]()); } }) diff --git a/apps/electron/src/helper/dialog/dialog.ts b/apps/electron/src/helper/dialog/dialog.ts index d9f9add1c9..a304a4c1d0 100644 --- a/apps/electron/src/helper/dialog/dialog.ts +++ b/apps/electron/src/helper/dialog/dialog.ts @@ -1,6 +1,13 @@ import path from 'node:path'; import { ValidationResult } from '@affine/native'; +import type { + FakeDialogResult, + LoadDBFileResult, + MoveDBFileResult, + SaveDBFileResult, + SelectDBFileLocationResult, +} from '@toeverything/infra/type'; import fs from 'fs-extra'; import { nanoid } from 'nanoid'; @@ -28,13 +35,6 @@ export async function revealDBFile(workspaceId: string) { await mainRPC.showItemInFolder(meta.secondaryDBPath ?? meta.mainDBPath); } -// provide a backdoor to set dialog path for testing in playwright -export interface FakeDialogResult { - canceled?: boolean; - filePath?: string; - filePaths?: string[]; -} - // result will be used in the next call to showOpenDialog // if it is being read once, it will be reset to undefined let fakeDialogResult: FakeDialogResult | undefined = undefined; @@ -53,23 +53,6 @@ export function setFakeDialogResult(result: FakeDialogResult | undefined) { } } -const ErrorMessages = [ - 'DB_FILE_ALREADY_LOADED', - 'DB_FILE_PATH_INVALID', - 'DB_FILE_INVALID', - 'DB_FILE_MIGRATION_FAILED', - 'FILE_ALREADY_EXISTS', - 'UNKNOWN_ERROR', -] as const; - -type ErrorMessage = (typeof ErrorMessages)[number]; - -export interface SaveDBFileResult { - filePath?: string; - canceled?: boolean; - error?: ErrorMessage; -} - const extension = 'affine'; function getDefaultDBFileName(name: string, id: string) { @@ -125,12 +108,6 @@ export async function saveDBFileAs( } } -export interface SelectDBFileLocationResult { - filePath?: string; - error?: ErrorMessage; - canceled?: boolean; -} - export async function selectDBFileLocation(): Promise { try { const ret = @@ -157,12 +134,6 @@ export async function selectDBFileLocation(): Promise { } } -export interface MoveDBFileResult { - filePath?: string; - error?: ErrorMessage; - canceled?: boolean; -} - /** * This function is called when the user clicks the "Move" button in the "Move Workspace Storage" setting. * diff --git a/packages/infra/src/type.ts b/packages/infra/src/type.ts index a3334da36a..d4ee55b1f1 100644 --- a/packages/infra/src/type.ts +++ b/packages/infra/src/type.ts @@ -105,9 +105,9 @@ export type DBHandlers = { key: string, data: Uint8Array ) => Promise; - getBlob: (workspaceId: string, key: string) => Promise; + getBlob: (workspaceId: string, key: string) => Promise; deleteBlob: (workspaceId: string, key: string) => Promise; - getBlobKeys: (workspaceId: string) => Promise; + getBlobKeys: (workspaceId: string) => Promise; getDefaultStorageLocation: () => Promise; }; @@ -116,13 +116,55 @@ export type DebugHandlers = { logFilePath: () => Promise; }; +export type ErrorMessage = + | 'DB_FILE_ALREADY_LOADED' + | 'DB_FILE_PATH_INVALID' + | 'DB_FILE_INVALID' + | 'DB_FILE_MIGRATION_FAILED' + | 'FILE_ALREADY_EXISTS' + | 'UNKNOWN_ERROR'; + +export interface LoadDBFileResult { + workspaceId?: string; + error?: ErrorMessage; + canceled?: boolean; +} + +export interface SaveDBFileResult { + filePath?: string; + canceled?: boolean; + error?: ErrorMessage; +} + +export interface SelectDBFileLocationResult { + filePath?: string; + error?: ErrorMessage; + canceled?: boolean; +} + +export interface MoveDBFileResult { + filePath?: string; + error?: ErrorMessage; + canceled?: boolean; +} + +// provide a backdoor to set dialog path for testing in playwright +export interface FakeDialogResult { + canceled?: boolean; + filePath?: string; + filePaths?: string[]; +} + export type DialogHandlers = { - revealDBFile: (workspaceId: string) => Promise; - loadDBFile: () => Promise; - saveDBFileAs: (workspaceId: string) => Promise; - moveDBFile: (workspaceId: string, dbFileLocation?: string) => Promise; - selectDBFileLocation: () => Promise; - setFakeDialogResult: (result: any) => Promise; + revealDBFile: (workspaceId: string) => Promise; + loadDBFile: () => Promise; + saveDBFileAs: (workspaceId: string) => Promise; + moveDBFile: ( + workspaceId: string, + dbFileLocation?: string + ) => Promise; + selectDBFileLocation: () => Promise; + setFakeDialogResult: (result: any) => Promise; }; export type UIHandlers = {