Refact: move explorer reducer (#30)

* Refact: move explorer reducer

* Fix: 添加TS eslint 规则,修复所有报错

* Fix: 修复Ts报错,添加React resolution 版本16.9.35. 添加tsconfig moduleResolution
This commit is contained in:
TS 2020-05-17 18:04:06 -07:00 committed by GitHub
parent f958c1e5a8
commit f427033b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
119 changed files with 1258 additions and 1210 deletions

View File

@ -1,10 +1,12 @@
extends:
- eslint:recommended
- plugin:react/recommended
- plugin:@typescript-eslint/recommended
parser: '@typescript-eslint/parser'
plugins:
- react
- react-hooks
parser: babel-eslint
- '@typescript-eslint'
parserOptions:
sourceType: module
ecmaVersion: 2020
@ -25,4 +27,10 @@ rules:
react/prop-types: 0
react-hooks/rules-of-hooks: "error"
# TODO: 修改添加deps后出现的死循环
react-hooks/exhaustive-deps: 0
react-hooks/exhaustive-deps: 0
'@typescript-eslint/explicit-function-return-type': 0
overrides:
- files: ['*.js', '*.jsx']
rules:
'@typescript-eslint/camelcase': 0

View File

@ -9,9 +9,12 @@
"@material-ui/lab": "^4.0.0-alpha.42",
"@svgr/webpack": "4.3.2",
"@types/invariant": "^2.2.32",
"@types/react-dom": "^16.9.7",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/parser": "^2.2.0",
"@types/jest": "^25.2.2",
"@types/node": "^14.0.1",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"axios": "^0.19.0",
"babel-eslint": "10.0.3",
"babel-jest": "^24.9.0",
@ -87,7 +90,7 @@
"terser-webpack-plugin": "1.4.1",
"timeago-react": "^3.0.0",
"ts-pnp": "1.1.4",
"typescript": "^3.8.3",
"typescript": "^3.9.2",
"url-loader": "2.1.0",
"webpack": "4.41.0",
"webpack-dev-server": "3.2.1",
@ -98,7 +101,7 @@
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js",
"eslint": "eslint src/** --fix",
"eslint": "eslint src --fix",
"postinstall": "node node_modules/husky/lib/installer/bin install"
},
"browserslist": {
@ -174,5 +177,8 @@
"hooks": {
"pre-commit": "yarn run eslint"
}
},
"resolutions": {
"@types/react": "^16.9.35"
}
}

View File

