From 566900ccbb187dc469e7a716eefd1ebb060f69fb Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 24 Apr 2022 15:03:35 +0800 Subject: [PATCH] fix: cannot download single file share with score --- src/component/Admin/Policy/Guid/S3Guide.js | 22 ------------ src/component/FileManager/ContextMenu.js | 26 ++++++-------- src/component/FileManager/Modals.js | 20 +---------- src/component/FileManager/ObjectIcon.js | 23 +++++------- src/component/Navbar/Navbar.js | 33 +++++++---------- src/component/Share/SharedFile.js | 41 +++++++++++----------- src/redux/explorer/action.ts | 39 ++++++++++++++++++-- 7 files changed, 88 insertions(+), 116 deletions(-) diff --git a/src/component/Admin/Policy/Guid/S3Guide.js b/src/component/Admin/Policy/Guid/S3Guide.js index 45b4f5f..a3baf1b 100644 --- a/src/component/Admin/Policy/Guid/S3Guide.js +++ b/src/component/Admin/Policy/Guid/S3Guide.js @@ -322,28 +322,6 @@ export default function S3Guide(props) { setActiveStep(1); }} > -
-
-
0
-
-
- - Cloudreve 主站需要启用 CORS 支持,具体步骤如下: -
- 修改 Cloudreve 配置文件,新增以下 CORS - 配置项,保存并重启 Cloudreve。 -
-                                    [CORS]
-                                    
- AllowOrigins = *
- AllowMethods = OPTIONS,GET,POST -
- AllowHeaders = *
-
-
-
-
-
1
diff --git a/src/component/FileManager/ContextMenu.js b/src/component/FileManager/ContextMenu.js index 29613fe..a898ac8 100644 --- a/src/component/FileManager/ContextMenu.js +++ b/src/component/FileManager/ContextMenu.js @@ -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 {
this.openDownload()} + onClick={() => + this.openDownload(this.props.share) + } > diff --git a/src/component/FileManager/Modals.js b/src/component/FileManager/Modals.js index b667956..ee2cd6a 100644 --- a/src/component/FileManager/Modals.js +++ b/src/component/FileManager/Modals.js @@ -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({ diff --git a/src/component/FileManager/ObjectIcon.js b/src/component/FileManager/ObjectIcon.js index 5aa51ae..362b32c 100644 --- a/src/component/FileManager/ObjectIcon.js +++ b/src/component/FileManager/ObjectIcon.js @@ -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) => { diff --git a/src/component/Navbar/Navbar.js b/src/component/Navbar/Navbar.js index e95f971..1aa161a 100644 --- a/src/component/Navbar/Navbar.js +++ b/src/component/Navbar/Navbar.js @@ -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 { - this.props.openPreview() + this.props.openPreview( + window.shareInfo + ) } > diff --git a/src/component/Share/SharedFile.js b/src/component/Share/SharedFile.js index 7de75b4..760dbb6 100644 --- a/src/component/Share/SharedFile.js +++ b/src/component/Share/SharedFile.js @@ -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 {