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

Commit 0db29b5

Browse files
eaglexmw-gmailYCKJ2082
andauthored
feat: Added SubFolder configuration to support secondary subdirectory access under the domain name (#49)
Co-authored-by: YCKJ2082 <[email protected]>
1 parent 77bc2e0 commit 0db29b5

File tree

11 files changed

+62
-20
lines changed

11 files changed

+62
-20
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<script>
3535
window.ALIST = {
3636
cdn: "/CDN_URL/",
37+
subfolder: "SUB_FOLDER",
3738
api: undefined,
3839
};
3940
</script>

src/App.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ import { ClimbingBoxLoader } from "react-spinners";
77
import { Toaster } from 'react-hot-toast';
88

99
function App() {
10+
let subfolder = ""
11+
if (window.ALIST.subfolder) {
12+
subfolder = window.ALIST.subfolder;
13+
}
14+
if (subfolder.endsWith("/")) {
15+
subfolder = subfolder.substring(0, subfolder.length - 1);
16+
}
17+
if (subfolder.startsWith("/")) {
18+
subfolder = subfolder.substring(1);
19+
}
20+
1021
return (
1122
<div className="App">
1223
<div><Toaster/></div>
13-
<Router>
24+
<Router basename={"/" + subfolder} >
1425
<Suspense
1526
fallback={
1627
<Center h="100vh">

src/hooks/useEncrypt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const useEncrypt = () => {
1010
return link;
1111
}
1212
const name = url.split("/").pop();
13-
const token = localStorage.getItem("admin-token");
13+
const token = localStorage.getItem("alist_admin-token");
1414
if (loggedIn) {
1515
const sign = md5_16(`alist-${token}-${name}`);
1616
return link + (encode ? encodeURI(`?sign=${sign}`) : `?sign=${sign}`);

src/hooks/useFolderLink.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,20 @@ const useFolderLink = (proxy = false) => {
1313
if (type === "file") {
1414
path = path.substring(0, path.lastIndexOf("/"));
1515
}
16+
let subfolder = ""
17+
if (window.ALIST.subfolder) {
18+
subfolder = window.ALIST.subfolder;
19+
}
20+
if (subfolder.endsWith("/")) {
21+
subfolder = subfolder.substring(0, subfolder.length - 1);
22+
}
23+
if (subfolder.startsWith("/")) {
24+
subfolder = subfolder.substring(1);
25+
}
1626
if (proxy) {
17-
return `${host}p${path}`;
27+
return `${host}${subfolder}/p${path}`;
1828
}
19-
return `${host}d${path}`;
29+
return `${host}${subfolder}/d${path}`;
2030
};
2131

2232
export default useFolderLink;

src/hooks/useLocalStorage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function useLocalStorage<T>(key: string, initialValue: T) {
77
const [storedValue, setStoredValue] = useState<T>(() => {
88
try {
99
// Get from local storage by key
10-
const item = window.localStorage.getItem(key);
10+
const item = window.localStorage.getItem("alist_" + key);
1111
// Parse stored json or if none return initialValue
1212
return item ? JSON.parse(item) : initialValue;
1313
} catch (error) {
@@ -26,7 +26,7 @@ function useLocalStorage<T>(key: string, initialValue: T) {
2626
// Save state
2727
setStoredValue(valueToStore);
2828
// Save to local storage
29-
window.localStorage.setItem(key, JSON.stringify(valueToStore));
29+
window.localStorage.setItem("alist_" + key, JSON.stringify(valueToStore));
3030
} catch (error) {
3131
// A more advanced implementation would handle the error case
3232
console.log(error);

src/pages/list/context.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const IContextProvider = (props: any) => {
160160
const [msg, setMsg] = useState("");
161161
const [settingLoaded, setSettingLoaded] = React.useState<boolean>(false);
162162
const [password, setPassword] = React.useState<string>(
163-
localStorage.getItem("password") || ""
163+
localStorage.getItem("alist_password") || ""
164164
);
165165
const [sort, setSort] = useState<Sort>({
166166
orderBy: undefined,
@@ -170,7 +170,7 @@ const IContextProvider = (props: any) => {
170170
const [selectFiles, setSelectFiles] = useState<File[]>([]);
171171

172172
const [show, setShow] = React.useState<string>(
173-
localStorage.getItem("show") || "list"
173+
localStorage.getItem("alist_show") || "list"
174174
);
175175

176176
const [page, setPage] = React.useState<Page>({
@@ -257,7 +257,7 @@ const IContextProvider = (props: any) => {
257257
});
258258
}, []);
259259
const login = useCallback(() => {
260-
if (!localStorage.getItem("admin-token")) {
260+
if (!localStorage.getItem("alist_admin-token")) {
261261
return;
262262
}
263263
admin.get("login").then((resp) => {

src/pages/list/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const Do = (props: any) => {
208208
}}
209209
onKeyUp={(e) => {
210210
if (e.key === "Enter") {
211-
localStorage.setItem("password", password);
211+
localStorage.setItem("alist_password", password);
212212
inputPass = true;
213213
refresh();
214214
onClose();
@@ -220,7 +220,7 @@ const Do = (props: any) => {
220220
<ModalFooter>
221221
<Button
222222
onClick={() => {
223-
localStorage.setItem("password", password);
223+
localStorage.setItem("alist_password", password);
224224
inputPass = true;
225225
refresh();
226226
onClose();

src/pages/list/layout/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const Header = () => {
167167
onClick={() => {
168168
setShow!(show === "list" ? "grid" : "list");
169169
localStorage.setItem(
170-
"show",
170+
"alist_show",
171171
show === "list" ? "grid" : "list"
172172
);
173173
}}

src/pages/list/preview/video.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const Video = ({ file }: FileProps) => {
3535
let fileUrl = useFileUrl();
3636
let link = fileUrl();
3737
const proxyLink = useFolderLink(true);
38-
const url = file.name.endsWith(".m3u8") ? link : file.url;
38+
const url = link; //file.name.endsWith(".m3u8") ? link : file.url;
3939
const history = useHistory();
4040
let art: Artplayer;
4141
const subtitleSize = useBreakpointValue({

src/utils/admin.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ if (window.ALIST.api) {
77
api = window.ALIST.api;
88
}
99

10+
let subfolder = ""
11+
if (window.ALIST.subfolder) {
12+
subfolder = window.ALIST.subfolder;
13+
}
14+
if (!subfolder.endsWith("/")) {
15+
subfolder = subfolder + "/";
16+
}
17+
if (subfolder.startsWith("/")) {
18+
subfolder = subfolder.substring(1);
19+
}
1020
const instance = axios.create({
11-
baseURL: api + "api/admin/",
21+
baseURL: api + subfolder + "api/admin/",
1222
// timeout: 5000
1323
headers: {
1424
"Content-Type": "application/json;charset=utf-8",
15-
// 'Authorization': localStorage.getItem("admin-token") || "",
25+
// 'Authorization': localStorage.getItem("alist_admin-token") || "",
1626
},
1727
withCredentials: false,
1828
});
@@ -47,7 +57,7 @@ instance.interceptors.response.use(
4757
);
4858

4959
instance.defaults.headers.common["Authorization"] =
50-
localStorage.getItem("admin-token") || "";
60+
localStorage.getItem("alist_admin-token") || "";
5161

5262
export const changeToken = (password: string) => {
5363
let token = "";
@@ -56,7 +66,7 @@ export const changeToken = (password: string) => {
5666
}
5767
instance.defaults.headers.common["Authorization"] = token;
5868
publicR.defaults.headers.common["Authorization"] = token;
59-
localStorage.setItem("admin-token", token);
69+
localStorage.setItem("alist_admin-token", token);
6070
};
6171

6272
export default instance;

0 commit comments

Comments
 (0)