@ -59,7 +59,7 @@ export default function Admin() {
const [show, setShow] = useState(false);
useEffect(() => {
let user = Auth.GetUser();
const user = Auth.GetUser();
if (user && user.group) {
if (user.group.id !== 1) {
history.push("/home");

View File

@ -40,11 +40,11 @@ export default function App() {
const theme = React.useMemo(() => {
themeConfig.palette.type = prefersDarkMode ? "dark" : "light";
let prefer = Auth.GetPreference("theme_mode");
const prefer = Auth.GetPreference("theme_mode");
if (prefer) {
themeConfig.palette.type = prefer;
}
let theme = createMuiTheme({
const theme = createMuiTheme({
...themeConfig,
palette: {
...themeConfig.palette,
@ -79,7 +79,7 @@ export default function App() {
const classes = useStyles();
let { path } = useRouteMatch();
const { path } = useRouteMatch();
return (
<React.Fragment>
<ThemeProvider theme={theme}>

View File

@ -1,14 +1,18 @@
export * from './explorer'
export const setNavigator = (path, navigatorLoading) => {
return {
type: 'SET_NAVIGATOR',
path,
navigatorLoading
}
}
export const navigateTo = path => {
return (dispatch, getState) => {
const state = getState()
const navigatorLoading = path !== state.navigator.path
return dispatch({
type: "NAVIGATOR_TO",
path: path,
navigatorLoading,
})
dispatch(setNavigator(path, navigatorLoading))
}
};
@ -19,11 +23,7 @@ export const navigateUp = () => {
pathSplit.pop();
const newPath = pathSplit.length===1? "/":pathSplit.join("/");
const navigatorLoading = newPath !== state.navigator.path
return dispatch({
type: "NAVIGATOR_UP",
path: newPath,
navigatorLoading
})
dispatch(setNavigator(newPath, navigatorLoading))
}
};
@ -55,20 +55,6 @@ export const toggleDaylightMode = ()=>{
};
};
export const changeSortMethod = method => {
return {
type: "CHANGE_SORT_METHOD",
method: method
};
};
export const updateFileList = list => {
return {
type: "UPDATE_FILE_LIST",
list: list
};
};
export const changeContextMenu = (type, open) => {
return {
type: "CHANGE_CONTEXT_MENU",

View File

@ -34,10 +34,10 @@ export default function SizeInput({onChange,min,value,required,label,max,suffix}
const [unit,setUnit] = useState(1);
let first = useRef(true);
const first = useRef(true);
const transform = useCallback(()=>{
let res = unitTransform(value);
const res = unitTransform(value);
if(first && value !== 0){
setUnit(res[1]);
first.current = false;

View File

@ -278,7 +278,7 @@ export default function Dashboard({ content }) {
};
}, []);
let { path } = useRouteMatch();
const { path } = useRouteMatch();
return (
<div className={classes.root}>

View File

@ -41,6 +41,7 @@ export default function AddGroup({ open, onClose, onSubmit }) {
.then(response => {
setGroups(response.data);
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.catch(() => {});
}
// eslint-disable-next-line
@ -62,7 +63,7 @@ export default function AddGroup({ open, onClose, onSubmit }) {
const submit = e => {
e.preventDefault();
let groupCopy = {...group};
const groupCopy = {...group};
groupCopy.time = parseInt(groupCopy.time) * 86400;
groupCopy.price = parseInt(groupCopy.price) * 100;
groupCopy.score = parseInt(groupCopy.score);

View File

@ -38,7 +38,7 @@ export default function AddPack({ open, onClose,onSubmit }) {
const submit = e => {
e.preventDefault();
let packCopy = {...pack};
const packCopy = {...pack};
packCopy.size = parseInt(packCopy.size);
packCopy.time = parseInt(packCopy.time) * 86400;
packCopy.price = parseInt(packCopy.price) * 100;

View File

@ -48,7 +48,7 @@ export default function FileFilter({setFilter,setSearch,open, onClose }) {
},[])
const submit = () => {
let res = {};
const res = {};
Object.keys(input).forEach(v=>{
if(input[v] !== "all" && input[v] !== ""){
res[v] = input[v];

View File

@ -22,7 +22,7 @@ export default function ShareFilter({setFilter,setSearch,open, onClose }) {
}
const submit = () => {
let res = {};
const res = {};
Object.keys(input).forEach(v=>{
if(input[v] !== "all" && input[v] !== ""){
res[v] = input[v];

View File

@ -43,7 +43,7 @@ export default function UserFilter({setFilter,setSearch,open, onClose }) {
},[])
const submit = () => {
let res = {};
const res = {};
Object.keys(input).forEach(v=>{
if(input[v] !== "all"){
res[v] = input[v];

View File

@ -85,7 +85,7 @@ export default function File() {
const [selected, setSelected] = useState([]);
const [loading,setLoading] = useState(false);
let history = useHistory();
const history = useHistory();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>

View File

@ -94,7 +94,7 @@ export default function Import() {
});
};
let history = useHistory();
const history = useHistory();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
@ -162,7 +162,7 @@ export default function Import() {
conditions: {}
})
.then(response => {
let res = {};
const res = {};
response.data.items.forEach(v => {
res[v.ID] = v;
});
@ -183,7 +183,7 @@ export default function Import() {
};
const setMoveTarget = setter => folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;

View File

@ -8,7 +8,7 @@ import GroupForm from "./GroupForm";
export default function EditGroupPreload( ) {
const [group,setGroup] = useState({});
let {id } = useParams();
const {id } = useParams();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(

View File

@ -79,9 +79,9 @@ export default function Group() {
const [total, setTotal] = useState(0);
const [policies, setPolicies] = React.useState({});
let location = useLocation();
let history = useHistory();
let query = useQuery();
const location = useLocation();
const history = useHistory();
const query = useQuery();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(

View File

@ -70,7 +70,7 @@ export default function GroupForm(props) {
);
const [policies, setPolicies] = useState({});
let history = useHistory();
const history = useHistory();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
@ -87,7 +87,7 @@ export default function GroupForm(props) {
conditions: {}
})
.then(response => {
let res = {};
const res = {};
response.data.items.forEach(v => {
res[v.ID] = v.Name;
});
@ -106,7 +106,7 @@ export default function GroupForm(props) {
};
const handleCheckChange = name => event => {
let value = event.target.checked ? "true" : "false";
const value = event.target.checked ? "true" : "false";
setGroup({
...group,
[name]: value
@ -114,7 +114,7 @@ export default function GroupForm(props) {
};
const handleOptionCheckChange = name => event => {
let value = event.target.checked ? "true" : "false";
const value = event.target.checked ? "true" : "false";
setGroup({
...group,
OptionsSerialized: {
@ -136,7 +136,7 @@ export default function GroupForm(props) {
const submit = e => {
e.preventDefault();
let groupCopy = {
const groupCopy = {
...group,
OptionsSerialized: { ...group.OptionsSerialized }
};

View File

@ -118,7 +118,7 @@ export default function Index() {
useEffect(() => {
API.get("/admin/summary")
.then(response => {
let data = [];
const data = [];
response.data.date.forEach((v, k) => {
data.push({
name: v,
@ -148,7 +148,7 @@ export default function Index() {
.get("/api/v3/admin/news")
.then(response => {
setNews(response.data.data);
let res = {};
const res = {};
response.data.included.forEach(v => {
if (v.type === "users") {
res[v.id] = v.attributes;

View File

@ -26,7 +26,7 @@ const useStyles = makeStyles(theme => ({
export default function AddPolicyParent( ) {
const classes = useStyles();
let { type } = useParams();
const { type } = useParams();
return (
<div>

View File

@ -32,7 +32,7 @@ export default function EditPolicyPreload( ) {
const [type,setType] = useState("");
const [policy,setPolicy] = useState({});
let { mode,id } = useParams();
const { mode,id } = useParams();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(

View File

@ -171,7 +171,7 @@ export default function COSGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
if (useCDN === "false"){

View File

@ -93,7 +93,7 @@ export default function EditPro(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
// 类型转换

View File

@ -163,7 +163,7 @@ export default function LocalGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
// 处理存储策略

View File

@ -164,7 +164,7 @@ export default function OSSGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
if (useCDN === "false"){

View File

@ -198,7 +198,7 @@ export default function OneDriveGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
// baseURL处理

View File

@ -148,7 +148,7 @@ export default function RemoteGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
// 类型转换

View File

@ -188,7 +188,7 @@ export default function RemoteGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = {...policy};
const policyCopy = {...policy};
policyCopy.OptionsSerialized = {...policyCopy.OptionsSerialized};
// 处理存储策略

View File

@ -146,7 +146,7 @@ export default function UpyunGuide(props) {
e.preventDefault();
setLoading(true);
let policyCopy = { ...policy };
const policyCopy = { ...policy };
policyCopy.OptionsSerialized = { ...policyCopy.OptionsSerialized };
// 类型转换

View File

@ -89,9 +89,9 @@ export default function Policy() {
const [anchorEl, setAnchorEl] = React.useState(null);
const [editID, setEditID] = React.useState(0);
let location = useLocation();
let history = useHistory();
let query = useQuery();
const location = useLocation();
const history = useHistory();
const query = useQuery();
const handleClick = event => {
setAnchorEl(event.currentTarget);

View File

@ -66,7 +66,7 @@ export default function Access() {
};
const handleInputChange = name => event => {
let value = event.target.value;
const value = event.target.value;
setOptions({
...options,
[name]: value
@ -106,7 +106,7 @@ export default function Access() {
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k => {
option.push({
key: k,

View File

@ -72,10 +72,12 @@ export default function Aria2() {
const reload = () => {
API.get("/admin/reload/aria2")
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then(() => {})
.catch(error => {
ToggleSnackbar("top", "right", error.message, "error");
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then(() => {});
};
@ -98,7 +100,7 @@ export default function Aria2() {
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k=>{
option.push({
key:k,

View File

@ -81,7 +81,7 @@ export default function ImageSetting() {
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k=>{
option.push({
key:k,

View File

@ -115,17 +115,19 @@ export default function Mail() {
const reload = () => {
API.get("/admin/reload/email")
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then(() => {})
.catch(error => {
ToggleSnackbar("top", "right", error.message, "error");
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then(() => {});
};
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k => {
option.push({
key: k,

View File

@ -78,7 +78,7 @@ export default function SiteInformation() {
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k=>{
option.push({
key:k,

View File

@ -64,6 +64,13 @@ export default function Theme() {
const [themeConfigError, setThemeConfigError] = useState({});
const [create, setCreate] = useState(false);
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
dispatch(toggleSnackbar(vertical, horizontal, msg, color)),
[dispatch]
);
const deleteTheme = color => {
if(color === options.defaultTheme){
ToggleSnackbar("top", "right", "不能删除默认配色", "warning");
@ -73,9 +80,9 @@ export default function Theme() {
ToggleSnackbar("top", "right", "请至少保留一个配色方案", "warning");
return
}
let themeCopy = {...theme};
const themeCopy = {...theme};
delete themeCopy[color];
let resStr = JSON.stringify(themeCopy);
const resStr = JSON.stringify(themeCopy);
setOptions({
...options,
themes:resStr,
@ -88,11 +95,11 @@ export default function Theme() {
ToggleSnackbar("top", "right", "主色调不能与已有配色重复", "warning");
return
}
let res = {
const res = {
...theme,
[newTheme.palette.primary.main]:newTheme,
};
let resStr = JSON.stringify(res);
const resStr = JSON.stringify(res);
setOptions({
...options,
themes:resStr,
@ -100,8 +107,8 @@ export default function Theme() {
}
useEffect(() => {
let res = JSON.parse(options.themes);
let themeString = {};
const res = JSON.parse(options.themes);
const themeString = {};
Object.keys(res).forEach(k => {
themeString[k] = JSON.stringify(res[k]);
@ -118,13 +125,6 @@ export default function Theme() {
});
};
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
dispatch(toggleSnackbar(vertical, horizontal, msg, color)),
[dispatch]
);
useEffect(() => {
API.post("/admin/setting", {
keys: Object.keys(options)
@ -141,7 +141,7 @@ export default function Theme() {
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k => {
option.push({
key: k,
@ -233,7 +233,7 @@ export default function Theme() {
}}
onBlur={e => {
try {
let res = JSON.parse(
const res = JSON.parse(
e.target.value
);
if(

View File

@ -56,7 +56,7 @@ export default function UploadDownload() {
});
const handleCheckChange = name => event => {
let value= event.target.checked ? "1" : "0";
const value= event.target.checked ? "1" : "0";
setOptions({
...options,
[name]: value
@ -94,7 +94,7 @@ export default function UploadDownload() {
const submit = e => {
e.preventDefault();
setLoading(true);
let option = [];
const option = [];
Object.keys(options).forEach(k=>{
option.push({
key:k,

View File

@ -176,7 +176,7 @@ export default function Task() {
return "-"
}
try {
let res = JSON.parse(error)
const res = JSON.parse(error)
return res.msg
}catch (e) {
return "未知"

View File

@ -8,7 +8,7 @@ import UserForm from "./UserForm";
export default function EditUserPreload( ) {
const [user,setUser] = useState({});
let {id } = useParams();
const {id } = useParams();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(

View File

@ -83,8 +83,8 @@ export default function Group() {
const [selected, setSelected] = useState([]);
const [loading,setLoading] = useState(false);
let history = useHistory();
let theme = useTheme();
const history = useHistory();
const theme = useTheme();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
@ -149,7 +149,7 @@ export default function Group() {
.then(response => {
setUsers(users.map(v=>{
if (v.ID === id){
let newUser = {...v,Status:response.data}
const newUser = {...v,Status:response.data}
return newUser;
}
return v

View File

@ -48,7 +48,7 @@ export default function UserForm(props) {
);
const [groups, setGroups] = useState([]);
let history = useHistory();
const history = useHistory();
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
@ -76,7 +76,7 @@ export default function UserForm(props) {
const submit = e => {
e.preventDefault();
let userCopy = {...user};
const userCopy = {...user};
// 整型转换
["Status", "GroupID","Score"].forEach(v => {

View File

@ -10,29 +10,28 @@ function AutoHidden ({ children, enable }){
const show = 50;
useEffect(() => {
const handleNavigation = (e) => {
const window = e.currentTarget;
if (prev > window.scrollY) {
if (lastUpdate - window.scrollY > show){
lastUpdate = window.scrollY;
setHidden(false);
}
} else if (prev < window.scrollY) {
if (window.scrollY - lastUpdate > show){
lastUpdate = window.scrollY;
setHidden(true);
}
}
prev = window.scrollY;
};
if (enable){
window.addEventListener('scroll', e => handleNavigation(e));
}
// eslint-disable-next-line
}, [enable])
const handleNavigation = (e) => {
const window = e.currentTarget;
if (prev > window.scrollY) {
if (lastUpdate - window.scrollY > show){
lastUpdate = window.scrollY;
setHidden(false);
}
} else if (prev < window.scrollY) {
if (window.scrollY - lastUpdate > show){
lastUpdate = window.scrollY;
setHidden(true);
}
}
prev = window.scrollY;
};
return (
<Zoom in={!hidden}>
{children}

View File

@ -63,6 +63,21 @@ export default function UploadButton(props) {
setQueued(props.Queued);
}, [props.Queued]);
const openUpload = id =>{
const uploadButton = document.getElementsByClassName(
id
)[0];
if (document.body.contains(uploadButton)) {
uploadButton.click();
} else {
ToggleSnackbar(
"top",
"right",
"上传组件还未加载完成",
"warning"
);
}
};
const uploadClicked = () => {
if (open) {
if (queued !== 0) {
@ -73,22 +88,6 @@ export default function UploadButton(props) {
}
};
const openUpload = id =>{
let uploadButton = document.getElementsByClassName(
id
)[0];
if (document.body.contains(uploadButton)) {
uploadButton.click();
} else {
ToggleSnackbar(
"top",
"right",
"上传组件还未加载完成",
"warning"
);
}
};
const handleOpen = () => {
setOpen(true);
};

View File

@ -145,7 +145,7 @@ const useStyles = makeStyles(theme => ({
}));
export default function DownloadingCard(props) {
let canvasRef = React.createRef();
const canvasRef = React.createRef();
const classes = useStyles();
const theme = useTheme();
@ -202,11 +202,16 @@ export default function DownloadingCard(props) {
return (completed / total) * 100;
};
const activeFiles = useCallback(() => {
return task.info.files.filter(v => v.selected === "true");
}, [task.info.files]);
const deleteFile = index => {
setLoading(true);
let current = activeFiles();
let newIndex = [];
let newFiles = [];
const current = activeFiles();
const newIndex = [];
const newFiles = [];
// eslint-disable-next-line
current.map(v => {
if (v.index !== index && v.selected) {
@ -250,10 +255,6 @@ export default function DownloadingCard(props) {
return task.name === "." ? "[未知]" : task.name;
}, [task]);
const activeFiles = useCallback(() => {
return task.info.files.filter(v => v.selected === "true");
}, [task.info.files]);
const getIcon = useCallback(() => {
if (task.info.bittorrent.mode === "multi") {
return (

View File

@ -187,7 +187,7 @@ export default function FinishedCard(props) {
const getTaskError = error =>{
try{
let res = JSON.parse(error)
const res = JSON.parse(error)
return res.msg + "" + res.error
}catch (e) {
return "文件转存失败"

View File

@ -162,7 +162,7 @@ class ContextMenuCompoment extends Component {
clickUpload = id => {
this.props.changeContextMenu("empty", false);
let uploadButton = document.getElementsByClassName(id)[0];
const uploadButton = document.getElementsByClassName(id)[0];
if (document.body.contains(uploadButton)) {
uploadButton.click();
} else {
@ -176,9 +176,9 @@ class ContextMenuCompoment extends Component {
};
openPreview = () => {
let isShare = pathHelper.isSharePage(this.props.location.pathname);
const isShare = pathHelper.isSharePage(this.props.location.pathname);
if (isShare) {
let user = Auth.GetUser();
const user = Auth.GetUser();
if (!Auth.Check() && user && !user.group.shareDownload) {
this.props.toggleSnackbar(
"top",
@ -191,7 +191,7 @@ class ContextMenuCompoment extends Component {
}
}
this.props.changeContextMenu("file", false);
let previewPath =
const previewPath =
this.props.selected[0].path === "/"
? this.props.selected[0].path + this.props.selected[0].name
: this.props.selected[0].path +

View File

@ -8,7 +8,8 @@ import React, { Component } from "react";
import { configure, GlobalHotKeys } from "react-hotkeys";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import { changeContextMenu, changeSortMethod, navigateTo, navigateUp, openRemoveDialog, setSelectedTarget } from "../../actions/index";
import { changeContextMenu, navigateTo, navigateUp, openRemoveDialog, setSelectedTarget } from "../../actions/index";
import explorer from "../../redux/explorer"
import { isMac } from "../../utils";
import pathHelper from "../../utils/page";
import ContextMenu from "./ContextMenu";
@ -150,7 +151,7 @@ const mapDispatchToProps = dispatch => {
dispatch(openRemoveDialog());
},
changeSort: method => {
dispatch(changeSortMethod(method));
dispatch(explorer.actions.changeSortMethod(method));
}
};
};
@ -207,7 +208,7 @@ class ExplorerCompoment extends Component {
}
ClickAway = e => {
let element = e.target;
const element = e.target;
if (element.dataset.clickaway) {
this.props.setSelectedTarget([]);
}

View File

@ -11,6 +11,7 @@ import Explorer from "./Explorer"
import Modals from "./Modals"
import Navigator from "./Navigator/Navigator"
// eslint-disable-next-line @typescript-eslint/no-empty-function
const mapStateToProps = ()=>{
}

View File

@ -35,11 +35,11 @@ class ImagPreviewComponent extends Component {
};
UNSAFE_componentWillReceiveProps = nextProps => {
let items = [];
const items = [];
let firstOne = 0;
if (nextProps.first !== null) {
if (pathHelper.isSharePage(this.props.location.pathname) && !nextProps.first.path){
let newImg = {
const newImg = {
intro: nextProps.first.name,
src:
baseURL +
@ -56,7 +56,7 @@ class ImagPreviewComponent extends Component {
}
// eslint-disable-next-line
nextProps.other.map(value => {
let fileType = value.name
const fileType = value.name
.split(".")
.pop()
.toLowerCase();
@ -74,7 +74,7 @@ class ImagPreviewComponent extends Component {
"/file/preview/" +
value.id
}
let newImg = {
const newImg = {
intro: value.name,
src:src,
};

View File

@ -35,11 +35,11 @@ class ImgPreviewCompoment extends Component {
};
UNSAFE_componentWillReceiveProps = nextProps => {
let items = [];
const items = [];
let firstOne = 0;
if (nextProps.first !== null) {
if (pathHelper.isSharePage(this.props.location.pathname) && !nextProps.first.path){
let newImg = {
const newImg = {
title: nextProps.first.name,
src:
baseURL +
@ -56,7 +56,7 @@ class ImgPreviewCompoment extends Component {
}
// eslint-disable-next-line
nextProps.other.map(value => {
let fileType = value.name
const fileType = value.name
.split(".")
.pop()
.toLowerCase();
@ -74,7 +74,7 @@ class ImgPreviewCompoment extends Component {
"/file/preview/" +
value.id
}
let newImg = {
const newImg = {
title: value.name,
src:src,
};

View File

@ -137,7 +137,7 @@ class ModalsCompoment extends Component {
return;
}
if (this.props.modalsStatus.rename !== nextProps.modalsStatus.rename) {
let name = nextProps.selected[0].name;
const name = nextProps.selected[0].name;
this.setState({
newName: name
});
@ -172,7 +172,7 @@ class ModalsCompoment extends Component {
Download = () => {
let reqURL = "";
if (this.props.selected[0].key) {
let downloadPath =
const downloadPath =
this.props.selected[0].path === "/"
? this.props.selected[0].path + this.props.selected[0].name
: this.props.selected[0].path +
@ -205,7 +205,7 @@ class ModalsCompoment extends Component {
};
archiveDownload = () => {
let dirs = [],
const dirs = [],
items = [];
this.props.selected.map(value => {
if (value.type === "dir") {
@ -217,7 +217,7 @@ class ModalsCompoment extends Component {
});
let reqURL = "/file/archive";
let postBody = {
const postBody = {
items: items,
dirs: dirs
};
@ -260,7 +260,7 @@ class ModalsCompoment extends Component {
submitRemove = e => {
e.preventDefault();
this.props.setModalsLoading(true);
let dirs = [],
const dirs = [],
items = [];
// eslint-disable-next-line
this.props.selected.map(value => {
@ -307,7 +307,7 @@ class ModalsCompoment extends Component {
e.preventDefault();
}
this.props.setModalsLoading(true);
let dirs = [],
const dirs = [],
items = [];
// eslint-disable-next-line
this.props.selected.map(value => {
@ -386,9 +386,9 @@ class ModalsCompoment extends Component {
submitRename = e => {
e.preventDefault();
this.props.setModalsLoading(true);
let newName = this.state.newName;
const newName = this.state.newName;
let src = {
const src = {
dirs: [],
items: []
};
@ -578,7 +578,7 @@ class ModalsCompoment extends Component {
};
setMoveTarget = folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;

View File

@ -6,7 +6,7 @@ export default function DropDown(props) {
let timer;
let first = props.folders.length;
let status = [];
const status = [];
for (let index = 0; index < props.folders.length; index++) {
status[index] = false;

View File

@ -14,9 +14,7 @@ import {
navigateTo,
navigateUp,
changeViewMethod,
changeSortMethod,
setNavigatorError,
updateFileList,
setNavigatorLoadingStatus,
refreshFileList,
setSelectedTarget,
@ -25,6 +23,7 @@ import {
drawerToggleAction,
setShareUserPopover, openResaveDialog, openCompressDialog
} from "../../../actions/index";
import explorer from "../../../redux/explorer"
import API from "../../../middleware/Api";
import { setCookie, setGetParameter, fixUrlHash } from "../../../utils/index";
import {
@ -69,13 +68,13 @@ const mapDispatchToProps = dispatch => {
dispatch(changeViewMethod(method));
},
changeSort: method => {
dispatch(changeSortMethod(method));
dispatch(explorer.actions.changeSortMethod(method));
},
setNavigatorError: (status, msg) => {
dispatch(setNavigatorError(status, msg));
},
updateFileList: list => {
dispatch(updateFileList(list));
dispatch(explorer.actions.updateFileList(list));
},
setNavigatorLoadingStatus: status => {
dispatch(setNavigatorLoadingStatus(status));
@ -181,8 +180,8 @@ class NavigatorComponent extends Component {
}
componentDidMount = () => {
var url = new URL(fixUrlHash(window.location.href));
var c = url.searchParams.get("path");
const url = new URL(fixUrlHash(window.location.href));
const c = url.searchParams.get("path");
this.renderPath(c === null ? "/":c);
if (!this.props.isShare) {
@ -192,8 +191,8 @@ class NavigatorComponent extends Component {
// 后退操作时重新导航
window.onpopstate = () => {
var url = new URL(fixUrlHash(window.location.href));
var c = url.searchParams.get("path");
const url = new URL(fixUrlHash(window.location.href));
const c = url.searchParams.get("path");
if (c !== null && c !== this.props.path) {
this.props.navigateToPath(c);
}
@ -208,8 +207,8 @@ class NavigatorComponent extends Component {
? path.substr(1).split("/")
: this.props.path.substr(1).split("/")
});
var newPath = path !== null ? path : this.props.path;
var apiURL = this.props.share
let newPath = path !== null ? path : this.props.path;
const apiURL = this.props.share
? "/share/list/" + this.props.share.key
: this.keywords === null
? "/directory"
@ -221,7 +220,7 @@ class NavigatorComponent extends Component {
this.currentID = response.data.parent;
this.props.updateFileList(response.data.objects);
this.props.setNavigatorLoadingStatus(false);
let pathTemp = (path !== null
const pathTemp = (path !== null
? path.substr(1).split("/")
: this.props.path.substr(1).split("/")
).join(",");
@ -328,8 +327,8 @@ class NavigatorComponent extends Component {
this.redresh();
return;
}
let presentPath = this.props.path.split("/");
let newTarget = [
const presentPath = this.props.path.split("/");
const newTarget = [
{
id:this.currentID,
type: "dir",
@ -359,7 +358,7 @@ class NavigatorComponent extends Component {
};
toggleViewMethod = () => {
let newMethod =
const newMethod =
this.props.viewMethod === "icon"
? "list"
: this.props.viewMethod === "list"
@ -371,7 +370,7 @@ class NavigatorComponent extends Component {
handleMenuItemClick = (e, index) => {
this.setState({ selectedIndex: index, anchorEl: null });
let optionsTable = {
const optionsTable = {
0: "namePos",
1: "nameRev",
2: "timePos",
@ -388,7 +387,7 @@ class NavigatorComponent extends Component {
const isHomePage = pathHelper.isHomePage(this.props.location.pathname);
const user = Auth.GetUser();
let presentFolderMenu = (
const presentFolderMenu = (
<Menu
id="presentFolderMenu"
anchorEl={this.state.anchorEl}

View File

@ -44,8 +44,8 @@ export default function ObjectIcon(props) {
state => state.viewUpdate.explorerViewMethod
);
const navigatorPath = useSelector(state => state.navigator.path);
let location = useLocation();
let history = useHistory();
const location = useLocation();
const history = useHistory();
const dispatch = useDispatch();
const ContextMenu = useCallback(
@ -101,7 +101,11 @@ export default function ObjectIcon(props) {
const selectFile = e => {
dispatch(selectFileAction(props.file, e, props.index))
};
const enterFolder = () => {
NavitateTo(
path === "/" ? path + props.file.name : path + "/" + props.file.name
);
};
const handleClick = e => {
if (props.file.type === "up") {
NavitateTo(pathBack(navigatorPath));
@ -128,9 +132,9 @@ export default function ObjectIcon(props) {
enterFolder();
return;
}
let isShare = statusHelper.isSharePage(location.pathname);
const isShare = statusHelper.isSharePage(location.pathname);
if (isShare) {
let user = Auth.GetUser();
const user = Auth.GetUser();
if (!Auth.Check() && user && !user.group.shareDownload) {
ToggleSnackbar("top", "right", "请先登录", "warning");
return;
@ -140,7 +144,7 @@ export default function ObjectIcon(props) {
OpenLoadingDialog("获取下载地址...");
return;
}
let previewPath =
const previewPath =
selected[0].path === "/"
? selected[0].path + selected[0].name
: selected[0].path + "/" + selected[0].name;
@ -232,12 +236,6 @@ export default function ObjectIcon(props) {
}
};
const enterFolder = () => {
NavitateTo(
path === "/" ? path + props.file.name : path + "/" + props.file.name
);
};
const [{ isDragging }, drag, preview] = useDrag({
item: {
object: props.file,

View File

@ -67,21 +67,21 @@ class PathSelectorCompoment extends Component {
}
componentDidMount= ()=>{
let toBeLoad = this.props.presentPath;
const toBeLoad = this.props.presentPath;
this.enterFolder(this.props.keywords === null ? toBeLoad : "/");
}
back = ()=>{
let paths = this.state.presentPath.split("/");
const paths = this.state.presentPath.split("/");
paths.pop();
let toBeLoad = paths.join("/");
const toBeLoad = paths.join("/");
this.enterFolder(toBeLoad===""?"/":toBeLoad);
}
enterFolder = (toBeLoad)=>{
API.get((this.props.api ? this.props.api : '/directory')+encodeURIComponent(toBeLoad),)
.then( (response)=> {
var dirList = response.data.objects.filter( (x)=> {
const dirList = response.data.objects.filter( (x)=> {
return (x.type === "dir" && (this.props.selected.findIndex((value)=>{
return (value.name === x.name )&&(value.path === x.path);
}))===-1);

View File

@ -106,7 +106,7 @@ let color;
const TypeIcon = props => {
const theme = useTheme();
let fileSuffix = props.fileName
const fileSuffix = props.fileName
.split(".")
.pop()
.toLowerCase();
@ -116,7 +116,7 @@ const TypeIcon = props => {
fileType = k;
}
});
let IconComponent = icons[fileType].icon;
const IconComponent = icons[fileType].icon;
color = getColor(theme, icons[fileType].color);
if (props.getColorValue) {
props.getColorValue(color);

View File

@ -50,8 +50,8 @@ function useQuery() {
}
function Activation() {
let query = useQuery();
let location = useLocation();
const query = useQuery();
const location = useLocation();
const [success,setSuccess] = useState(false);
const [email,setEmail] = useState("");

View File

@ -120,9 +120,9 @@ function LoginForm() {
[dispatch]
);
let history = useHistory();
let location = useLocation();
let query = useQuery();
const history = useHistory();
const location = useLocation();
const query = useQuery();
const classes = useStyles();
@ -148,6 +148,24 @@ function LoginForm() {
}
}, [location,loginCaptcha]);
const afterLogin = data =>{
Auth.authenticate(data);
// 设置用户主题色
if (data["preferred_theme"] !== "") {
ApplyThemes(data["preferred_theme"]);
}
enableUploaderLoad();
// 设置登录状态
SetSessionStatus(true);
history.push("/home");
ToggleSnackbar("top", "right", "登录成功", "success");
localStorage.removeItem("siteConfigCache");
}
const authnLogin = e => {
e.preventDefault();
if (!navigator.credentials) {
@ -160,7 +178,7 @@ function LoginForm() {
API.get("/user/authn/" + email)
.then(response => {
let credentialRequestOptions = response.data;
const credentialRequestOptions = response.data;
console.log(credentialRequestOptions);
credentialRequestOptions.publicKey.challenge = bufferDecode(
credentialRequestOptions.publicKey.challenge
@ -176,11 +194,11 @@ function LoginForm() {
});
})
.then(assertion => {
let authData = assertion.response.authenticatorData;
let clientDataJSON = assertion.response.clientDataJSON;
let rawId = assertion.rawId;
let sig = assertion.response.signature;
let userHandle = assertion.response.userHandle;
const authData = assertion.response.authenticatorData;
const clientDataJSON = assertion.response.clientDataJSON;
const rawId = assertion.rawId;
const sig = assertion.response.signature;
const userHandle = assertion.response.userHandle;
return API.post(
"/user/authn/finish/" + email,
@ -209,24 +227,6 @@ function LoginForm() {
});
};
const afterLogin = data =>{
Auth.authenticate(data);
// 设置用户主题色
if (data["preferred_theme"] !== "") {
ApplyThemes(data["preferred_theme"]);
}
enableUploaderLoad();
// 设置登录状态
SetSessionStatus(true);
history.push("/home");
ToggleSnackbar("top", "right", "登录成功", "success");
localStorage.removeItem("siteConfigCache");
}
const login = e => {
e.preventDefault();
setLoading(true);

View File

@ -118,6 +118,7 @@ export default class ReCAPTCHA extends React.Component {
render() {
// consume properties owned by the reCATPCHA, pass the rest to the div so the user can style it.
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
const {
sitekey,
onChange,
@ -154,6 +155,7 @@ ReCAPTCHA.propTypes = {
badge: PropTypes.oneOf(["bottomright", "bottomleft", "inline"]),
};
ReCAPTCHA.defaultProps = {
// eslint-disable-next-line @typescript-eslint/no-empty-function
onChange: () => {},
theme: "light",
type: "image",

View File

@ -59,7 +59,7 @@ function useQuery() {
}
function ResetForm() {
let query = useQuery();
const query = useQuery();
const [input, setInput] = useState({
password: "",
password_repeat: ""

View File

@ -110,7 +110,7 @@ export default function AddTag(props) {
// eslint-disable-next-line
const [selectedPathName, setSelectedPathName] = useState("");
const setMoveTarget = folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;
@ -148,14 +148,6 @@ export default function AddTag(props) {
[dispatch]
);
const submit = () => {
if (value === 0) {
submitNewTag();
}else{
submitNewLink();
}
};
const submitNewLink = ()=>{
setLoading(true);
@ -210,7 +202,13 @@ export default function AddTag(props) {
setLoading(false);
});
};
const submit = () => {
if (value === 0) {
submitNewTag();
}else{
submitNewLink();
}
};
const selectPath = ()=>{
setInput({
...input,

View File

@ -59,7 +59,7 @@ export default function CompressDialog(props) {
);
const setMoveTarget = folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;
@ -73,7 +73,7 @@ export default function CompressDialog(props) {
}
SetModalsLoading(true);
let dirs = [],
const dirs = [],
items = [];
// eslint-disable-next-line
props.selected.map(value => {

View File

@ -57,7 +57,7 @@ export default function CopyDialog(props) {
}, [dispatch]);
const setMoveTarget = folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;
@ -70,7 +70,7 @@ export default function CopyDialog(props) {
e.preventDefault();
}
SetModalsLoading(true);
let dirs = [],
const dirs = [],
items = [];
// eslint-disable-next-line

View File

@ -189,7 +189,7 @@ export default function CreatShare(props) {
const submitShare = e => {
e.preventDefault();
props.setModalsLoading(true);
let submitFormBody = {
const submitFormBody = {
id: props.selected[0].id,
is_dir: props.selected[0].type === "dir",
password: values.password,

View File

@ -43,7 +43,7 @@ export default function CreateWebDAVAccount(props) {
const classes = useStyles();
const setMoveTarget = folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;

View File

@ -54,7 +54,7 @@ export default function DecompressDialog(props) {
);
const setMoveTarget = folder => {
let path =
const path =
folder.path === "/"
? folder.path + folder.name
: folder.path + "/" + folder.name;

View File

@ -43,7 +43,7 @@ export default function SelectFileDialog(props) {
const handleChange = index => event =>{
let filesCopy = [...files];
const filesCopy = [...files];
// eslint-disable-next-line
filesCopy.map((v,k)=>{
if (v.index === index){
@ -54,7 +54,7 @@ export default function SelectFileDialog(props) {
};
const submit = () =>{
let index = [];
const index = [];
// eslint-disable-next-line
files.map(v=>{
if(v.selected === "true"){

View File

@ -21,13 +21,12 @@ const DarkModeSwitcher = ({ position }) => {
const ToggleThemeMode = useCallback(() => dispatch(toggleDaylightMode()), [
dispatch
]);
const toggleMode = () => {
Auth.SetPreference("theme_mode",isDayLight?"dark":"light");
ToggleThemeMode();
};
const isDayLight = (ThemeType && ThemeType === "light") || !ThemeType;
const isDark = ThemeType && ThemeType === "dark";
const toggleMode = () => {
Auth.SetPreference("theme_mode",isDayLight?"dark":"light");
ToggleThemeMode();
};
const classes = useStyles();
return (
<Tooltip

View File

@ -137,8 +137,8 @@ const AddTag = React.lazy(() => import ("../Modals/AddTag" ));
export default function FileTag() {
const classes = useStyles();
let location = useLocation();
let history = useHistory();
const location = useLocation();
const history = useHistory();
const isHomePage = pathHelper.isHomePage(location.pathname);
@ -162,7 +162,7 @@ export default function FileTag() {
const getIcon = (icon, color) => {
if (icons[icon]) {
let IconComponent = icons[icon];
const IconComponent = icons[icon];
return (
<IconComponent
className={[classes.iconFix]}
@ -180,9 +180,9 @@ export default function FileTag() {
};
const submitSuccess = tag =>{
let newTags = [...tags,tag];
const newTags = [...tags,tag];
setTags(newTags);
let user = Auth.GetUser();
const user = Auth.GetUser();
user.tags = newTags;
Auth.SetUser(user);
};
@ -190,9 +190,9 @@ export default function FileTag() {
const submitDelete = id =>{
API.delete("/tag/"+id)
.then(() => {
let newTags = tags.filter((v)=>{return v.id !== id});
const newTags = tags.filter((v)=>{return v.id !== id});
setTags(newTags)
let user = Auth.GetUser();
const user = Auth.GetUser();
user.tags = newTags;
Auth.SetUser(user);
})

View File

@ -336,9 +336,9 @@ class NavbarCompoment extends Component {
};
openPreview = () => {
let isShare = pathHelper.isSharePage(this.props.location.pathname);
const isShare = pathHelper.isSharePage(this.props.location.pathname);
if (isShare) {
let user = Auth.GetUser();
const user = Auth.GetUser();
if (!Auth.Check() && user && !user.group.shareDownload) {
this.props.toggleSnackbar(
"top",
@ -351,7 +351,7 @@ class NavbarCompoment extends Component {
}
}
this.props.changeContextMenu("file", false);
let previewPath =
const previewPath =
this.props.selected[0].path === "/"
? this.props.selected[0].path + this.props.selected[0].name
: this.props.selected[0].path +

View File

@ -119,6 +119,7 @@ class StorageBarCompoment extends Component {
total: sizeToString(response.data.total)
});
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.catch(() => {});
};

View File

@ -95,7 +95,7 @@ export default function Authn(props) {
}
API.put("/user/authn", {})
.then(response => {
let credentialCreationOptions = response.data;
const credentialCreationOptions = response.data;
credentialCreationOptions.publicKey.challenge = bufferDecode(
credentialCreationOptions.publicKey.challenge
);
@ -104,7 +104,7 @@ export default function Authn(props) {
);
if (credentialCreationOptions.publicKey.excludeCredentials) {
for (
var i = 0;
let i = 0;
i <
credentialCreationOptions.publicKey.excludeCredentials
.length;
@ -124,9 +124,9 @@ export default function Authn(props) {
});
})
.then(credential => {
let attestationObject = credential.response.attestationObject;
let clientDataJSON = credential.response.clientDataJSON;
let rawId = credential.rawId;
const attestationObject = credential.response.attestationObject;
const clientDataJSON = credential.response.clientDataJSON;
const rawId = credential.rawId;
return API.put(
"/user/authn/finish",
JSON.stringify({

View File

@ -52,22 +52,6 @@ export default function Tasks() {
const [total, setTotal] = useState(0);
const [page, setPage] = useState(1);
useEffect(() => {
loadList(page);
// eslint-disable-next-line
}, [page]);
const loadList = page => {
API.get("/user/setting/tasks?page=" + page)
.then(response => {
setTasks(response.data.tasks);
setTotal(response.data.total);
})
.catch(error => {
ToggleSnackbar("top", "right", error.message, "error");
});
};
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
@ -75,12 +59,28 @@ export default function Tasks() {
[dispatch]
);
const loadList = page => {
API.get("/user/setting/tasks?page=" + page)
.then(response => {
setTasks(response.data.tasks);
setTotal(response.data.total);
})
.catch(error => {
ToggleSnackbar("top", "right", error.message, "error");
});
};
useEffect(() => {
loadList(page);
// eslint-disable-next-line
}, [page]);
const getError = error => {
if (error === ""){
return "-"
}
try {
let res = JSON.parse(error)
const res = JSON.parse(error)
return res.msg
}catch (e) {
return "未知"

View File

@ -233,7 +233,7 @@ class UserSettingCompoment extends Component {
}
toggleViewMethod = () => {
let newMethod =
const newMethod =
this.props.viewMethod === "icon"
? "list"
: this.props.viewMethod === "list"
@ -246,7 +246,7 @@ class UserSettingCompoment extends Component {
loadSetting = () => {
API.get("/user/setting")
.then(response => {
let theme = JSON.parse(response.data.themes);
const theme = JSON.parse(response.data.themes);
response.data.themes = theme;
this.setState({
settings: response.data
@ -327,7 +327,7 @@ class UserSettingCompoment extends Component {
this.setState({
loading: "avatar"
});
var formData = new FormData();
const formData = new FormData();
formData.append("avatar", this.fileInput.current.files[0]);
API.post("/user/setting/avatar", formData, {
headers: {

View File

@ -52,11 +52,13 @@ export default function WebDAV() {
const [create, setCreate] = useState(false);
const [accounts, setAccounts] = useState([]);
useEffect(() => {
loadList();
// eslint-disable-next-line
}, []);
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
dispatch(toggleSnackbar(vertical, horizontal, msg, color)),
[dispatch]
);
const loadList = () =>{
API.get("/webdav/accounts")
.then(response => {
@ -66,16 +68,13 @@ export default function WebDAV() {
ToggleSnackbar("top", "right", error.message, "error");
});
}
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
dispatch(toggleSnackbar(vertical, horizontal, msg, color)),
[dispatch]
);
useEffect(() => {
loadList();
// eslint-disable-next-line
}, []);
const deleteAccount = id => {
let account = accounts[id];
const account = accounts[id];
API.delete("/webdav/accounts/" + account.ID)
.then(() => {
let accountCopy = [...accounts];

View File

@ -55,7 +55,7 @@ const mapDispatchToProps = dispatch => {
class LockedFileCompoment extends Component {
constructor(props) {
super(props);
let query = new URLSearchParams(this.props.location.search);
const query = new URLSearchParams(this.props.location.search);
this.state = {
pwd: query.get("password"),
};

View File

@ -146,12 +146,12 @@ class MyShareCompoment extends Component {
};
changePermission = id => {
let newPwd = Math.random()
const newPwd = Math.random()
.toString(36)
.substr(2)
.slice(2, 8);
let oldList = this.state.shareList;
let shareIndex = oldList.findIndex(value => {
const oldList = this.state.shareList;
const shareIndex = oldList.findIndex(value => {
return value.key === id;
});
API
@ -171,8 +171,8 @@ class MyShareCompoment extends Component {
};
changePreviewOption = id => {
let oldList = this.state.shareList;
let shareIndex = oldList.findIndex(value => {
const oldList = this.state.shareList;
const shareIndex = oldList.findIndex(value => {
return value.key === id;
});
API
@ -192,7 +192,7 @@ class MyShareCompoment extends Component {
};
loadList = (page,orderBy) => {
let order = orderBy.split(" ");
const order = orderBy.split(" ");
API.get("/share?page=" + page + "&order_by=" + order[0] + "&order=" + order[1])
.then(response => {
if (response.data.items.length === 0) {

View File

@ -73,11 +73,11 @@ export default function ReadMe(props) {
[dispatch]
);
let $vm = React.createRef();
const $vm = React.createRef();
useEffect(() => {
setLoading(true);
let previewPath =
const previewPath =
props.file.path === "/"
? props.file.path + props.file.name
: props.file.path + "/" + props.file.name;

View File

@ -81,9 +81,9 @@ export default function SearchResult() {
const classes = useStyles();
const dispatch = useDispatch();
let query = useQuery();
let location = useLocation();
let history = useHistory();
const query = useQuery();
const location = useLocation();
const history = useHistory();
const ToggleSnackbar = useCallback(
(vertical, horizontal, msg, color) =>
@ -97,7 +97,7 @@ export default function SearchResult() {
const [orderBy, setOrderBy] = useState("created_at DESC");
const search = useCallback((keywords, page, orderBy) => {
let order = orderBy.split(" ");
const order = orderBy.split(" ");
API.get(
"/share/search?page=" +
page +
@ -126,7 +126,7 @@ export default function SearchResult() {
}, []);
useEffect(() => {
let keywords = query.get("keywords");
const keywords = query.get("keywords");
if (keywords) {
search(keywords, page, orderBy);
} else {
@ -136,13 +136,13 @@ export default function SearchResult() {
const handlePageChange = (event, value) => {
setPage(value);
let keywords = query.get("keywords");
const keywords = query.get("keywords");
search(keywords, value, orderBy);
};
const handleOrderChange = event => {
setOrderBy(event.target.value);
let keywords = query.get("keywords");
const keywords = query.get("keywords");
search(keywords, page, event.target.value);
};

View File

@ -12,7 +12,7 @@ import SharedFolder from "./SharedFolder";
export default function SharePreload() {
const dispatch = useDispatch();
let { id } = useParams();
const { id } = useParams();
const [share, setShare] = useState(undefined);
const [loading, setLoading] = useState(false);

View File

@ -134,7 +134,7 @@ class SharedFileCompoment extends Component {
preview = () => {
if (pathHelper.isSharePage(this.props.location.pathname)) {
let user = Auth.GetUser();
const user = Auth.GetUser();
if (!Auth.Check() && user && !user.group.shareDownload) {
this.props.toggleSnackbar(
"top",

View File

@ -89,8 +89,8 @@ class FileList extends Component {
}
deQueue(file) {
var filesNow = [...this.state.files];
var fileID = filesNow.findIndex(f => {
const filesNow = [...this.state.files];
const fileID = filesNow.findIndex(f => {
return f.id === file.id;
});
if (fileID !== -1) {
@ -103,8 +103,8 @@ class FileList extends Component {
}
updateStatus(file) {
var filesNow = [...this.state.files];
var fileID = filesNow.findIndex(f => {
const filesNow = [...this.state.files];
const fileID = filesNow.findIndex(f => {
return f.id === file.id;
});
if (!file.errMsg || file.ignoreMsg) {
@ -121,8 +121,8 @@ class FileList extends Component {
setComplete(file) {
console.log("setComplete");
var filesNow = [...this.state.files];
var fileID = filesNow.findIndex(f => {
const filesNow = [...this.state.files];
const fileID = filesNow.findIndex(f => {
return f.id === file.id;
});
if (fileID !== -1) {
@ -136,8 +136,8 @@ class FileList extends Component {
}
setError(file, errMsg) {
var filesNow = [...this.state.files];
var fileID = filesNow.findIndex(f => {
const filesNow = [...this.state.files];
const fileID = filesNow.findIndex(f => {
return f.id === file.id;
});
if (fileID !== -1) {

View File

@ -57,7 +57,7 @@ class UploaderComponent extends Component {
}
fileAdd = (up, files) => {
let path = window.currntPath ? window.currntPath : this.props.path;
const path = window.currntPath ? window.currntPath : this.props.path;
if (
this.props.keywords === null &&
window.location.href
@ -76,7 +76,7 @@ class UploaderComponent extends Component {
return !isDsStore
})
.map(file => {
let source = file.getSource();
const source = file.getSource();
if (source.relativePath && source.relativePath !== "") {
file.path = basename(
pathJoin([path, source.relativePath])
@ -106,7 +106,7 @@ class UploaderComponent extends Component {
return;
}
loaded = true;
var user = Auth.GetUser();
const user = Auth.GetUser();
this.uploader = window.Qiniu.uploader({
runtimes: "html5",
browse_button: ["pickfiles", "pickfolder"],
@ -133,6 +133,7 @@ class UploaderComponent extends Component {
init: {
FilesAdded: this.fileAdd,
// eslint-disable-next-line @typescript-eslint/no-empty-function
BeforeUpload: function() {},
QueueChanged: up => {
this.setState({ queued: up.total.queued });
@ -149,7 +150,7 @@ class UploaderComponent extends Component {
file[0].status,
file[0]
);
for (var i = 0; i < file.length; i++) {
for (let i = 0; i < file.length; i++) {
if (file[i].status === 5) {
window.fileList["setComplete"](file[i]);
}
@ -167,11 +168,13 @@ class UploaderComponent extends Component {
this.props.refreshFileList();
this.props.refreshStorage();
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
FileUploaded: function() {},
Error: (up, err, errTip) => {
window.fileList["openFileList"]();
window.fileList["setError"](err.file, errTip);
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
FilesRemoved: () => {}
}
});
@ -180,6 +183,7 @@ class UploaderComponent extends Component {
}
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
onError() {}
openFileList = () => {

View File

@ -58,9 +58,9 @@ export default function CodeViewer() {
const [suffix, setSuffix] = useState("javascript");
const math = useRouteMatch();
let location = useLocation();
let query = useQuery();
let { id } = useParams();
const location = useLocation();
const query = useQuery();
const { id } = useParams();
const theme = useTheme();
const dispatch = useDispatch();
@ -75,12 +75,12 @@ export default function CodeViewer() {
useEffect(() => {
if (!pathHelper.isSharePage(location.pathname)) {
let path = query.get("p").split("/");
let extension = query.get("p").split(".");
const path = query.get("p").split("/");
const extension = query.get("p").split(".");
setSuffix(codePreviewSuffix[extension.pop()]);
SetSubTitle(path[path.length - 1]);
} else {
let extension = query.get("name").split(".");
const extension = query.get("name").split(".");
setSuffix(codePreviewSuffix[extension.pop()]);
SetSubTitle(query.get("name"));
}
@ -100,8 +100,8 @@ export default function CodeViewer() {
setLoading(true);
API.get(requestURL, { responseType: "arraybuffer" })
.then(response => {
var buffer = new Buffer(response.rawData, "binary");
var textdata = buffer.toString(); // for string
const buffer = new Buffer(response.rawData, "binary");
const textdata = buffer.toString(); // for string
setContent(textdata);
})
.catch(error => {

View File

@ -27,11 +27,11 @@ function useQuery() {
}
export default function DocViewer() {
let [url,setURL] = useState("");
const [url,setURL] = useState("");
const math = useRouteMatch();
let location = useLocation();
let query = useQuery();
let { id } = useParams();
const location = useLocation();
const query = useQuery();
const { id } = useParams();
const dispatch = useDispatch();
@ -48,7 +48,7 @@ export default function DocViewer() {
useEffect(() => {
if (!pathHelper.isSharePage(location.pathname)) {
let path = query.get("p").split("/");
const path = query.get("p").split("/");
SetSubTitle(path[path.length - 1]);
} else {
SetSubTitle(query.get("name"));

View File

@ -41,9 +41,9 @@ function useQuery() {
export default function PDFViewer() {
const math = useRouteMatch();
let location = useLocation();
let query = useQuery();
let { id } = useParams();
const location = useLocation();
const query = useQuery();
const { id } = useParams();
const [pageNumber, setPageNumber] = useState(1);
@ -59,7 +59,7 @@ export default function PDFViewer() {
useEffect(() => {
if (!pathHelper.isSharePage(location.pathname)) {
let path = query.get("p").split("/");
const path = query.get("p").split("/");
SetSubTitle(path[path.length - 1]);
} else {
SetSubTitle(query.get("name"));

View File

@ -47,10 +47,10 @@ export default function TextViewer() {
const [status, setStatus] = useState("");
const [loading, setLoading] = useState(true);
const math = useRouteMatch();
let $vm = React.createRef();
let location = useLocation();
let query = useQuery();
let { id } = useParams();
const $vm = React.createRef();
const location = useLocation();
const query = useQuery();
const { id } = useParams();
const dispatch = useDispatch();
const SetSubTitle = useCallback(title => dispatch(changeSubTitle(title)), [
@ -64,7 +64,7 @@ export default function TextViewer() {
useEffect(() => {
if (!pathHelper.isSharePage(location.pathname)) {
let path = query.get("p").split("/");
const path = query.get("p").split("/");
SetSubTitle(path[path.length - 1]);
} else {
SetSubTitle(query.get("name"));
@ -84,8 +84,8 @@ export default function TextViewer() {
setLoading(true);
API.get(requestURL, { responseType: 'arraybuffer' })
.then(response => {
var buffer = new Buffer(response.rawData, 'binary');
var textdata = buffer.toString(); // for string
const buffer = new Buffer(response.rawData, 'binary');
const textdata = buffer.toString(); // for string
setContent(textdata);
})
.catch(error => {

View File

@ -33,16 +33,16 @@ function useQuery() {
export default function VideoViewer() {
const math = useRouteMatch();
let location = useLocation();
let query = useQuery();
let { id } = useParams();
const location = useLocation();
const query = useQuery();
const { id } = useParams();
const dispatch = useDispatch();
const SetSubTitle = useCallback(title => dispatch(changeSubTitle(title)), [
dispatch
]);
useEffect(() => {
if (!pathHelper.isSharePage(location.pathname)) {
let path = query.get("p").split("/");
const path = query.get("p").split("/");
SetSubTitle(path[path.length - 1]);
} else {
SetSubTitle(query.get("name"));

View File

@ -57,7 +57,7 @@ export const policyTypeMap = {
onedrive:"OneDrive",
};
export const isPreviewable = name=>{
let suffix = name.split(".").pop().toLowerCase();
const suffix = name.split(".").pop().toLowerCase();
if(imgPreviewSuffix.indexOf(suffix)!==-1){
return "img";
}else if(msDocPreviewSuffix.indexOf(suffix)!==-1){
@ -76,7 +76,7 @@ export const isPreviewable = name=>{
return false;
}
export const isTorrent = name=>{
let suffix = name.split(".").pop().toLowerCase();
const suffix = name.split(".").pop().toLowerCase();
if(mediaType.torrent.indexOf(suffix)!==-1){
return true;
}
@ -84,7 +84,7 @@ export const isTorrent = name=>{
}
export const isCompressFile = name=>{
let suffix = name.split(".").pop().toLowerCase();
const suffix = name.split(".").pop().toLowerCase();
return suffix === "zip"
}

View File

@ -7,44 +7,6 @@ const loadedScript = [];
const pendingScripts = {};
let failedScript = [];
export function startLoadingScripts(scripts, onComplete = noop) {
// sequence load
const loadNewScript = script => {
const src = typeof script === "object" ? script.src : script;
if (loadedScript.indexOf(src) < 0) {
return taskComplete => {
const callbacks = pendingScripts[src] || [];
callbacks.push(taskComplete);
pendingScripts[src] = callbacks;
if (callbacks.length === 1) {
return newScript(script)(err => {
pendingScripts[src].forEach(cb => cb(err, src));
delete pendingScripts[src];
});
}
};
}
};
const tasks = scripts.map(src => {
if (Array.isArray(src)) {
return src.map(loadNewScript);
} else return loadNewScript(src);
});
series(...tasks)((err, src) => {
if (err) {
failedScript.push(src);
} else {
if (Array.isArray(src)) {
src.forEach(addCache);
} else addCache(src);
}
})(err => {
removeFailedScript();
onComplete(err);
});
}
const addCache = entry => {
if (loadedScript.indexOf(entry) < 0) {
loadedScript.push(entry);
@ -64,6 +26,44 @@ const removeFailedScript = () => {
}
};
export function startLoadingScripts(scripts, onComplete = noop) {
// sequence load
const loadNewScript = script => {
const src = typeof script === "object" ? script.src : script;
if (loadedScript.indexOf(src) < 0) {
return taskComplete => {
const callbacks = pendingScripts[src] || [];
callbacks.push(taskComplete);
pendingScripts[src] = callbacks;
if (callbacks.length === 1) {
return newScript(script)(err => {
pendingScripts[src].forEach(cb => cb(err, src));
delete pendingScripts[src];
});
}
};
}
};
const tasks = scripts.map(src => {
if (Array.isArray(src)) {
return src.map(loadNewScript);
} else return loadNewScript(src);
});
series(...tasks)((err, src) => {
if (err) {
failedScript.push(src);
} else {
if (Array.isArray(src)) {
src.forEach(addCache);
} else addCache(src);
}
})(err => {
removeFailedScript();
onComplete(err);
});
}
const uploaderLoader = () => WrappedComponent => {
class ScriptLoader extends Component {
static propTypes = {
@ -87,7 +87,7 @@ const uploaderLoader = () => WrappedComponent => {
componentDidMount() {
this._isMounted = true;
let scripts = [
const scripts = [
["/static/js/uploader/moxie.js"],
["/static/js/uploader/plupload.dev.js"],
["/static/js/uploader/i18n/zh_CN.js"],

View File

@ -1,12 +1,13 @@
export const isDefined = val => val != null
export const isFunction = val => typeof val === 'function'
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const noop = () => { }
export const newScript = (src) => (cb) => {
const scriptElem = document.createElement('script')
if (typeof src === 'object') {
// copy every property to the element
for (var key in src) {
for (const key in src) {
if (Object.prototype.hasOwnProperty.call(src, key)) {
scriptElem[key] = src[key];
}
@ -72,6 +73,7 @@ export const series = (...tasks) => (each) => (cb) => {
const nextThunk = () => {
const key = nextKey.next()
let thunk = tasks[key]
// eslint-disable-next-line prefer-spread
if (Array.isArray(thunk)) thunk = parallel.apply(null, thunk).call(null, each)
return [ +key, thunk ] // convert `key` to number
}

View File

@ -1,7 +1,7 @@
import axios from "axios";
import Auth from "./Auth";
export let baseURL = "/api/v3";
export const baseURL = "/api/v3";
export const getBaseURL = () => {
return baseURL;

View File

@ -5,7 +5,7 @@ const Auth = {
Auth.isAuthenticated = true;
},
GetUser(){
return JSON.parse(localStorage.getItem("user"))
return JSON.parse(localStorage.getItem("user") || '')
},
SetUser(newUser: any){
localStorage.setItem("user", JSON.stringify(newUser));
@ -22,18 +22,18 @@ const Auth = {
},
signout() {
Auth.isAuthenticated = false;
let oldUser = Auth.GetUser();
const oldUser = Auth.GetUser();
oldUser.id = 0;
localStorage.setItem("user", JSON.stringify(oldUser));
},
SetPreference(key: string,value: any){
let preference = JSON.parse(localStorage.getItem("user_preference"));
let preference = JSON.parse(localStorage.getItem("user_preference") || '');
preference = (preference == null) ? {} : preference;
preference[key] = value;
localStorage.setItem("user_preference", JSON.stringify(preference));
},
GetPreference(key: string): any | null{
let preference = JSON.parse(localStorage.getItem("user_preference"));
const preference = JSON.parse(localStorage.getItem("user_preference") || '');
if (preference && preference[key]){
return preference[key];
}

View File

@ -3,28 +3,11 @@ import { fixUrlHash } from "../utils/index"
import API from "./Api"
import Auth from "./Auth"
import pathHelper from "../utils/page";
export var InitSiteConfig = (rawStore) => {
// 从缓存获取默认配置
let configCache = JSON.parse(localStorage.getItem('siteConfigCache'));
if (configCache != null) {
rawStore.siteConfig = configCache
}
// 检查是否有path参数
var url = new URL(fixUrlHash(window.location.href));
var c = url.searchParams.get("path");
rawStore.navigator.path = c===null?"/":c;
// 初始化用户个性配置
rawStore.siteConfig = initUserConfig(rawStore.siteConfig);
// 更改站点标题
document.title = rawStore.siteConfig.title;
return rawStore
}
const initUserConfig = (siteConfig) => {
if (siteConfig.user!==undefined && !siteConfig.user.anonymous){
let themes = JSON.parse(siteConfig.themes);
let user = siteConfig.user;
const themes = JSON.parse(siteConfig.themes);
const user = siteConfig.user;
delete siteConfig.user
//更换用户自定配色
@ -41,9 +24,27 @@ const initUserConfig = (siteConfig) => {
return siteConfig
}
export const InitSiteConfig = (rawStore) => {
// 从缓存获取默认配置
const configCache = JSON.parse(localStorage.getItem('siteConfigCache'));
if (configCache != null) {
rawStore.siteConfig = configCache
}
// 检查是否有path参数
const url = new URL(fixUrlHash(window.location.href));
const c = url.searchParams.get("path");
rawStore.navigator.path = c===null?"/":c;
// 初始化用户个性配置
rawStore.siteConfig = initUserConfig(rawStore.siteConfig);
// 更改站点标题
document.title = rawStore.siteConfig.title;
return rawStore
}
export function enableUploaderLoad(){
// 开启上传组件加载
let user = Auth.GetUser();
const user = Auth.GetUser();
window.policyType = user!==null?user.policy.saveType : "local";
window.uploadConfig = user!==null?user.policy:{};
window.pathCache = [];
@ -51,18 +52,18 @@ export function enableUploaderLoad(){
export async function UpdateSiteConfig(store) {
API.get("/site/config").then(function(response) {
let themes = JSON.parse(response.data.themes);
const themes = JSON.parse(response.data.themes);
response.data.theme = themes[response.data.defaultTheme]
response.data = initUserConfig(response.data)
store.dispatch(setSiteConfig(response.data));
localStorage.setItem('siteConfigCache', JSON.stringify(response.data));
// 偏爱的列表样式
let preferListMethod = Auth.GetPreference("view_method");
const preferListMethod = Auth.GetPreference("view_method");
if(preferListMethod){
store.dispatch(changeViewMethod(preferListMethod));
}else{
let path = window.location.hash.split("#");
const path = window.location.hash.split("#");
if(path.length >=1 && pathHelper.isSharePage(path[1])){
store.dispatch(changeViewMethod(response.data.share_view_method));
}else{

View File

@ -58,7 +58,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<DownloadApp/>

View File

@ -59,7 +59,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<FileShareApp/>

View File

@ -59,7 +59,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<FolderShareApp/>

View File

@ -58,7 +58,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<LockApp/>

View File

@ -58,7 +58,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<LoginApp/>

View File

@ -58,7 +58,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<MarkdownApp/>

View File

@ -58,7 +58,7 @@ const defaultStatus = {
}
};
let store = createStore(cloureveApp,defaultStatus)
const store = createStore(cloureveApp,defaultStatus)
ReactDOM.render(
<Provider store={store}>
<MyShareApp/>

Some files were not shown because too many files have changed in this diff Show More