mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
fix: cannot download single file share with score
This commit is contained in:
parent
e53609932d
commit
566900ccbb
|
|
@ -322,28 +322,6 @@ export default function S3Guide(props) {
|
|||
setActiveStep(1);
|
||||
}}
|
||||
>
|
||||
<div className={classes.subStepContainer}>
|
||||
<div className={classes.stepNumberContainer}>
|
||||
<div className={classes.stepNumber}>0</div>
|
||||
</div>
|
||||
<div className={classes.subStepContent}>
|
||||
<Typography variant={"body2"}>
|
||||
Cloudreve 主站需要启用 CORS 支持,具体步骤如下:
|
||||
<br />
|
||||
修改 Cloudreve 配置文件,新增以下 CORS
|
||||
配置项,保存并重启 Cloudreve。
|
||||
<pre>
|
||||
[CORS]
|
||||
<br />
|
||||
AllowOrigins = *<br />
|
||||
AllowMethods = OPTIONS,GET,POST
|
||||
<br />
|
||||
AllowHeaders = *<br />
|
||||
</pre>
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={classes.subStepContainer}>
|
||||
<div className={classes.stepNumberContainer}>
|
||||
<div className={classes.stepNumber}>1</div>
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ import { connect } from "react-redux";
|
|||
import { withRouter } from "react-router-dom";
|
||||
import { isCompressFile, isPreviewable, isTorrent } from "../../config";
|
||||
import Auth from "../../middleware/Auth";
|
||||
import { allowSharePreview } from "../../utils/index";
|
||||
import pathHelper from "../../utils/page";
|
||||
import RefreshIcon from "@material-ui/icons/Refresh";
|
||||
import {
|
||||
openPreview,
|
||||
setSelectedTarget,
|
||||
startBatchDownload,
|
||||
startDownload,
|
||||
toggleObjectInfoSidebar,
|
||||
} from "../../redux/explorer/action";
|
||||
import {
|
||||
|
|
@ -154,8 +154,8 @@ const mapDispatchToProps = (dispatch) => {
|
|||
refreshFileList: () => {
|
||||
dispatch(refreshFileList());
|
||||
},
|
||||
openPreview: () => {
|
||||
dispatch(openPreview());
|
||||
openPreview: (share) => {
|
||||
dispatch(openPreview(share));
|
||||
},
|
||||
toggleObjectInfoSidebar: (open) => {
|
||||
dispatch(toggleObjectInfoSidebar(open));
|
||||
|
|
@ -169,6 +169,9 @@ const mapDispatchToProps = (dispatch) => {
|
|||
openFolderSelector: () => {
|
||||
dispatch(openFolderSelector());
|
||||
},
|
||||
startDownload: (share, file) => {
|
||||
dispatch(startDownload(share, file));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -192,18 +195,7 @@ class ContextMenuCompoment extends Component {
|
|||
};
|
||||
|
||||
openDownload = () => {
|
||||
if (!allowSharePreview()) {
|
||||
this.props.toggleSnackbar(
|
||||
"top",
|
||||
"right",
|
||||
"未登录用户无法预览",
|
||||
"warning"
|
||||
);
|
||||
this.props.changeContextMenu("file", false);
|
||||
return;
|
||||
}
|
||||
this.props.changeContextMenu("file", false);
|
||||
this.props.openLoadingDialog("获取下载地址...");
|
||||
this.props.startDownload(this.props.share, this.props.selected[0]);
|
||||
};
|
||||
|
||||
enterFolder = () => {
|
||||
|
|
@ -447,7 +439,9 @@ class ContextMenuCompoment extends Component {
|
|||
<div>
|
||||
<MenuItem
|
||||
dense
|
||||
onClick={() => this.openDownload()}
|
||||
onClick={() =>
|
||||
this.openDownload(this.props.share)
|
||||
}
|
||||
>
|
||||
<StyledListItemIcon>
|
||||
<DownloadIcon />
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import {
|
|||
toggleSnackbar,
|
||||
} from "../../redux/explorer";
|
||||
import OptionSelector from "../Modals/OptionSelector";
|
||||
import { getDownloadURL } from "../../services/file";
|
||||
|
||||
const styles = (theme) => ({
|
||||
wrapper: {
|
||||
|
|
@ -112,30 +111,13 @@ class ModalsCompoment extends Component {
|
|||
};
|
||||
|
||||
newNameSuffix = "";
|
||||
downloaded = false;
|
||||
|
||||
UNSAFE_componentWillReceiveProps = (nextProps) => {
|
||||
if (this.props.dndSignale !== nextProps.dndSignale) {
|
||||
this.dragMove(nextProps.dndSource, nextProps.dndTarget);
|
||||
return;
|
||||
}
|
||||
if (this.props.loading !== nextProps.loading) {
|
||||
// 打包下载
|
||||
if (nextProps.loading === true) {
|
||||
if (nextProps.loadingText === "获取下载地址...") {
|
||||
if (
|
||||
pathHelper.isSharePage(this.props.location.pathname) &&
|
||||
this.props.share &&
|
||||
this.props.share.score > 0
|
||||
) {
|
||||
this.scoreHandler(this.Download);
|
||||
return;
|
||||
}
|
||||
this.Download();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.props.modalsStatus.rename !== nextProps.modalsStatus.rename) {
|
||||
const name = nextProps.selected[0].name;
|
||||
this.setState({
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import { useDrag } from "react-dnd";
|
|||
import { getEmptyImage } from "react-dnd-html5-backend";
|
||||
import DropWarpper from "./DnD/DropWarpper";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import Auth from "../../middleware/Auth";
|
||||
import { pathBack } from "../../utils";
|
||||
import {
|
||||
changeContextMenu,
|
||||
|
|
@ -70,7 +69,13 @@ export default function ObjectIcon(props) {
|
|||
(text) => dispatch(openLoadingDialog(text)),
|
||||
[dispatch]
|
||||
);
|
||||
const OpenPreview = useCallback(() => dispatch(openPreview()), [dispatch]);
|
||||
const OpenPreview = useCallback((share) => dispatch(openPreview(share)), [
|
||||
dispatch,
|
||||
]);
|
||||
const StartDownload = useCallback(
|
||||
(share, file) => dispatch(StartDownload(share, file)),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const classes = useStyles();
|
||||
|
||||
|
|
@ -117,20 +122,8 @@ export default function ObjectIcon(props) {
|
|||
enterFolder();
|
||||
return;
|
||||
}
|
||||
const isShare = statusHelper.isSharePage(location.pathname);
|
||||
if (isShare) {
|
||||
const user = Auth.GetUser();
|
||||
if (!Auth.Check() && user && !user.group.shareDownload) {
|
||||
ToggleSnackbar("top", "right", "请先登录", "warning");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (window.shareInfo && !window.shareInfo.preview) {
|
||||
OpenLoadingDialog("获取下载地址...");
|
||||
return;
|
||||
}
|
||||
|
||||
OpenPreview();
|
||||
OpenPreview(window.shareInfo);
|
||||
};
|
||||
|
||||
const handleIconClick = (e) => {
|
||||
|
|
|
|||
|
|
@ -12,12 +12,7 @@ import MoveIcon from "@material-ui/icons/Input";
|
|||
import DeleteIcon from "@material-ui/icons/Delete";
|
||||
import MenuIcon from "@material-ui/icons/Menu";
|
||||
import { isPreviewable } from "../../config";
|
||||
import {
|
||||
allowSharePreview,
|
||||
changeThemeColor,
|
||||
sizeToString,
|
||||
vhCheck,
|
||||
} from "../../utils";
|
||||
import { changeThemeColor, sizeToString, vhCheck } from "../../utils";
|
||||
import Uploader from "../Uploader/Uploader.js";
|
||||
import pathHelper from "../../utils/page";
|
||||
import SezrchBar from "./SearchBar";
|
||||
|
|
@ -69,7 +64,7 @@ import {
|
|||
showImgPreivew,
|
||||
toggleSnackbar,
|
||||
} from "../../redux/explorer";
|
||||
import { startBatchDownload } from "../../redux/explorer/action";
|
||||
import { startBatchDownload, startDownload } from "../../redux/explorer/action";
|
||||
|
||||
vhCheck();
|
||||
const drawerWidth = 240;
|
||||
|
|
@ -143,8 +138,8 @@ const mapDispatchToProps = (dispatch) => {
|
|||
setSessionStatus: () => {
|
||||
dispatch(setSessionStatus());
|
||||
},
|
||||
openPreview: () => {
|
||||
dispatch(openPreview());
|
||||
openPreview: (share) => {
|
||||
dispatch(openPreview(share));
|
||||
},
|
||||
audioPreviewOpen: () => {
|
||||
dispatch(audioPreviewSetIsOpen(true));
|
||||
|
|
@ -152,6 +147,9 @@ const mapDispatchToProps = (dispatch) => {
|
|||
startBatchDownload: (share) => {
|
||||
dispatch(startBatchDownload(share));
|
||||
},
|
||||
startDownload: (share, file) => {
|
||||
dispatch(startDownload(share, file));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -335,20 +333,11 @@ class NavbarCompoment extends Component {
|
|||
};
|
||||
|
||||
openDownload = () => {
|
||||
if (!allowSharePreview()) {
|
||||
this.props.toggleSnackbar(
|
||||
"top",
|
||||
"right",
|
||||
"未登录用户无法预览",
|
||||
"warning"
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.props.openLoadingDialog("获取下载地址...");
|
||||
this.props.startDownload(window.shareInfo, this.props.selected[0]);
|
||||
};
|
||||
|
||||
archiveDownload = () => {
|
||||
this.props.startBatchDownload(this.props.share);
|
||||
this.props.startBatchDownload(window.shareInfo);
|
||||
};
|
||||
|
||||
signOut = () => {
|
||||
|
|
@ -642,7 +631,9 @@ class NavbarCompoment extends Component {
|
|||
<IconButton
|
||||
color="inherit"
|
||||
onClick={() =>
|
||||
this.props.openPreview()
|
||||
this.props.openPreview(
|
||||
window.shareInfo
|
||||
)
|
||||
}
|
||||
>
|
||||
<OpenIcon />
|
||||
|
|
|
|||
|
|
@ -6,11 +6,18 @@ import { Button, Typography, withStyles } from "@material-ui/core";
|
|||
import Divider from "@material-ui/core/Divider";
|
||||
import TypeIcon from "../FileManager/TypeIcon";
|
||||
import Auth from "../../middleware/Auth";
|
||||
import API from "../../middleware/Api";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import Creator from "./Creator";
|
||||
import pathHelper from "../../utils/page";
|
||||
import { openMusicDialog, openResaveDialog, setSelectedTarget, showImgPreivew, toggleSnackbar } from "../../redux/explorer";
|
||||
import {
|
||||
openMusicDialog,
|
||||
openResaveDialog,
|
||||
setSelectedTarget,
|
||||
showImgPreivew,
|
||||
toggleSnackbar,
|
||||
} from "../../redux/explorer";
|
||||
import { startDownload } from "../../redux/explorer/action";
|
||||
import { trySharePurchase } from "../../redux/explorer/async";
|
||||
|
||||
|
||||
vhCheck();
|
||||
|
|
@ -111,6 +118,10 @@ const mapDispatchToProps = (dispatch) => {
|
|||
openResave: (key) => {
|
||||
dispatch(openResaveDialog(key));
|
||||
},
|
||||
startDownload: (share, file) => {
|
||||
dispatch(startDownload(share, file));
|
||||
},
|
||||
trySharePurchase: (share) => dispatch(trySharePurchase(share)),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -204,6 +215,10 @@ class SharedFileCompoment extends Component {
|
|||
}
|
||||
};
|
||||
|
||||
scoreHandler = (callback) => (event) => {
|
||||
this.props.trySharePurchase(this.props.share).then(() => callback());
|
||||
};
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.setSelectedTarget([]);
|
||||
}
|
||||
|
|
@ -213,23 +228,7 @@ class SharedFileCompoment extends Component {
|
|||
};
|
||||
|
||||
download = () => {
|
||||
this.setState({ loading: true });
|
||||
API.put("/share/download/" + this.props.share.key)
|
||||
.then((response) => {
|
||||
this.downloaded = true;
|
||||
window.location.assign(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.props.toggleSnackbar(
|
||||
"top",
|
||||
"right",
|
||||
error.message,
|
||||
"warning"
|
||||
);
|
||||
})
|
||||
.then(() => {
|
||||
this.setState({ loading: false });
|
||||
});
|
||||
this.props.startDownload(this.props.share, null);
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
@ -263,7 +262,7 @@ class SharedFileCompoment extends Component {
|
|||
<Button
|
||||
variant="outlined"
|
||||
color="secondary"
|
||||
onClick={this.scoreHandle(this.preview)}
|
||||
onClick={this.scoreHandler(this.preview)}
|
||||
disabled={this.state.loading}
|
||||
>
|
||||
预览
|
||||
|
|
@ -275,7 +274,7 @@ class SharedFileCompoment extends Component {
|
|||
variant="contained"
|
||||
color="secondary"
|
||||
className={classes.downloadButton}
|
||||
onClick={this.scoreHandle(this.download)}
|
||||
onClick={this.download}
|
||||
disabled={this.state.loading}
|
||||
>
|
||||
下载
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
showImgPreivew,
|
||||
toggleSnackbar,
|
||||
} from "./index";
|
||||
import { getDownloadURL } from "../../services/file";
|
||||
|
||||
export interface ActionSetFileList extends AnyAction {
|
||||
type: "SET_FILE_LIST";
|
||||
|
|
@ -241,6 +242,40 @@ export const serverSideBatchDownload = (
|
|||
};
|
||||
};
|
||||
|
||||
export const startDownload = (
|
||||
share: any,
|
||||
file: CloudreveFile
|
||||
): ThunkAction<any, any, any, any> => {
|
||||
return async (dispatch, getState): Promise<void> => {
|
||||
const {
|
||||
router: {
|
||||
location: { pathname },
|
||||
},
|
||||
} = getState();
|
||||
const user = Auth.GetUser();
|
||||
if (
|
||||
pathHelper.isSharePage(pathname) &&
|
||||
!Auth.Check() &&
|
||||
user &&
|
||||
!user.group.shareDownload
|
||||
) {
|
||||
dispatch(toggleSnackbar("top", "right", "请先登录", "warning"));
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(changeContextMenu("file", false));
|
||||
dispatch(openLoadingDialog("获取下载地址..."));
|
||||
try {
|
||||
const res = await getDownloadURL(file ? file : share);
|
||||
window.location.assign(res.data);
|
||||
dispatch(closeAllModals());
|
||||
} catch (e) {
|
||||
toggleSnackbar("top", "right", e.message, "warning");
|
||||
dispatch(closeAllModals());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const startBatchDownload = (
|
||||
share: any
|
||||
): ThunkAction<any, any, any, any> => {
|
||||
|
|
@ -397,7 +432,7 @@ export const openViewer = (
|
|||
};
|
||||
};
|
||||
|
||||
export const openPreview = () => {
|
||||
export const openPreview = (share: any) => {
|
||||
return (dispatch: any, getState: any) => {
|
||||
const {
|
||||
explorer: { selected },
|
||||
|
|
@ -439,7 +474,7 @@ export const openPreview = () => {
|
|||
dispatch(openViewer("code", selected[0], isShare));
|
||||
return;
|
||||
default:
|
||||
dispatch(openLoadingDialog("获取下载地址..."));
|
||||
dispatch(startDownload(share, selected[0]));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue