From 3b540dacc895ba76cd69148a1ee734a1a99ebc76 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sun, 11 Sep 2022 19:15:20 +0800 Subject: [PATCH] feat: add aliyun office previewer --- index.html | 1 + src/index.d.ts | 6 ++++ src/pages/home/previews/aliyun_office.tsx | 36 +++++++++++++++++++++++ src/pages/home/previews/index.ts | 6 ++++ 4 files changed, 49 insertions(+) create mode 100644 src/pages/home/previews/aliyun_office.tsx diff --git a/index.html b/index.html index 9217910..9f0e9f6 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,7 @@ + { + const { pathname } = useRouter(); + const [loading, post] = useFetch( + (): Promise> => + r.post("/fs/other", { + path: pathname(), + password: password(), + method: "doc_preview" + }) + ); + const init = async () => { + const resp = await post(); + handleRresp(resp, (data) => { + const docOptions = aliyun.config({ + mount: document.querySelector("#office-preview")!, + url: data.preview_url, + }); + docOptions.setToken({ token: data.access_token }); + }); + }; + init(); + return ( + + + + ); +}; + +export default AliDocPreview; diff --git a/src/pages/home/previews/index.ts b/src/pages/home/previews/index.ts index 6a18468..77f7df7 100644 --- a/src/pages/home/previews/index.ts +++ b/src/pages/home/previews/index.ts @@ -55,6 +55,12 @@ const previews: Preview[] = [ exts: ["plist"], component: lazy(() => import("./plist")), }, + { + name: "Aliyun Office Previewer", + exts: ["doc", "docx", "ppt", "pptx", "xls", "xlsx", "pdf"], + provider: /Aliyundrive/, + component: lazy(() => import("./aliyun_office")), + }, ]; export const getPreviews = (