文件下载

This commit is contained in:
HFO4 2019-12-14 12:45:11 +08:00
parent 9f4078c119
commit 8cd187c947
16 changed files with 1491 additions and 919 deletions

View File

@ -16,6 +16,7 @@
"react-dnd": "^9.5.1",
"react-dnd-html5-backend": "^9.5.1",
"react-dom": "^16.12.0",
"react-hotkeys": "^2.0.0",
"react-image-lightbox": "^5.1.1",
"react-lazy-load-image-component": "^1.3.2",
"react-redux": "^7.1.3",

View File

@ -177,6 +177,13 @@ export const openCopyDialog = () => {
};
};
export const openLoadingDialog = (text) => {
return {
type: "OPEN_LOADING_DIALOG",
text: text,
}
};
export const closeAllModals = () => {
return {
type: "CLOSE_ALL_MODALS"

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types';
import { connect } from 'react-redux'
import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import {
changeContextMenu,
setNavigatorLoadingStatus,
@ -16,326 +16,478 @@ import {
openRemoteDownloadDialog,
openTorrentDownloadDialog,
openGetSourceDialog,
openCopyDialog
} from "../../actions/index"
import {isPreviewable,isTorrent} from "../../config"
import {allowSharePreview} from "../../untils/index"
import UploadIcon from '@material-ui/icons/CloudUpload'
import DownloadIcon from '@material-ui/icons/CloudDownload'
import NewFolderIcon from '@material-ui/icons/CreateNewFolder'
import OpenFolderIcon from '@material-ui/icons/FolderOpen'
import FileCopyIcon from '@material-ui/icons/FileCopy';
import ShareIcon from '@material-ui/icons/Share'
import RenameIcon from '@material-ui/icons/BorderColor'
import MoveIcon from '@material-ui/icons/Input'
import LinkIcon from '@material-ui/icons/InsertLink'
import DeleteIcon from '@material-ui/icons/Delete'
import OpenIcon from '@material-ui/icons/OpenInNew'
import {MagnetOn} from 'mdi-material-ui'
import {baseURL} from "../../middleware/Api"
import { withStyles, Popover, Typography, MenuList, MenuItem, Divider, ListItemIcon } from '@material-ui/core';
import pathHelper from "../../untils/page"
import {withRouter} from 'react-router-dom'
import Auth from "../../middleware/Auth"
openCopyDialog,
openLoadingDialog
} from "../../actions/index";
import { isPreviewable, isTorrent } from "../../config";
import { allowSharePreview } from "../../untils/index";
import UploadIcon from "@material-ui/icons/CloudUpload";
import DownloadIcon from "@material-ui/icons/CloudDownload";
import NewFolderIcon from "@material-ui/icons/CreateNewFolder";
import OpenFolderIcon from "@material-ui/icons/FolderOpen";
import FileCopyIcon from "@material-ui/icons/FileCopy";
import ShareIcon from "@material-ui/icons/Share";
import RenameIcon from "@material-ui/icons/BorderColor";
import MoveIcon from "@material-ui/icons/Input";
import LinkIcon from "@material-ui/icons/InsertLink";
import DeleteIcon from "@material-ui/icons/Delete";
import OpenIcon from "@material-ui/icons/OpenInNew";
import { MagnetOn } from "mdi-material-ui";
import { baseURL } from "../../middleware/Api";
import {
withStyles,
Popover,
Typography,
MenuList,
MenuItem,
Divider,
ListItemIcon
} from "@material-ui/core";
import pathHelper from "../../untils/page";
import { withRouter } from "react-router-dom";
import Auth from "../../middleware/Auth";
const styles = theme => ({
propover:{
minWidth:"200px!important",
propover: {
minWidth: "200px!important"
}
})
});
const mapStateToProps = state => {
return {
menuType:state.viewUpdate.contextType,
menuOpen:state.viewUpdate.contextOpen,
isMultiple:state.explorer.selectProps.isMultiple,
withFolder:state.explorer.selectProps.withFolder,
withFile:state.explorer.selectProps.withFile,
path:state.navigator.path,
selected:state.explorer.selected,
}
}
menuType: state.viewUpdate.contextType,
menuOpen: state.viewUpdate.contextOpen,
isMultiple: state.explorer.selectProps.isMultiple,
withFolder: state.explorer.selectProps.withFolder,
withFile: state.explorer.selectProps.withFile,
path: state.navigator.path,
selected: state.explorer.selected
};
};
const mapDispatchToProps = dispatch => {
return {
changeContextMenu: (type,open) => {
dispatch(changeContextMenu(type,open))
changeContextMenu: (type, open) => {
dispatch(changeContextMenu(type, open));
},
setNavigatorLoadingStatus: status => {
dispatch(setNavigatorLoadingStatus(status))
dispatch(setNavigatorLoadingStatus(status));
},
navitateTo:path => {
dispatch(navitateTo(path))
navitateTo: path => {
dispatch(navitateTo(path));
},
openCreateFolderDialog:()=>{
dispatch(openCreateFolderDialog())
openCreateFolderDialog: () => {
dispatch(openCreateFolderDialog());
},
openRenameDialog:()=>{
dispatch(openRenameDialog())
openRenameDialog: () => {
dispatch(openRenameDialog());
},
openMoveDialog:()=>{
dispatch(openMoveDialog())
openMoveDialog: () => {
dispatch(openMoveDialog());
},
openRemoveDialog:()=>{
dispatch(openRemoveDialog())
openRemoveDialog: () => {
dispatch(openRemoveDialog());
},
openShareDialog:()=>{
dispatch(openShareDialog())
openShareDialog: () => {
dispatch(openShareDialog());
},
showImgPreivew:(first)=>{
dispatch(showImgPreivew(first))
showImgPreivew: first => {
dispatch(showImgPreivew(first));
},
openMusicDialog:()=>{
dispatch(openMusicDialog())
openMusicDialog: () => {
dispatch(openMusicDialog());
},
toggleSnackbar:(vertical,horizontal,msg,color)=>{
dispatch(toggleSnackbar(vertical,horizontal,msg,color))
toggleSnackbar: (vertical, horizontal, msg, color) => {
dispatch(toggleSnackbar(vertical, horizontal, msg, color));
},
openRemoteDownloadDialog:()=>{
dispatch(openRemoteDownloadDialog())
openRemoteDownloadDialog: () => {
dispatch(openRemoteDownloadDialog());
},
openTorrentDownloadDialog:()=>{
dispatch(openTorrentDownloadDialog())
openTorrentDownloadDialog: () => {
dispatch(openTorrentDownloadDialog());
},
openGetSourceDialog:()=>{
dispatch(openGetSourceDialog())
openGetSourceDialog: () => {
dispatch(openGetSourceDialog());
},
openCopyDialog:()=>{
dispatch(openCopyDialog())
openCopyDialog: () => {
dispatch(openCopyDialog());
},
openLoadingDialog: text => {
dispatch(openLoadingDialog(text));
}
}
}
};
};
class ContextMenuCompoment extends Component {
X = 0;
Y = 0;
X=0;
Y=0;
state={
}
state = {};
componentDidMount = ()=>{
window.document.addEventListener("mousemove",this.setPoint);
}
setPoint = e=>{
this.Y=e.clientY;
this.X=e.clientX;
componentDidMount = () => {
window.document.addEventListener("mousemove", this.setPoint);
};
setPoint = e => {
this.Y = e.clientY;
this.X = e.clientX;
};
openDownload = ()=>{
if(!allowSharePreview()){
this.props.toggleSnackbar("top","right","未登录用户无法预览","warning");
this.props.changeContextMenu("file",false);
openArchiveDownload = () => {
this.props.changeContextMenu("file", false);
this.props.openLoadingDialog("打包中...");
};
openDownload = () => {
if (!allowSharePreview()) {
this.props.toggleSnackbar(
"top",
"right",
"未登录用户无法预览",
"warning"
);
this.props.changeContextMenu("file", false);
return;
}
this.props.changeContextMenu("file",false);
let downloadPath = this.props.selected[0].path === "/" ? this.props.selected[0].path+this.props.selected[0].name:this.props.selected[0].path+"/"+this.props.selected[0].name;
window.open(baseURL+"/file/download"+(downloadPath));
}
this.props.changeContextMenu("file", false);
this.props.openLoadingDialog("获取下载地址...");
};
enterFolder = () => {
this.props.navitateTo(this.props.path==="/"?this.props.path+this.props.selected[0].name:this.props.path+"/"+this.props.selected[0].name);
}
this.props.navitateTo(
this.props.path === "/"
? this.props.path + this.props.selected[0].name
: this.props.path + "/" + this.props.selected[0].name
);
};
clickUpload = () => {
this.props.changeContextMenu("empty",false);
this.props.changeContextMenu("empty", false);
let uploadButton = document.getElementsByClassName("uploadForm")[0];
if (document.body.contains(uploadButton)){
if (document.body.contains(uploadButton)) {
uploadButton.click();
}else{
this.props.toggleSnackbar("top","right","上传组件还未加载完成","warning");
} else {
this.props.toggleSnackbar(
"top",
"right",
"上传组件还未加载完成",
"warning"
);
}
}
};
openPreview = ()=>{
if(!allowSharePreview()){
this.props.toggleSnackbar("top","right","未登录用户无法预览","warning");
this.props.changeContextMenu("file",false);
openPreview = () => {
if (!allowSharePreview()) {
this.props.toggleSnackbar(
"top",
"right",
"未登录用户无法预览",
"warning"
);
this.props.changeContextMenu("file", false);
return;
}
this.props.changeContextMenu("file",false);
let previewPath = this.props.selected[0].path === "/" ? this.props.selected[0].path+this.props.selected[0].name:this.props.selected[0].path+"/"+this.props.selected[0].name;
switch(isPreviewable(this.props.selected[0].name)){
case 'img':
this.props.changeContextMenu("file", false);
let previewPath =
this.props.selected[0].path === "/"
? this.props.selected[0].path + this.props.selected[0].name
: this.props.selected[0].path +
"/" +
this.props.selected[0].name;
switch (isPreviewable(this.props.selected[0].name)) {
case "img":
this.props.showImgPreivew(this.props.selected[0]);
return;
case 'msDoc':
window.open(window.apiURL.docPreiview+"/?path="+encodeURIComponent(previewPath));
case "msDoc":
window.open(
window.apiURL.docPreiview +
"/?path=" +
encodeURIComponent(previewPath)
);
return;
case 'audio':
case "audio":
this.props.openMusicDialog();
return;
case 'open':
window.open(window.apiURL.preview+"/?action=preview&path="+encodeURIComponent(previewPath));
case "open":
window.open(
window.apiURL.preview +
"/?action=preview&path=" +
encodeURIComponent(previewPath)
);
return;
case 'video':
if(pathHelper.isSharePage(this.props.location.pathname)){
window.location.href=("/Viewer/Video?share=true&shareKey="+window.shareInfo.shareId+"&path="+encodeURIComponent(previewPath));
case "video":
if (pathHelper.isSharePage(this.props.location.pathname)) {
window.location.href =
"/Viewer/Video?share=true&shareKey=" +
window.shareInfo.shareId +
"&path=" +
encodeURIComponent(previewPath);
return;
}
window.location.href=("/Viewer/Video?&path="+encodeURIComponent(previewPath));
window.location.href =
"/Viewer/Video?&path=" + encodeURIComponent(previewPath);
return;
case 'edit':
if(pathHelper.isSharePage(this.props.location.pathname)){
window.location.href=("/Viewer/Markdown?share=true&shareKey="+window.shareInfo.shareId+"&path="+encodeURIComponent(previewPath));
case "edit":
if (pathHelper.isSharePage(this.props.location.pathname)) {
window.location.href =
"/Viewer/Markdown?share=true&shareKey=" +
window.shareInfo.shareId +
"&path=" +
encodeURIComponent(previewPath);
return;
}
window.location.href=("/Viewer/Markdown?path="+encodeURIComponent(previewPath));
window.location.href =
"/Viewer/Markdown?path=" + encodeURIComponent(previewPath);
return;
default:
return;
}
}
};
render() {
const { classes} = this.props;
const { classes } = this.props;
const user = Auth.GetUser();
return (
<div>
<Popover
id="simple-popper"
open={this.props.menuOpen}
anchorReference="anchorPosition"
anchorPosition={{ top: this.Y, left: this.X }}
onClose={()=>this.props.changeContextMenu(this.props.menuType,false)}
anchorOrigin={{
vertical: 'top',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'left',
}}
<div>
<Popover
id="simple-popper"
open={this.props.menuOpen}
anchorReference="anchorPosition"
anchorPosition={{ top: this.Y, left: this.X }}
onClose={() =>
this.props.changeContextMenu(this.props.menuType, false)
}
anchorOrigin={{
vertical: "top",
horizontal: "left"
}}
transformOrigin={{
vertical: "top",
horizontal: "left"
}}
>
{this.props.menuType==="empty"&&
<MenuList>
<MenuItem onClick={this.clickUpload}>
<ListItemIcon>
<UploadIcon/>
</ListItemIcon>
<Typography variant="inherit">上传文件</Typography>
</MenuItem>
{Auth.GetUser().group.allowRemoteDownload&&
<MenuItem onClick={()=>this.props.openRemoteDownloadDialog()}>
{this.props.menuType === "empty" && (
<MenuList>
<MenuItem onClick={this.clickUpload}>
<ListItemIcon>
<DownloadIcon/>
<UploadIcon />
</ListItemIcon>
<Typography variant="inherit">离线下载</Typography>
<Typography variant="inherit">
上传文件
</Typography>
</MenuItem>
}
<Divider/>
<MenuItem onClick = {()=>this.props.openCreateFolderDialog()}>
<ListItemIcon>
<NewFolderIcon/>
</ListItemIcon>
<Typography variant="inherit">创建文件夹</Typography>
</MenuItem>
</MenuList>
}
{this.props.menuType!=="empty"&&
<MenuList>
{(!this.props.isMultiple && this.props.withFolder)&&
<>
<MenuItem onClick={this.enterFolder}>
<ListItemIcon>
<OpenFolderIcon/>
</ListItemIcon>
<Typography variant="inherit">进入</Typography>
</MenuItem>
<Divider/>
</>
}
{(!this.props.isMultiple&&this.props.withFile&&isPreviewable(this.props.selected[0].name))&&
<>
<MenuItem onClick={()=>this.openPreview()}>
{user.group.allowRemoteDownload && (
<MenuItem
onClick={() =>
this.props.openRemoteDownloadDialog()
}
>
<ListItemIcon>
<OpenIcon/>
<DownloadIcon />
</ListItemIcon>
<Typography variant="inherit">打开</Typography>
<Typography variant="inherit">
离线下载
</Typography>
</MenuItem>
<Divider/>
</>
}
)}
{(!this.props.isMultiple&&this.props.withFile)&&
<MenuItem onClick={()=>this.openDownload()}>
<Divider />
<MenuItem
onClick={() =>
this.props.openCreateFolderDialog()
}
>
<ListItemIcon>
<DownloadIcon/>
<NewFolderIcon />
</ListItemIcon>
<Typography variant="inherit">下载</Typography>
<Typography variant="inherit">
创建文件夹
</Typography>
</MenuItem>
}
</MenuList>
)}
{this.props.menuType !== "empty" && (
<MenuList>
{!this.props.isMultiple && this.props.withFolder && (
<>
<MenuItem onClick={this.enterFolder}>
<ListItemIcon>
<OpenFolderIcon />
</ListItemIcon>
<Typography variant="inherit">
进入
</Typography>
</MenuItem>
<Divider />
</>
)}
{!this.props.isMultiple &&
this.props.withFile &&
isPreviewable(this.props.selected[0].name) && (
<>
<MenuItem
onClick={() => this.openPreview()}
>
<ListItemIcon>
<OpenIcon />
</ListItemIcon>
<Typography variant="inherit">
打开
</Typography>
</MenuItem>
<Divider />
</>
)}
{(!this.props.isMultiple&&this.props.withFile&&(Auth.GetUser().policy.allowSource))&&
<MenuItem onClick={()=>this.props.openGetSourceDialog()}>
<ListItemIcon>
<LinkIcon/>
</ListItemIcon>
<Typography variant="inherit">获取外链</Typography>
</MenuItem>
}
{!this.props.isMultiple && this.props.withFile && (
<MenuItem onClick={() => this.openDownload()}>
<ListItemIcon>
<DownloadIcon />
</ListItemIcon>
<Typography variant="inherit">
下载
</Typography>
</MenuItem>
)}
{(!this.props.isMultiple&&pathHelper.isHomePage(this.props.location.pathname)&&(Auth.GetUser().group.allowTorrentDownload)&&this.props.withFile&&isTorrent(this.props.selected[0].name))&&
<MenuItem onClick={()=>this.props.openTorrentDownloadDialog()}>
<ListItemIcon>
<MagnetOn/>
</ListItemIcon>
<Typography variant="inherit">创建离线下载任务</Typography>
</MenuItem>
}
{(this.props.isMultiple || this.props.withFolder) &&
user.group.allowArchiveDownload && (
<MenuItem
onClick={() =>
this.openArchiveDownload()
}
>
<ListItemIcon>
<DownloadIcon />
</ListItemIcon>
<Typography variant="inherit">
打包下载
</Typography>
</MenuItem>
)}
{(!this.props.isMultiple && pathHelper.isHomePage(this.props.location.pathname))&&
<MenuItem onClick={()=>this.props.openShareDialog()}>
<ListItemIcon>
<ShareIcon/>
</ListItemIcon>
<Typography variant="inherit">分享</Typography>
</MenuItem>
}
{(!this.props.isMultiple&&pathHelper.isHomePage(this.props.location.pathname))&&
<>
<MenuItem onClick={()=>this.props.openRenameDialog() }>
<ListItemIcon>
<RenameIcon/>
</ListItemIcon>
<Typography variant="inherit">重命名</Typography>
</MenuItem>
<MenuItem onClick={()=>this.props.openCopyDialog() }>
<ListItemIcon>
<FileCopyIcon/>
</ListItemIcon>
<Typography variant="inherit">复制</Typography>
</MenuItem>
</>
}
{pathHelper.isHomePage(this.props.location.pathname)&&<div>
<MenuItem onClick={()=>this.props.openMoveDialog() }>
<ListItemIcon>
<MoveIcon/>
</ListItemIcon>
<Typography variant="inherit">移动</Typography>
</MenuItem>
<Divider/>
<MenuItem className={classes.propover} onClick={()=>this.props.openRemoveDialog()}>
<ListItemIcon>
<DeleteIcon/>
</ListItemIcon>
<Typography variant="inherit">删除</Typography>
</MenuItem>
</div>}
{!this.props.isMultiple &&
this.props.withFile &&
user.policy.allowSource && (
<MenuItem
onClick={() =>
this.props.openGetSourceDialog()
}
>
<ListItemIcon>
<LinkIcon />
</ListItemIcon>
<Typography variant="inherit">
获取外链
</Typography>
</MenuItem>
)}
{!this.props.isMultiple &&
pathHelper.isHomePage(
this.props.location.pathname
) &&
user.group.allowTorrentDownload &&
this.props.withFile &&
isTorrent(this.props.selected[0].name) && (
<MenuItem
onClick={() =>
this.props.openTorrentDownloadDialog()
}
>
<ListItemIcon>
<MagnetOn />
</ListItemIcon>
<Typography variant="inherit">
创建离线下载任务
</Typography>
</MenuItem>
)}
</MenuList>
}
{!this.props.isMultiple &&
pathHelper.isHomePage(
this.props.location.pathname
) && (
<MenuItem
onClick={() =>
this.props.openShareDialog()
}
>
<ListItemIcon>
<ShareIcon />
</ListItemIcon>
<Typography variant="inherit">
分享
</Typography>
</MenuItem>
)}
{!this.props.isMultiple &&
pathHelper.isHomePage(
this.props.location.pathname
) && (
<>
<MenuItem
onClick={() =>
this.props.openRenameDialog()
}
>
<ListItemIcon>
<RenameIcon />
</ListItemIcon>
<Typography variant="inherit">
重命名
</Typography>
</MenuItem>
<MenuItem
onClick={() =>
this.props.openCopyDialog()
}
>
<ListItemIcon>
<FileCopyIcon />
</ListItemIcon>
<Typography variant="inherit">
复制
</Typography>
</MenuItem>
</>
)}
{pathHelper.isHomePage(
this.props.location.pathname
) && (
<div>
<MenuItem
onClick={() =>
this.props.openMoveDialog()
}
>
<ListItemIcon>
<MoveIcon />
</ListItemIcon>
<Typography variant="inherit">
移动
</Typography>
</MenuItem>
<Divider />
<MenuItem
className={classes.propover}
onClick={() =>
this.props.openRemoveDialog()
}
>
<ListItemIcon>
<DeleteIcon />
</ListItemIcon>
<Typography variant="inherit">
删除
</Typography>
</MenuItem>
</div>
)}
</MenuList>
)}
</Popover>
</div>
);
@ -344,13 +496,12 @@ class ContextMenuCompoment extends Component {
ContextMenuCompoment.propTypes = {
classes: PropTypes.object.isRequired,
menuType:PropTypes.string.isRequired,
menuType: PropTypes.string.isRequired
};
const ContextMenu = connect(
mapStateToProps,
mapDispatchToProps
)( withStyles(styles)(withRouter(ContextMenuCompoment)))
)(withStyles(styles)(withRouter(ContextMenuCompoment)));
export default ContextMenu
export default ContextMenu;

View File

@ -1,7 +1,6 @@
import React from "react";
import SmallIcon from "../SmallIcon";
import FileIcon from "../FileIcon";
import Folder from "../Folder";
import { useSelector } from "react-redux";
import { makeStyles } from "@material-ui/core";
@ -46,7 +45,7 @@ const Preview = props => {
const classes = useStyles();
return (
<>
{selected.length == 0 && diliverIcon(props.object,viewMethod,classes)}
{selected.length === 0 && diliverIcon(props.object,viewMethod,classes)}
{selected.length>0&&<>
{selected.slice(0, 3).map((card, i) => (
<div
@ -57,7 +56,7 @@ const Preview = props => {
transform: `rotateZ(${-i * 2.5}deg)`,
}}
>
{diliverIcon(props.object,viewMethod,classes)}
{diliverIcon(card,viewMethod,classes)}
</div>
))}
</>

View File

@ -1,7 +1,7 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import {navitateTo, changeContextMenu, navitateUp, setSelectedTarget} from "../../actions/index";
import {navitateTo, changeContextMenu, navitateUp, setSelectedTarget, openRemoveDialog} from "../../actions/index";
import ObjectIcon from "./ObjectIcon";
import ContextMenu from "./ContextMenu";
import EmptyIcon from "@material-ui/icons/Unarchive";
@ -24,6 +24,7 @@ import {
Paper,
Button
} from "@material-ui/core";
import { GlobalHotKeys } from "react-hotkeys";
const styles = theme => ({
paper: {
@ -141,11 +142,40 @@ const mapDispatchToProps = dispatch => {
setSelectedTarget: targets => {
dispatch(setSelectedTarget(targets));
},
openRemoveDialog:()=>{
dispatch(openRemoveDialog())
},
};
};
class ExplorerCompoment extends Component {
constructor() {
super();
this.keyMap = {
DELETE_FILE: "del",
SELECT_ALL:"ctrl+a",
};
this.handlers = {
DELETE_FILE: ()=>{
if (this.props.selected.length > 0){
this.props.openRemoveDialog();
}
},
SELECT_ALL:(e)=>{
e.preventDefault();
if(this.props.selected.length >= this.props.dirList.length + this.props.fileList.length){
this.props.setSelectedTarget([]);
}else{
this.props.setSelectedTarget([...this.props.dirList,...this.props.fileList]);
}
},
};
}
contextMenu = e => {
e.preventDefault();
if (this.props.keywords === null && !pathHelper.isSharePage(this.props.location.pathname)) {
@ -170,7 +200,7 @@ class ExplorerCompoment extends Component {
const { classes } = this.props;
return (
<div
onContextMenu={this.contextMenu}
onClick={this.ClickAway}
@ -183,6 +213,7 @@ class ExplorerCompoment extends Component {
classes.button
)}
>
<GlobalHotKeys handlers={this.handlers} keyMap={this.keyMap}/>
<ContextMenu />
<ImgPreivew />
{this.props.navigatorError && (

View File

@ -47,7 +47,7 @@ class ImgPreviewCompoment extends Component {
title: value.name,
src:
baseURL +
"/file/download" +
"/file/redirect" +
(value.path === "/"
? value.path + value.name
: value.path + "/" + value.name)

File diff suppressed because it is too large Load Diff

View File

@ -190,11 +190,7 @@ export default function ObjectIcon(props) {
"/Viewer/Markdown?path=" + encodeURIComponent(previewPath);
return;
default:
window.open(
window.apiURL.download +
"?action=download&path=" +
encodeURIComponent(previewPath)
);
this.props.openLoadingDialog("获取下载地址...");
return;
}
};

View File

@ -3,7 +3,7 @@ import { useDispatch, useSelector } from "react-redux";
import LockOutlinedIcon from "@material-ui/icons/LockOutlined";
import { makeStyles } from "@material-ui/core";
import { toggleSnackbar, applyThemes } from "../../actions/index";
import Placeholder from "../placeholder/captcha";
import Placeholder from "../Placeholder/captcha";
import { useHistory } from "react-router-dom";
import API from "../../middleware/Api";
import Auth from "../../middleware/Auth";

View File

@ -1,45 +1,51 @@
import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import CircularProgress from '@material-ui/core/CircularProgress';
import DialogContent from '@material-ui/core/DialogContent';
import Dialog from '@material-ui/core/Dialog';
import DialogContentText from '@material-ui/core/DialogContentText';
import { blue } from '@material-ui/core/colors';
import React from "react";
import PropTypes from "prop-types";
import { makeStyles } from "@material-ui/core/styles";
import CircularProgress from "@material-ui/core/CircularProgress";
import DialogContent from "@material-ui/core/DialogContent";
import Dialog from "@material-ui/core/Dialog";
import DialogContentText from "@material-ui/core/DialogContentText";
import { blue } from "@material-ui/core/colors";
import {useSelector} from "react-redux";
const emails = ['username@gmail.com', 'user02@gmail.com'];
const useStyles = makeStyles({
avatar: {
backgroundColor: blue[100],
color: blue[600],
},
loadingContainer:{
display:"flex",
},
loading:{
marginTop: 10,
marginLeft: 20,
}
avatar: {
backgroundColor: blue[100],
color: blue[600]
},
loadingContainer: {
display: "flex"
},
loading: {
marginTop: 10,
marginLeft: 20
}
});
export default function LoadingDialog(props) {
const classes = useStyles();
const { open } = props;
const classes = useStyles();
const open = useSelector(
state => state.viewUpdate.modals.loading,
);
const text = useSelector(
state => state.viewUpdate.modals.loadingText,
);
return (
<Dialog aria-labelledby="simple-dialog-title" open={open}>
<DialogContent>
<DialogContentText className={classes.loadingContainer}><CircularProgress color="secondary" />
<div className={classes.loading}>处理中...</div>
</DialogContentText>
</DialogContent>
</Dialog>
);
return (
<Dialog aria-labelledby="simple-dialog-title" open={open}>
<DialogContent>
<DialogContentText className={classes.loadingContainer}>
<CircularProgress color="secondary" />
<div className={classes.loading}>
{text}
</div>
</DialogContentText>
</DialogContent>
</Dialog>
);
}
LoadingDialog.propTypes = {
open: PropTypes.bool.isRequired,
open: PropTypes.bool.isRequired
};

View File

@ -35,7 +35,7 @@ import {
openMoveDialog,
openRemoveDialog,
openShareDialog,
openRenameDialog
openRenameDialog, openLoadingDialog
} from "../../actions";
import {
allowSharePreview,
@ -134,6 +134,9 @@ const mapDispatchToProps = dispatch => {
},
openShareDialog: () => {
dispatch(openShareDialog());
},
openLoadingDialog:(text) => {
dispatch(openLoadingDialog(text))
}
};
};
@ -398,17 +401,16 @@ class NavbarCompoment extends Component {
);
return;
}
let downloadPath =
this.props.selected[0].path === "/"
? this.props.selected[0].path + this.props.selected[0].name
: this.props.selected[0].path +
"/" +
this.props.selected[0].name;
window.open(baseURL + "/file/download" + downloadPath);
this.props.openLoadingDialog("获取下载地址...");
};
archiveDownload = () =>{
this.props.openLoadingDialog("打包中...");
}
render() {
const { classes } = this.props;
const user =Auth.GetUser();
const drawer = (
<div id="container" className={classes.upDrawer}>
@ -818,6 +820,27 @@ class NavbarCompoment extends Component {
</Tooltip>
</Grow>
)}
{(this.props.isMultiple || this.props.withFolder) &&
user.group.allowArchiveDownload && (
<Grow
in={
(this.props.isMultiple || this.props.withFolder) &&
user.group.allowArchiveDownload
}
>
<Tooltip title="打包下载">
<IconButton
color="inherit"
onClick={() =>
this.archiveDownload()
}
>
<DownloadIcon />
</IconButton>
</Tooltip>
</Grow>
)}
{!this.props.isMultiple &&
this.props.withFolder && (
<Grow

View File

@ -25,7 +25,7 @@ const mapDispatchToProps = dispatch => {
};
};
class UploaderCompoment extends Component {
class UploaderComponent extends Component {
constructor(props) {
super(props);
this.state = {
@ -139,7 +139,7 @@ const Uploader = connect(mapStateToProps, mapDispatchToProps, null, {
["/static/js/uploader/i18n/zh_CN.js"],
["/static/js/uploader/ui.js"],
["/static/js/uploader/uploader.js"]
)(UploaderCompoment)
)(UploaderComponent)
);
export default Uploader;

View File

@ -331,6 +331,16 @@ const cloudreveApp = (state = [], action) => {
contextOpen:false,
}),
});
case 'OPEN_LOADING_DIALOG':
return Object.assign({}, state, {
viewUpdate: Object.assign({}, state.viewUpdate, {
modals: Object.assign({}, state.viewUpdate.modals, {
loading:true,
loadingText:action.text,
}),
contextOpen:false,
}),
});
case 'CLOSE_ALL_MODALS':
return Object.assign({}, state, {
viewUpdate: Object.assign({}, state.viewUpdate, {
@ -346,6 +356,7 @@ const cloudreveApp = (state = [], action) => {
getSource:false,
resave:false,
copy:false,
loading:false,
}),
}),
});

View File

@ -1,112 +1,119 @@
export const sizeToString = (bytes) => {
if (bytes === 0) return '0 B';
export const sizeToString = bytes => {
if (bytes === 0) return "0 B";
var k = 1024;
var sizes = ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toFixed(1) + ' ' + sizes[i];
}
return (bytes / Math.pow(k, i)).toFixed(1) + " " + sizes[i];
};
export const fixUrlHash = (path)=> {
var relativePath = path.split('#')
var url = new URL('http://example.com/' + relativePath[1]);
export const fixUrlHash = path => {
var relativePath = path.split("#");
var url = new URL("http://example.com/" + relativePath[1]);
return url.toString();
}
};
export const setCookie = (name,value,days)=>{
export const setCookie = (name, value, days) => {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
}
document.cookie = name + "=" + (value || "") +"; path=/";
}
document.cookie = name + "=" + (value || "") + "; path=/";
};
export const setGetParameter = (paramName, paramValue) =>{
export const setGetParameter = (paramName, paramValue) => {
var url = window.location.href;
if (url.indexOf(paramName + "=") >= 0)
{
if (url.indexOf(paramName + "=") >= 0) {
var prefix = url.substring(0, url.indexOf(paramName));
var suffix = url.substring(url.indexOf(paramName));
suffix = suffix.substring(suffix.indexOf("=") + 1);
suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : "";
suffix =
suffix.indexOf("&") >= 0
? suffix.substring(suffix.indexOf("&"))
: "";
url = prefix + paramName + "=" + paramValue + suffix;
} else {
if (url.indexOf("?") < 0) url += "?" + paramName + "=" + paramValue;
else url += "&" + paramName + "=" + paramValue;
}
else
{
if (url.indexOf("?") < 0)
url += "?" + paramName + "=" + paramValue;
else
url += "&" + paramName + "=" + paramValue;
}
if(url===window.location.href){
if (url === window.location.href) {
return;
}
window.history.pushState(null, null, url);
}
};
export const allowSharePreview=()=>{
if(!window.isSharePage){
export const allowSharePreview = () => {
if (!window.isSharePage) {
return true;
}
if(window.isSharePage){
if(window.shareInfo.allowPreview){
if (window.isSharePage) {
if (window.shareInfo.allowPreview) {
return true;
}
if(window.userInfo.uid===-1){
if (window.userInfo.uid === -1) {
return false;
}
return true;
}
}
};
export const checkGetParameters= field=>{
export const checkGetParameters = field => {
var url = window.location.href;
if(url.indexOf('?' + field + '=') !== -1)
return true;
else if(url.indexOf('&' + field + '=') !== -1)
return true;
return false
}
if (url.indexOf("?" + field + "=") !== -1) return true;
else if (url.indexOf("&" + field + "=") !== -1) return true;
return false;
};
export const changeThemeColor = color=>{
var metaThemeColor = window.document.querySelector("meta[name=theme-color]");
export const changeThemeColor = color => {
var metaThemeColor = window.document.querySelector(
"meta[name=theme-color]"
);
metaThemeColor.setAttribute("content", color);
}
};
export const decode=(c)=>{
export const decode = c => {
var e = c.height,
a = c.width,
b = document.createElement("canvas");
a = c.width,
b = document.createElement("canvas");
b.height = e;
b.width = a;
b = b.getContext("2d");
b.drawImage(c, 0, 0);
c = b.getImageData(0, 0, a, e);
b = [];
for (var d = 0; d < a * e * 4; d += 4) 0 != (d + 4) % (4 * a) && [].push.apply(b, [].slice.call(c.data, d, d + 3));
for (var d = 0; d < a * e * 4; d += 4)
0 != (d + 4) % (4 * a) &&
[].push.apply(b, [].slice.call(c.data, d, d + 3));
c = e = 0;
for (a = ""; c < b.length && (16 >= c || (0 == b[c] % 2 ? (e++, a += "1") : (e = 0, a += "0"), 17 != e)); c++);
for (
a = "";
c < b.length &&
(16 >= c ||
(0 == b[c] % 2 ? (e++, (a += "1")) : ((e = 0), (a += "0")),
17 != e));
c++
);
a = a.slice(0, -16);
a = a.replace(/[\s]/g, "").replace(/(\d{16})(?=\d)/g, "$1 ");
e = "";
a = a.split(" ");
for (c = 0; c < a.length; c++) {
b = a[c];
if(16 == b.length){
if (16 == b.length) {
b = parseInt(b, 2);
e += String.fromCharCode(b);
e += String.fromCharCode(b);
}
}
return e
return e;
};
export function bufferDecode(value) {
return Uint8Array.from(atob(value), c => c.charCodeAt(0));
}
}
// ArrayBuffer to URLBase64
export function bufferEncode(value) {
// ArrayBuffer to URLBase64
export function bufferEncode(value) {
return btoa(String.fromCharCode.apply(null, new Uint8Array(value)))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");;
}
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
}

View File

@ -8246,7 +8246,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.3"
prop-types@^15.5.10, prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@^15.5.10, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@ -8499,6 +8499,13 @@ react-error-overlay@^6.0.3:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.3.tgz#c378c4b0a21e88b2e159a3e62b2f531fd63bf60d"
integrity sha512-bOUvMWFQVk5oz8Ded9Xb7WVdEi3QGLC8tH7HmYP0Fdp4Bn3qw0tRFmr5TW6mvahzvmrK4a6bqWGfCevBflP+Xw==
react-hotkeys@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-hotkeys/-/react-hotkeys-2.0.0.tgz#a7719c7340cbba888b0e9184f806a9ec0ac2c53f"
integrity sha512-3n3OU8vLX/pfcJrR3xJ1zlww6KS1kEJt0Whxc4FiGV+MJrQ1mYSYI3qS/11d2MJDFm8IhOXMTFQirfu6AVOF6Q==
dependencies:
prop-types "^15.6.1"
react-image-lightbox@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/react-image-lightbox/-/react-image-lightbox-5.1.1.tgz#872d1a4336b5a6410ea7909b767cf59014081004"