mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
Feat: support dispatch remote policy uploader
This commit is contained in:
parent
a5de76bf64
commit
98dba63496
|
|
@ -7,11 +7,11 @@ import { sizeToString } from "../../utils";
|
|||
import { toggleSnackbar } from "../../actions";
|
||||
|
||||
import {
|
||||
withStyles,
|
||||
LinearProgress,
|
||||
Typography,
|
||||
Divider,
|
||||
LinearProgress,
|
||||
Tooltip,
|
||||
Typography,
|
||||
withStyles,
|
||||
} from "@material-ui/core";
|
||||
import ButtonBase from "@material-ui/core/ButtonBase";
|
||||
import { withRouter } from "react-router";
|
||||
|
|
@ -68,6 +68,7 @@ const styles = (theme) => ({
|
|||
},
|
||||
});
|
||||
|
||||
// TODO 使用 hooks 重构
|
||||
class StorageBarCompoment extends Component {
|
||||
state = {
|
||||
percent: 0,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {
|
|||
import React, { useCallback } from "react";
|
||||
import { DeleteSweep } from "@material-ui/icons";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { toggleSnackbar } from "../../../actions";
|
||||
import { refreshStorage, toggleSnackbar } from "../../../actions";
|
||||
import API from "../../../middleware/Api";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({}));
|
||||
|
|
@ -27,6 +27,9 @@ export default function MoreActions({ anchorEl, onClose, uploadManager }) {
|
|||
dispatch(toggleSnackbar(vertical, horizontal, msg, color)),
|
||||
[dispatch]
|
||||
);
|
||||
const RefreshStorage = useCallback(() => dispatch(refreshStorage()), [
|
||||
dispatch,
|
||||
]);
|
||||
|
||||
const actionClicked = (next) => () => {
|
||||
onClose();
|
||||
|
|
@ -37,7 +40,17 @@ export default function MoreActions({ anchorEl, onClose, uploadManager }) {
|
|||
uploadManager.cleanupSessions();
|
||||
API.delete("/file/upload")
|
||||
.then((response) => {
|
||||
ToggleSnackbar("top", "right", "上传会话已清除", "success");
|
||||
if (response.rawData.code === 0) {
|
||||
ToggleSnackbar("top", "right", "上传会话已清除", "success");
|
||||
} else {
|
||||
ToggleSnackbar(
|
||||
"top",
|
||||
"right",
|
||||
response.rawData.msg,
|
||||
"warning"
|
||||
);
|
||||
}
|
||||
RefreshStorage();
|
||||
})
|
||||
.catch((error) => {
|
||||
ToggleSnackbar("top", "right", error.message, "error");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import Base from "./uploader/base";
|
|||
import Local from "./uploader/local";
|
||||
import { Pool } from "./utils/pool";
|
||||
import { cleanupResumeCtx } from "./utils";
|
||||
import Remote from "./uploader/remote";
|
||||
|
||||
export interface Option {
|
||||
logLevel: LogLevel;
|
||||
|
|
@ -45,7 +46,8 @@ export default class UploadManager {
|
|||
switch (task.policy.type) {
|
||||
case PolicyType.local:
|
||||
return new Local(task, this);
|
||||
|
||||
case PolicyType.remote:
|
||||
return new Remote(task, this);
|
||||
default:
|
||||
throw new UnknownPolicyError(
|
||||
"Unknown policy type.",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import { ChunkProgress } from "./uploader/chunk";
|
|||
export enum PolicyType {
|
||||
local = "local",
|
||||
remote = "remote",
|
||||
oss = "oss",
|
||||
qiniu = "qiniu",
|
||||
onedrive = "onedrive",
|
||||
}
|
||||
|
||||
export interface Policy {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,13 @@ export interface Progress {
|
|||
loaded: number;
|
||||
}
|
||||
|
||||
const resumePolicy = [PolicyType.local];
|
||||
const resumePolicy = [
|
||||
PolicyType.local,
|
||||
PolicyType.remote,
|
||||
PolicyType.qiniu,
|
||||
PolicyType.oss,
|
||||
PolicyType.onedrive,
|
||||
];
|
||||
const deleteUploadSessionDelay = 500;
|
||||
|
||||
export default abstract class Base {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
import Chunk, { ChunkInfo } from "./chunk";
|
||||
import { loadUploadChunk } from "../api";
|
||||
|
||||
export default class Remote extends Chunk {
|
||||
protected async uploadChunk(chunkInfo: ChunkInfo) {
|
||||
return loadUploadChunk(
|
||||
this.task.session?.sessionID!,
|
||||
chunkInfo,
|
||||
(p) => {
|
||||
this.updateChunkProgress(p.loaded, chunkInfo.index);
|
||||
},
|
||||
this.cancelToken.token
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue