mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 05:09:58 -05:00
A user can overwrite existing files when uploading.
This commit is contained in:
parent
3d6ccad0c0
commit
fab3fd62ed
5 changed files with 114 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
import {useDropzone} from "react-dropzone";
|
||||
import {Form, Header, Icon, Progress, Segment} from "./Theme";
|
||||
import {DirectorySearch, mimetypeIconName} from "./Common";
|
||||
import {DirectorySearch, mimetypeIconName, Toggle} from "./Common";
|
||||
import {useUploadFile} from "../hooks/customHooks";
|
||||
import _ from "lodash";
|
||||
import {ThemeContext} from "../contexts/contexts";
|
||||
|
|
@ -11,7 +11,16 @@ import {Form as SForm} from "semantic-ui-react";
|
|||
export function Upload({disabled}) {
|
||||
const {t} = React.useContext(ThemeContext);
|
||||
|
||||
const {setFiles, progresses, destination, setDestination, doClear, tagsSelector} = useUploadFile();
|
||||
const {
|
||||
setFiles,
|
||||
progresses,
|
||||
destination,
|
||||
setDestination,
|
||||
doClear,
|
||||
tagsSelector,
|
||||
overwrite,
|
||||
setOverwrite
|
||||
} = useUploadFile();
|
||||
|
||||
const onDrop = React.useCallback(async (acceptedFiles) => {
|
||||
if (acceptedFiles && acceptedFiles.length > 0) {
|
||||
|
|
@ -73,6 +82,8 @@ export function Upload({disabled}) {
|
|||
/>
|
||||
{tagsSelector}
|
||||
</SForm.Field>
|
||||
|
||||
<Toggle checked={overwrite} label='Overwrite' onChange={() => setOverwrite(!overwrite)}/>
|
||||
</Form>
|
||||
|
||||
{destination ?
|
||||
|
|
|
|||
|
|
@ -1153,6 +1153,7 @@ export const useUploadFile = () => {
|
|||
const [progresses, setProgresses] = useState({});
|
||||
const [destination, setDestination] = useState('');
|
||||
const [tagNames, setTagNames] = React.useState([]);
|
||||
const [overwrite, setOverwrite] = React.useState(false);
|
||||
|
||||
const handleProgress = (name, chunk, totalChunks, status, type) => {
|
||||
const percent = Math.round((100 * chunk) / totalChunks);
|
||||
|
|
@ -1184,6 +1185,9 @@ export const useUploadFile = () => {
|
|||
formData.append('filename', file.path);
|
||||
formData.append('totalChunks', totalChunks.toString());
|
||||
formData.append('destination', destination);
|
||||
if (overwrite) {
|
||||
formData.append('overwrite', 'true');
|
||||
}
|
||||
// Send the size that we're actually sending.
|
||||
formData.append('chunkSize', chunk.size.toString());
|
||||
formData.append('chunk', chunk);
|
||||
|
|
@ -1262,15 +1266,15 @@ export const useUploadFile = () => {
|
|||
const tagsSelector = <TagsSelector selectedTagNames={tagNames} onChange={(i,) => setTagNames(i)}/>;
|
||||
|
||||
return {
|
||||
destination,
|
||||
destination, setDestination,
|
||||
doClear,
|
||||
doUpload,
|
||||
files,
|
||||
progresses,
|
||||
setDestination,
|
||||
setFiles: handleFilesChange,
|
||||
tagNames,
|
||||
tagsSelector,
|
||||
overwrite, setOverwrite,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue