TagSpaces is an offline, open source, document manager with tagging support
Improve name of the saved file (#1888)
Stanimir948bcb530f7c
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex 90e4b142f..8c3729972 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -1344,6 +1344,9 @@ function EntryProperties(props: Props) {onClose={() => setShowSharingLinkDialog(false)}path={currentEntry.path}showNotification={props.showNotification}+ locationId={currentEntry.locationId}+ switchCurrentLocationType={props.switchCurrentLocationType}+ switchLocationType={props.switchLocationType}/>)}{BgndImgChooserDialog && (diff --git a/app/components/dialogs/CreateDialog.tsx b/app/components/dialogs/CreateDialog.tsxindex 72f6158b9..6c3eec756 100644--- a/app/components/dialogs/CreateDialog.tsx+++ b/app/components/dialogs/CreateDialog.tsx@@ -46,11 +46,7 @@ import {getCurrentDirectoryPerspective} from '-/reducers/app';import IOActions from '-/reducers/io-actions';-import {- getLocations,- getFirstRWLocation,- getCurrentLocation-} from '-/reducers/locations';+import { getFirstRWLocation } from '-/reducers/locations';import { TS } from '-/tagspaces.namespace';import PlatformIO from '-/services/platform-facade';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';@@ -62,7 +58,6 @@ import FormHelperText from '@mui/material/FormHelperText';import { FormControl } from '@mui/material';import { fileNameValidation } from '-/services/utils-io';import { PerspectiveIDs } from '-/perspectives';-import { FileTypeGroups } from '-/services/search';const styles: any = () => ({createButton: {@@ -132,6 +127,7 @@ function CreateDialog(props: Props) {AppConfig.endTagContainer);const [inputError, setInputError] = useState<boolean>(false);+ const [invalidURL, setInvalidURL] = useState<boolean>(false);const [ignored, forceUpdate] = useReducer(x => x + 1, 0);let fileInput: HTMLInputElement;const fileContent = '';@@ -280,47 +276,57 @@ function CreateDialog(props: Props) {function downloadURL() {if (fileUrl.current) {- const url = new URL(fileUrl.current);- let fileName;- let pathParts;- if (url.pathname) {- const delimiterIndex = url.pathname.lastIndexOf('/');- if (delimiterIndex > -1) {- fileName = url.pathname.substring(delimiterIndex + 1);- if (!fileName) {- pathParts = url.pathname.split('/').filter(Boolean);+ try {+ const url = new URL(fileUrl.current);+ if (invalidURL) {+ setInvalidURL(false);+ }+ let fileName;+ let pathParts;+ if (url.pathname) {+ const delimiterIndex = url.pathname.lastIndexOf('/');+ if (delimiterIndex > -1) {+ fileName = url.pathname.substring(delimiterIndex + 1);+ if (!fileName) {+ pathParts = url.pathname.split('/').filter(Boolean);+ }+ } else {+ fileName = url.pathname;}+ }+ if (!fileName) {+ fileName =+ url.hostname ++ (pathParts && pathParts.length > 0 ? pathParts.join('-') : '') ++ '.html';+ } else if (fileName.indexOf('.') === -1) {+ fileName = url.hostname + '-' + fileName + '.html';+ }+ if (PlatformIO.haveObjectStoreSupport() || AppConfig.isElectron) {+ props.resetProgress();+ props.toggleUploadDialog();+ props+ .downloadFile(+ fileUrl.current,+ targetDirectoryPath ++ PlatformIO.getDirSeparator() ++ decodeURIComponent(fileName),+ props.onUploadProgress+ )+ .then(() => {+ if (PlatformIO.haveObjectStoreSupport()) {+ // currently objectStore location in downloadFile use saveFilePromise and this function not have progress handling+ props.setProgress(fileUrl.current, 100);+ }+ });} else {- fileName = url.pathname;+ saveAs(fileUrl.current, decodeURIComponent(fileName));}+ onClose();+ } catch (ex) {+ setInvalidURL(true);+ console.error('downloadURL', ex);}- if (!fileName) {- fileName =- url.hostname +- (pathParts && pathParts.length > 0 ? pathParts.join('-') : '') +- '.html';- } else if (fileName.indexOf('.') === -1) {- fileName = url.hostname + '-' + fileName + '.html';- }- if (PlatformIO.haveObjectStoreSupport() || AppConfig.isElectron) {- props.resetProgress();- props.toggleUploadDialog();- props- .downloadFile(- fileUrl.current,- targetDirectoryPath + PlatformIO.getDirSeparator() + fileName,- props.onUploadProgress- )- .then(() => {- if (PlatformIO.haveObjectStoreSupport()) {- // currently objectStore location in downloadFile use saveFilePromise and this function not have progress handling- props.setProgress(fileUrl.current, 100);- }- });- } else {- saveAs(fileUrl.current, fileName);- }- onClose();}}@@ -484,6 +490,7 @@ function CreateDialog(props: Props) {</Grid><Grid style={{ marginTop: 40 }} item xs={12}><TextField+ error={invalidURL}label={i18n.t('core:url')}margin="dense"name="name"diff --git a/app/components/dialogs/FileUploadDialog.tsx b/app/components/dialogs/FileUploadDialog.tsxindex acbb54592..b5073eb0f 100644--- a/app/components/dialogs/FileUploadDialog.tsx+++ b/app/components/dialogs/FileUploadDialog.tsx@@ -154,7 +154,7 @@ function FileUploadDialog(props: Props) {const percentage = fileProgress.progress;const { path } = fileProgress;const fileName = extractFileName(- path,+ path.split('?')[0],PlatformIO.getDirSeparator());let { abort } = fileProgress;diff --git a/app/components/dialogs/LinkGeneratorDialog.tsx b/app/components/dialogs/LinkGeneratorDialog.tsxindex d97ae0cd7..e0bd36640 100644--- a/app/components/dialogs/LinkGeneratorDialog.tsx+++ b/app/components/dialogs/LinkGeneratorDialog.tsx@@ -16,7 +16,7 @@**/-import React, { ChangeEvent, useRef, useState } from 'react';+import React, { ChangeEvent, useRef, useReducer, useEffect } from 'react';import { Theme } from '@mui/material/styles';import withStyles from '@mui/styles/withStyles';import createStyles from '@mui/styles/createStyles';@@ -36,12 +36,16 @@ import TextField from '@mui/material/TextField';import MenuItem from '@mui/material/MenuItem';import PlatformIO from '-/services/platform-facade';import AppConfig from '-/AppConfig';+import useFirstRender from '-/utils/useFirstRender';interface Props {open: boolean;onClose: () => void;path: string;showNotification: (message: string) => void;+ locationId: string;+ switchLocationType: (locationId: string) => Promise<string | null>;+ switchCurrentLocationType: (currentLocationId: string) => Promise<boolean>;}const QRTextField = withStyles((theme: Theme) =>@@ -57,15 +61,27 @@ const QRTextField = withStyles((theme: Theme) =>function LinkGeneratorDialog(props: Props) {const { open, onClose, path, showNotification } = props;- const [linkValidityDuration, setLinkValidityDuration] = useState<number>(- 60 * 15- );- const signedLink = useRef<string>(- PlatformIO.getURLforPath(path, linkValidityDuration)- );+ const linkValidityDuration = useRef<number>(60 * 15);+ const signedLink = useRef<string>(undefined);+ const [ignored, forceUpdate] = useReducer(x => x + 1, 0);const theme = useTheme();const fullScreen = useMediaQuery(theme.breakpoints.down('md'));+ useEffect(() => {+ setSignedLink();+ }, []);++ function setSignedLink() {+ props.switchLocationType(props.locationId).then(currentLocationId => {+ signedLink.current = PlatformIO.getURLforPath(+ path,+ linkValidityDuration.current+ );+ forceUpdate();+ props.switchCurrentLocationType(currentLocationId);+ });+ }+return (<Dialogopen={open}@@ -91,14 +107,10 @@ function LinkGeneratorDialog(props: Props) {<InfoIcon tooltip={i18n.t('core:linkValidityTooltip')} /></>}- value={linkValidityDuration}+ value={linkValidityDuration.current}onChange={(event: ChangeEvent<HTMLInputElement>) => {- const validityDuration = parseInt(event.target.value, 10);- signedLink.current = PlatformIO.getURLforPath(- path,- validityDuration- );- setLinkValidityDuration(validityDuration);+ linkValidityDuration.current = parseInt(event.target.value, 10);+ setSignedLink();}}><MenuItem value={60 * 15}>15 {i18n.t('core:minutes')}</MenuItem>