feat: add aliyun office previewer

This commit is contained in:
Noah Hsu
2022-09-11 19:15:20 +08:00
parent 09699c10ab
commit 3b540dacc8
4 changed files with 49 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
<meta name="referrer" content="same-origin" />
<meta name="generator" content="AList V3" />
<meta name="theme-color" content="#000000" />
<script src="https://g.alicdn.com/IMM/office-js/1.1.5/aliyun-web-office-sdk.min.js" async></script>
<link
rel="shortcut icon"
type="image/ico"

6
src/index.d.ts vendored
View File

@@ -1 +1,7 @@
declare module "aplayer";
declare namespace aliyun {
class Config {
setToken(token: { token: string }): any;
}
function config(options: { mount: Element; url: string }): Config;
}

View File

@@ -0,0 +1,36 @@
import { Box } from "@hope-ui/solid";
import { MaybeLoading } from "~/components";
import { useFetch, useRouter } from "~/hooks";
import { password } from "~/store";
import { Resp } from "~/types";
import { handleRresp, r } from "~/utils";
const AliDocPreview = () => {
const { pathname } = useRouter();
const [loading, post] = useFetch(
(): Promise<Resp<{ access_token: string; preview_url: string }>> =>
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 (
<MaybeLoading loading={loading()}>
<Box w="$full" h="70vh" id="office-preview"></Box>
</MaybeLoading>
);
};
export default AliDocPreview;

View File

@@ -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 = (