Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit af3e2c8

Browse files
authored
chore: Merge pull request #45 from alist-org/dev
2 parents 38965d9 + 8d62361 commit af3e2c8

File tree

7 files changed

+37
-136
lines changed

7 files changed

+37
-136
lines changed

build_old.sh

Lines changed: 0 additions & 59 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@emotion/styled": "^11.8.1",
3232
"@monaco-editor/react": "^4.4.4",
3333
"@xhofe/react-viewer": "^3.2.3",
34-
"artplayer": "^4.3.1",
34+
"artplayer": "^4.4.3",
3535
"axios": "^0.26.0",
3636
"flv.js": "^1.6.2",
3737
"framer-motion": "^5.5.6",

src/pages/list/layout/files/menus/refresh.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import bus from "../../../../../utils/event-bus";
1010
import { IContext } from "../../../context";
1111

1212
const Refresh = () => {
13-
const { loggedIn } = useContext(IContext);
13+
const { loggedIn, setPage, page } = useContext(IContext);
1414
const { t } = useTranslation();
1515
const { refresh } = useApi();
1616
const toast = useToast();
@@ -28,6 +28,7 @@ const Refresh = () => {
2828
isClosable: true,
2929
});
3030
if (res.code === 200) {
31+
setPage({ ...page, page_num: 1 });
3132
bus.emit("refresh");
3233
}
3334
});
@@ -42,4 +43,4 @@ const Refresh = () => {
4243
);
4344
};
4445

45-
export default Refresh;
46+
export default Refresh;

src/pages/list/preview/codeeditor.tsx

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,14 @@
11
// Integrating the ESM version of the Monaco Editor
22
// https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md#using-vite
33

4-
// import * as monaco from 'monaco-editor';
5-
// self.MonacoEnvironment = {
6-
// getWorker: function (workerId, label) {
7-
// const getWorkerModule = (moduleUrl, label) => {
8-
// return new Worker(self.MonacoEnvironment.getWorkerUrl(moduleUrl), {
9-
// name: label,
10-
// type: 'module'
11-
// });
12-
// };
13-
14-
// switch (label) {
15-
// case 'json':
16-
// return getWorkerModule('/monaco-editor/esm/vs/language/json/json.worker?worker', label);
17-
// case 'css':
18-
// case 'scss':
19-
// case 'less':
20-
// return getWorkerModule('/monaco-editor/esm/vs/language/css/css.worker?worker', label);
21-
// case 'html':
22-
// case 'handlebars':
23-
// case 'razor':
24-
// return getWorkerModule('/monaco-editor/esm/vs/language/html/html.worker?worker', label);
25-
// case 'typescript':
26-
// case 'javascript':
27-
// return getWorkerModule('/monaco-editor/esm/vs/language/typescript/ts.worker?worker', label);
28-
// default:
29-
// return getWorkerModule('/monaco-editor/esm/vs/editor/editor.worker?worker', label);
30-
// }
31-
// }
32-
// };
33-
344
import Editor from "@monaco-editor/react";
355
import {
366
Box,
37-
Select,
387
Button,
398
Flex,
409
Spacer,
4110
useColorModeValue,
4211
useToast,
43-
Heading,
4412
} from "@chakra-ui/react";
4513
import React from "react";
4614
import axios from "axios";
@@ -49,29 +17,27 @@ import { useTranslation } from "react-i18next";
4917
import useFileUrl from "../../../hooks/useFileUrl";
5018
import { FileProps } from "../context";
5119
import request from "../../../utils/public";
20+
import { File } from "../context";
5221

5322
export const type = -1;
5423
export const exts = [];
5524

