Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: import interfaces and error message (#6630)
Kilu.Heb9ec9f863d22
diff --git a/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts b/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.tsindex bf51b34b1f..ecb67a3676 100644--- a/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts+++ b/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts@@ -1175,7 +1175,56 @@ export async function getActiveSubscription (workspaceId: string) {return Promise.reject(response?.data);}-export async function importFile (file: File, onProgress: (progress: number) => void) {+export async function createImportTask (file: File) {+ const url = `/api/import/create`;+ const fileName = file.name.split('.').slice(0, -1).join('.') || crypto.randomUUID();++ const res = await axiosInstance?.post<{+ code: number;+ data: {+ task_id: string;+ presigned_url: string;+ };+ message: string;+ }>(url, {+ workspace_name: fileName,+ content_length: file.size,+ });++ if (res?.data.code === 0) {+ return {+ taskId: res?.data.data.task_id,+ presignedUrl: res?.data.data.presigned_url,+ };+ }++ return Promise.reject(res?.data);+}++export async function uploadImportFile (presignedUrl: string, file: File, onProgress: (progress: number) => void) {+ const response = await axios.put(presignedUrl, file, {+ onUploadProgress: (progressEvent) => {+ const { progress = 0 } = progressEvent;++ console.log(`Upload progress: ${progress * 100}%`);+ onProgress(progress);+ },+ headers: {+ 'Content-Type': 'application/zip',+ },+ });++ if (response.status === 200) {+ return;+ }++ return Promise.reject({+ code: -1,+ message: `Upload file failed. ${response.statusText}`,+ });+}++export async function uploadFile (file: File, onProgress: (progress: number) => void) {const url = `/api/import`;const fileName = file.name.split('.').slice(0, -1).join('.') || crypto.randomUUID();diff --git a/frontend/appflowy_web_app/src/application/services/js-services/index.ts b/frontend/appflowy_web_app/src/application/services/js-services/index.tsindex 0d04333289..9a28db7f7e 100644--- a/frontend/appflowy_web_app/src/application/services/js-services/index.ts+++ b/frontend/appflowy_web_app/src/application/services/js-services/index.ts@@ -472,7 +472,13 @@ export class AFClientService implements AFService {sync.initialize();}- importFile (file: File, onProgress: (progress: number) => void) {- return APIService.importFile(file, onProgress);+ uploadFile (file: File, onProgress: (progress: number) => void) {+ return APIService.uploadFile(file, onProgress);+ }++ async importFile (file: File, onProgress: (progress: number) => void) {+ const task = await APIService.createImportTask(file);++ await APIService.uploadImportFile(task.presignedUrl, file, onProgress);}}diff --git a/frontend/appflowy_web_app/src/application/services/services.type.ts b/frontend/appflowy_web_app/src/application/services/services.type.tsindex 282915d84d..dd4fcd8399 100644--- a/frontend/appflowy_web_app/src/application/services/services.type.ts+++ b/frontend/appflowy_web_app/src/application/services/services.type.ts@@ -65,6 +65,7 @@ export interface AppService {getSubscriptions: () => Promise<Subscriptions>;getActiveSubscription: (workspaceId: string) => Promise<SubscriptionPlan[]>;registerDocUpdate: (doc: YDoc, workspaceId: string, objectId: string) => void;+ uploadFile: (file: File, onProgress: (progress: number) => void) => Promise<void>;importFile: (file: File, onProgress: (progress: number) => void) => Promise<void>;}diff --git a/frontend/appflowy_web_app/src/application/services/tauri-services/index.ts b/frontend/appflowy_web_app/src/application/services/tauri-services/index.tsindex c0a4d8e220..1f6816588c 100644--- a/frontend/appflowy_web_app/src/application/services/tauri-services/index.ts+++ b/frontend/appflowy_web_app/src/application/services/tauri-services/index.ts@@ -262,6 +262,10 @@ export class AFClientService implements AFService {throw new Error('Method not implemented.');}+ uploadFile (_file: File, _onProgress: (progress: number) => void) {+ return Promise.reject('Method not implemented');+ }+importFile (_file: File, _onProgress: (progress: number) => void) {return Promise.reject('Method not implemented');}diff --git a/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterDialogContent.tsx b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterDialogContent.tsxindex 7ace275f77..3e98853bcc 100644--- a/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterDialogContent.tsx+++ b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterDialogContent.tsx@@ -22,14 +22,16 @@ function ImporterDialogContent ({const handleUpload = useCallback(async (file: File) => {setIsError(false);+ if (!service) return;try {- await service?.importFile(file, setProgress);+ await service.importFile(file, setProgress);onSuccess();- } catch (e) {- notify.error(t('web.importFailed'));+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ } catch (e: any) {+ notify.error(e.message);setIsError(true);}- }, [onSuccess, service, t]);+ }, [onSuccess, service]);return (<div className={'flex flex-col gap-8'}>