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

subfolder under domain support #49

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<script>
window.ALIST = {
cdn: "/CDN_URL/",
subfolder: "SUB_FOLDER",
api: undefined,
};
</script>
Expand Down
13 changes: 12 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ import { ClimbingBoxLoader } from "react-spinners";
import { Toaster } from 'react-hot-toast';

function App() {
let subfolder = ""
if (window.ALIST.subfolder) {
subfolder = window.ALIST.subfolder;
}
if (subfolder.endsWith("/")) {
subfolder = subfolder.substring(0, subfolder.length - 1);
}
if (subfolder.startsWith("/")) {
subfolder = subfolder.substring(1);
}

return (
<div className="App">
<div><Toaster/></div>
<Router>
<Router basename={"/" + subfolder} >
<Suspense
fallback={
<Center h="100vh">
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEncrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useEncrypt = () => {
return link;
}
const name = url.split("/").pop();
const token = localStorage.getItem("admin-token");
const token = localStorage.getItem("alist_admin-token");
if (loggedIn) {
const sign = md5_16(`alist-${token}-${name}`);
return link + (encode ? encodeURI(`?sign=${sign}`) : `?sign=${sign}`);
Expand Down
14 changes: 12 additions & 2 deletions src/hooks/useFolderLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ const useFolderLink = (proxy = false) => {
if (type === "file") {
path = path.substring(0, path.lastIndexOf("/"));
}
let subfolder = ""
if (window.ALIST.subfolder) {
subfolder = window.ALIST.subfolder;
}
if (subfolder.endsWith("/")) {
subfolder = subfolder.substring(0, subfolder.length - 1);
}
if (subfolder.startsWith("/")) {
subfolder = subfolder.substring(1);
}
if (proxy) {
return `${host}p${path}`;
return `${host}${subfolder}/p${path}`;
}
return `${host}d${path}`;
return `${host}${subfolder}/d${path}`;
};

export default useFolderLink;
4 changes: 2 additions & 2 deletions src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function useLocalStorage<T>(key: string, initialValue: T) {
const [storedValue, setStoredValue] = useState<T>(() => {
try {
// Get from local storage by key
const item = window.localStorage.getItem(key);
const item = window.localStorage.getItem("alist_" + key);
// Parse stored json or if none return initialValue
return item ? JSON.parse(item) : initialValue;
} catch (error) {
Expand All @@ -26,7 +26,7 @@ function useLocalStorage<T>(key: string, initialValue: T) {
// Save state
setStoredValue(valueToStore);
// Save to local storage
window.localStorage.setItem(key, JSON.stringify(valueToStore));
window.localStorage.setItem("alist_" + key, JSON.stringify(valueToStore));
} catch (error) {
// A more advanced implementation would handle the error case
console.log(error);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/list/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const IContextProvider = (props: any) => {
const [msg, setMsg] = useState("");
const [settingLoaded, setSettingLoaded] = React.useState<boolean>(false);
const [password, setPassword] = React.useState<string>(
localStorage.getItem("password") || ""
localStorage.getItem("alist_password") || ""
);
const [sort, setSort] = useState<Sort>({
orderBy: undefined,
Expand All @@ -170,7 +170,7 @@ const IContextProvider = (props: any) => {
const [selectFiles, setSelectFiles] = useState<File[]>([]);

const [show, setShow] = React.useState<string>(
localStorage.getItem("show") || "list"
localStorage.getItem("alist_show") || "list"
);

const [page, setPage] = React.useState<Page>({
Expand Down Expand Up @@ -257,7 +257,7 @@ const IContextProvider = (props: any) => {
});
}, []);
const login = useCallback(() => {
if (!localStorage.getItem("admin-token")) {
if (!localStorage.getItem("alist_admin-token")) {
return;
}
admin.get("login").then((resp) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const Do = (props: any) => {
}}
onKeyUp={(e) => {
if (e.key === "Enter") {
localStorage.setItem("password", password);
localStorage.setItem("alist_password", password);
inputPass = true;
refresh();
onClose();
Expand All @@ -220,7 +220,7 @@ const Do = (props: any) => {
<ModalFooter>
<Button
onClick={() => {
localStorage.setItem("password", password);
localStorage.setItem("alist_password", password);
inputPass = true;
refresh();
onClose();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/list/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const Header = () => {
onClick={() => {
setShow!(show === "list" ? "grid" : "list");
localStorage.setItem(
"show",
"alist_show",
show === "list" ? "grid" : "list"
);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/list/preview/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Video = ({ file }: FileProps) => {
let fileUrl = useFileUrl();
let link = fileUrl();
const proxyLink = useFolderLink(true);
const url = file.name.endsWith(".m3u8") ? link : file.url;
const url = link; //file.name.endsWith(".m3u8") ? link : file.url;
const history = useHistory();
let art: Artplayer;
const subtitleSize = useBreakpointValue({
Expand Down
18 changes: 14 additions & 4 deletions src/utils/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ if (window.ALIST.api) {
api = window.ALIST.api;
}

let subfolder = ""
if (window.ALIST.subfolder) {
subfolder = window.ALIST.subfolder;
}
if (!subfolder.endsWith("/")) {
subfolder = subfolder + "/";
}
if (subfolder.startsWith("/")) {
subfolder = subfolder.substring(1);
}
const instance = axios.create({
baseURL: api + "api/admin/",
baseURL: api + subfolder + "api/admin/",
// timeout: 5000
headers: {
"Content-Type": "application/json;charset=utf-8",
// 'Authorization': localStorage.getItem("admin-token") || "",
// 'Authorization': localStorage.getItem("alist_admin-token") || "",
},
withCredentials: false,
});
Expand Down Expand Up @@ -47,7 +57,7 @@ instance.interceptors.response.use(
);

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

export const changeToken = (password: string) => {
let token = "";
Expand All @@ -56,7 +66,7 @@ export const changeToken = (password: string) => {
}
instance.defaults.headers.common["Authorization"] = token;
publicR.defaults.headers.common["Authorization"] = token;
localStorage.setItem("admin-token", token);
localStorage.setItem("alist_admin-token", token);
};

export default instance;
16 changes: 13 additions & 3 deletions src/utils/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ if (window.ALIST.api) {
api = window.ALIST.api;
}

let subfolder = ""
if (window.ALIST.subfolder) {
subfolder = window.ALIST.subfolder;
}
if (!subfolder.endsWith("/")) {
subfolder = subfolder + "/";
}
if (subfolder.startsWith("/")) {
subfolder = subfolder.substring(1);
}
const instance = axios.create({
baseURL: api + "api/public/",
baseURL: api + subfolder + "api/public/",
// timeout: 5000
headers: {
"Content-Type": "application/json;charset=utf-8",
// 'Authorization': localStorage.getItem("admin-token") || "",
// 'Authorization': localStorage.getItem("alist_admin-token") || "",
},
withCredentials: false,
});
Expand Down Expand Up @@ -45,6 +55,6 @@ instance.interceptors.response.use(
);

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

export default instance;