56-
const CodeEditor = ({ file }: FileProps) => {
25+
export interface CodeEditorProps {
26+
file: File;
27+
content: string;
28+
setContent: (content: string) => void;
29+
}
30+
31+
const CodeEditor = ({ file, content, setContent }: CodeEditorProps) => {
5732
const theme = useColorModeValue("light", "dark");
5833
const { t } = useTranslation();
5934
const toast = useToast();
6035
const { pathname } = useLocation();
6136

62-
const [content, setContent] = React.useState<string | undefined>("");
63-
64-
let link = useFileUrl(true)(file);
65-
const getContent = () => {
66-
axios.get(link).then(async (resp) => {
67-
setContent(resp.data);
68-
});
69-
};
70-
7137
const handleSaveButton: React.MouseEventHandler = async () => {
7238
const folder = pathname.substring(0, pathname.lastIndexOf("/") || 1);
7339
const form = new FormData();
74-
form.append("files", new Blob([content as string]), file.name);
40+
form.append("files", new Blob([content]), file.name);
7541
form.append("path", folder);
7642
request
7743
.post("upload", form, {
@@ -89,9 +55,6 @@ const CodeEditor = ({ file }: FileProps) => {
8955
});
9056
});
9157
};
92-
React.useEffect(() => {
93-
getContent();
94-
}, []);
9558

9659
return (
9760
<Box>
@@ -100,7 +63,7 @@ const CodeEditor = ({ file }: FileProps) => {
10063
value={content}
10164
path={file.name}
10265
theme={theme === "light" ? "light" : "vs-dark"}
103-
onChange={(value) => setContent(value)}
66+
onChange={(value) => setContent(value ?? "")}
10467
/>
10568
<Flex m="2">
10669
<Spacer />

src/pages/list/preview/markdown.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export const exts = [];
1414

1515
const MarkdownPreview = ({ file, readme }: FileProps) => {
1616
const [content, setContent] = React.useState("");
17-
const [srcDoc, setSrcDoc] = React.useState("");
18-
const { getSetting,loggedIn } = useContext(IContext);
17+
const { getSetting, loggedIn } = useContext(IContext);
1918
let link = useFileUrl(true)(file);
2019
const html = file.name.endsWith(".html");
2120
const [show, setShow] = React.useState("preview");
@@ -36,16 +35,7 @@ const MarkdownPreview = ({ file, readme }: FileProps) => {
3635
const decoder = new TextDecoder("gbk");
3736
res = decoder.decode(await blob.arrayBuffer());
3837
}
39-
if (html) {
40-
setSrcDoc(res);
41-
}
42-
if (file.name.endsWith(".md")) {
43-
setContent(res);
44-
} else {
45-
setContent(
46-
"```" + file.name.split(".").pop() + "\n" + res + "\n" + "```"
47-
);
48-
}
38+
setContent(res);
4939
});
5040
};
5141
useEffect(() => {
@@ -89,7 +79,7 @@ const MarkdownPreview = ({ file, readme }: FileProps) => {
8979
</HStack>
9080
{show === "render" ? (
9181
<iframe
92-
srcDoc={srcDoc}
82+
srcDoc={content}
9383
style={{
9484
width: "100%",
9585
borderRadius: "0.75rem",
@@ -98,10 +88,19 @@ const MarkdownPreview = ({ file, readme }: FileProps) => {
9888
}}
9989
></iframe>
10090
) : show === "edit" ? (
101-
<CodeEditor file={file} />
91+
<CodeEditor content={content} setContent={setContent} file={file} />
10292
) : (
10393
<Box className="markdown-body">
104-
<Markdown>{content}</Markdown>
94+
<Markdown>
95+
{file.name.endsWith(".md")
96+
? content
97+
: "```" +
98+
file.name.split(".").pop() +
99+
"\n" +
100+
content +
101+
"\n" +
102+
"```"}
103+
</Markdown>
105104
</Box>
106105
)}
107106
</Box>

src/pages/list/preview/pdf.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { Center } from "@chakra-ui/react";
2-
import React from "react";
2+
import React, { useContext } from "react";
3+
import { IContext } from "../context";
34

45
export const type = -1;
56
export const exts = [];
67

78
const Pdf = ({ url, unfold }: { url: string; unfold: boolean }) => {
9+
const { getSetting } = useContext(IContext)
10+
const pdfPreviewUrl = getSetting("pdf viewer url") || "https://alist-org.github.io/pdf.js/web/viewer.html?file=$url";
811
return (
912
<Center w="full" h="full" className="pdf-preview-box">
1013
<iframe
1114
title="pdf-viewer"
1215
width="100%"
1316
height="100%"
14-
src={`https://alist-org.github.io/pdf.js/web/viewer.html?file=${url}`}
17+
src={pdfPreviewUrl.replace("$url", url)}
1518
/>
1619
</Center>
1720
);

yarn.lock

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,13 +1214,12 @@ aria-hidden@^1.1.1:
12141214
dependencies:
12151215
tslib "^1.0.0"
12161216

1217-
artplayer@^4.3.1:
1218-
version "4.3.1"
1219-
resolved "https://registry.yarnpkg.com/artplayer/-/artplayer-4.3.1.tgz#8e1203129a17f19b6fe5de216d04f1bd139d6bb7"
1220-
integrity sha512-X0yD+PR4n07W9KMZpqX3R9kWzDF6QNaBDoeXzZU8kcFEgAwiueC4nkLR4NIVEuX02GWEEWfQgZ7Q2rNn6tLIrA==
1217+
artplayer@^4.4.3:
1218+
version "4.4.3"
1219+
resolved "https://registry.yarnpkg.com/artplayer/-/artplayer-4.4.3.tgz#9387d30ecac836f4918d6c083a6cb66d97932ed3"
1220+
integrity sha512-RdIWInmYJquUfSuM2h/dh4MjH9SR0fcQoFWL38GgT55RuvjbiVnH/lWZASeEBveCnA1jntVDpiCZYf54wGOENQ==
12211221
dependencies:
12221222
option-validator "^2.0.6"
1223-
screenfull "^6.0.1"
12241223

12251224
axios@^0.26.0:
12261225
version "0.26.0"
@@ -3083,11 +3082,6 @@ scheduler@^0.20.2:
30833082
loose-envify "^1.1.0"
30843083
object-assign "^4.1.1"
30853084

3086-
screenfull@^6.0.1:
3087-
version "6.0.1"
3088-
resolved "https://registry.yarnpkg.com/screenfull/-/screenfull-6.0.1.tgz#3b71e6f06b72d817a8d3be73c45ebe71fa8da1ce"
3089-
integrity sha512-yzQW+j4zMUBQC51xxWaoDYjxOtl8Kn+xvue3p6v/fv2pIi1jH4AldgVLU8TBfFVgH2x3VXlf3+YiA/AYIPlaew==
3090-
30913085
semver@^6.3.0:
30923086
version "6.3.0"
30933087
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"

0 commit comments

Comments
 (0)