Skip to content

TagSpaces is an offline, open source, document manager with tagging support

add download url (#1876)

Stanimirf0342b07e674
diff --git a/app/components/dialogs/CreateDialog.tsx b/app/components/dialogs/CreateDialog.tsx
index 48052969d..72f6158b9 100644
--- a/app/components/dialogs/CreateDialog.tsx
+++ b/app/components/dialogs/CreateDialog.tsx
@@ -19,9 +19,11 @@
import React, { useReducer, useRef, useState } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
+import { saveAs } from 'file-saver';
import Button from '@mui/material/Button';
import Container from '@mui/material/Container';
import HTMLFileIcon from '@mui/icons-material/PhotoAlbumOutlined';
+import InputAdornment from '@mui/material/InputAdornment';
import TextFileIcon from '@mui/icons-material/InsertDriveFileOutlined';
import MarkdownFileIcon from '@mui/icons-material/DescriptionOutlined';
import AddFileIcon from '@mui/icons-material/NoteAddOutlined';
@@ -60,6 +62,7 @@ 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: {
@@ -96,9 +99,15 @@ interface Props {
destination: string,
onUploadProgress?: (progress: Progress, response: any) => void
) => any;
+ downloadFile: (
+ url: string,
+ destination: string,
+ onDownloadProgress?: (progress: Progress, response: any) => void
+ ) => any;
onUploadProgress: (progress: Progress, response: any) => void;
toggleUploadDialog: () => void;
resetProgress: () => void;
+ setProgress: (path: string, progress: number) => void;
}
function CreateDialog(props: Props) {
@@ -115,6 +124,7 @@ function CreateDialog(props: Props) {
showNotification,
firstRWLocation
} = props;
+ const fileUrl = useRef<string>();
const fileName = useRef<string>(
'note' +
AppConfig.beginTagContainer +
@@ -264,6 +274,56 @@ function CreateDialog(props: Props) {
}
};
+ const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ fileUrl.current = event.target.value;
+ };
+
+ 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);
+ }
+ } 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() + 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();
+ }
+ }
+
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
return (
@@ -422,6 +482,33 @@ function CreateDialog(props: Props) {
</Container>
</Button>
</Grid>
+ <Grid style={{ marginTop: 40 }} item xs={12}>
+ <TextField
+ label={i18n.t('core:url')}
+ margin="dense"
+ name="name"
+ fullWidth={true}
+ data-tid="newUrlTID"
+ InputProps={{
+ endAdornment: (
+ <InputAdornment position="end">
+ <Button
+ data-tid="cancelRenameEntryTID"
+ onClick={() => downloadURL()}
+ >
+ {i18n.t('core:downloadFile')}
+ </Button>
+ </InputAdornment>
+ )
+ }}
+ onKeyDown={event => {
+ if (event.key === 'Enter') {
+ downloadURL();
+ }
+ }}
+ onChange={handleUrlChange}
+ />
+ </Grid>
</Grid>
<input
style={{ display: 'none' }}
@@ -458,9 +545,11 @@ function mapActionCreatorsToProps(dispatch) {
showNotification: AppActions.showNotification,
reflectCreateEntries: AppActions.reflectCreateEntries,
uploadFilesAPI: IOActions.uploadFilesAPI,
+ downloadFile: IOActions.downloadFile,
onUploadProgress: AppActions.onUploadProgress,
toggleUploadDialog: AppActions.toggleUploadDialog,
- resetProgress: AppActions.resetProgress
+ resetProgress: AppActions.resetProgress,
+ setProgress: AppActions.setProgress
},
dispatch
);
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 4d5598155..3da32a732 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -734,6 +734,7 @@
"autosave": "Auto save",
"restore": "Restore",
"createdOn": "Created on",
+ "url": "Download Url",
"duplicateLocationTitle": "Duplicate Location",
"-": "-"
}
diff --git a/app/package.json b/app/package.json
index 9f59a7083..f9bb7a5f7 100644
--- a/app/package.json
+++ b/app/package.json
@@ -16,7 +16,7 @@
"@tagspaces/extensions": "1.0.72"
},
"nodeDependencies": {
- "@tagspaces/tagspaces-ws": "2.1.18",
+ "@tagspaces/tagspaces-ws": "2.1.19",
"@tagspaces/extensions": "1.0.72",
"sharp": "0.31.3"
}
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index 913fe951b..51b0f9bd0 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -432,14 +432,18 @@ function GridPerspective(props: Props) {
const makeFirstSelectedEntryVisible = () => {
if (selectedEntries && selectedEntries.length > 0) {
- const firstSelectedElement = document.querySelector(
- '[data-entry-id="' + selectedEntries[0].uuid + '"]'
- );
- if (
- isObj(firstSelectedElement) &&
- !isVisibleOnScreen(firstSelectedElement)
- ) {
- firstSelectedElement.scrollIntoView(false);
+ try {
+ const firstSelectedElement = document.querySelector(
+ '[data-entry-id="' + selectedEntries[0].uuid + '"]'
+ );
+ if (
+ isObj(firstSelectedElement) &&
+ !isVisibleOnScreen(firstSelectedElement)
+ ) {
+ firstSelectedElement.scrollIntoView(false);
+ }
+ } catch (ex) {
+ console.debug('makeFirstSelectedEntryVisible:', ex);
}
}
};
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 9dd323ec2..fa8440928 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -504,15 +504,15 @@ export default (state: any = initialState, action: any) => {
};
}
case types.TOGGLE_UPLOAD_DIALOG: {
- if (PlatformIO.haveObjectStoreSupport()) {
- // upload dialog have objectStore support only
- return {
- ...state,
- // progress: (state.uploadDialogOpened ? state.progress : []),
- uploadDialogOpened: !state.uploadDialogOpened
- };
- }
- return state;
+ // if (PlatformIO.haveObjectStoreSupport()) {
+ // upload dialog have objectStore support only
+ return {
+ ...state,
+ // progress: (state.uploadDialogOpened ? state.progress : []),
+ uploadDialogOpened: !state.uploadDialogOpened
+ };
+ //}
+ // return state;
}
case types.SET_CURRENT_DIRECTORY_DIRS: {
return {
@@ -1120,7 +1120,7 @@ export const actions = {
type: types.SET_CURRENT_DIRECTORY_DIRS,
dirs
}),
- clearUploadDialog: () => (
+ /*clearUploadDialog: () => (
dispatch: (action) => void
// getState: () => any
) => {
@@ -1131,8 +1131,8 @@ export const actions = {
// const { currentDirectoryPath } = getState().app;
// dispatch(actions.loadDirectoryContent(currentDirectoryPath, false));
}
- },
- clearUploadDialogInt: () => ({
+ },*/
+ clearUploadDialog: () => ({
type: types.CLEAR_UPLOAD_DIALOG
}),
toggleProgressDialog: () => ({
@@ -2305,6 +2305,11 @@ export const actions = {
lmdt: new Date().getTime(),
path
};
+ dispatch(actions.reflectCreateEntryObj(newEntry));
+ },
+ reflectCreateEntryObj: (newEntry: TS.FileSystemEntry) => (
+ dispatch: (action) => void
+ ) => {
dispatch(actions.setSelectedEntries([newEntry]));
dispatch(actions.reflectCreateEntryInt(newEntry));
dispatch(LocationIndexActions.reflectCreateEntry(newEntry));
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index e40b56c02..6bbe050b2 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -29,7 +29,11 @@ import {
} from '@tagspaces/tagspaces-common/paths';
import AppConfig from '-/AppConfig';
import { actions as AppActions } from './app';
-import { copyFilesPromise, renameFilesPromise } from '-/services/utils-io';
+import {
+ copyFilesPromise,
+ getThumbPath,
+ renameFilesPromise
+} from '-/services/utils-io';
import i18n from '../services/i18n';
import { Pro } from '../pro';
import TaggingActions from './tagging-actions';
@@ -190,6 +194,68 @@ const actions = {
);
});
},
+ /**
+ * S3 TODO work for test files only
+ * @param url
+ * @param targetPath
+ * @param onDownloadProgress
+ */
+ downloadFile: (
+ url: string,
+ targetPath: string,
+ onDownloadProgress?: (progress: Progress, response: any) => void
+ ) => (dispatch: (actions: Object) => void) => {
+ function saveFile(response: Response): Promise<TS.FileSystemEntry> {
+ if (AppConfig.isElectron && !PlatformIO.haveObjectStoreSupport()) {
+ return PlatformIO.saveBinaryFilePromise(
+ { path: targetPath },
+ response.body,
+ true,
+ onDownloadProgress
+ );
+ }
+ return response.arrayBuffer().then(arrayBuffer => {
+ return PlatformIO.saveFilePromise(
+ { path: targetPath },
+ arrayBuffer,
+ true
+ );
+ });
+ }
+ return fetch(url)
+ .then(response => saveFile(response))
+ .then((fsEntry: TS.FileSystemEntry) => {
+ return generateThumbnailPromise(
+ PlatformIO.haveObjectStoreSupport() ? url : fsEntry.path,
+ 400
+ ).then(dataURL => {
+ if (dataURL && dataURL.length > 6) {
+ const baseString = dataURL.split(',').pop();
+ const fileContent = base64ToArrayBuffer(baseString);
+ return PlatformIO.saveBinaryFilePromise(
+ {
+ path: getThumbFileLocationForFile(
+ targetPath,
+ PlatformIO.getDirSeparator(),
+ false
+ )
+ },
+ fileContent,
+ true
+ ).then((thumb: TS.FileSystemEntry) => ({
+ ...fsEntry,
+ thumbPath: getThumbPath(thumb.path)
+ }));
+ }
+ return fsEntry;
+ });
+ })
+ .then((fsEntry: TS.FileSystemEntry) => {
+ dispatch(AppActions.reflectCreateEntryObj(fsEntry));
+ return fsEntry;
+ })
+ .catch(e => console.log(e));
+ },
/**
* with HTML5 Files API
* @param files
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index b5dddaac2..b8354b58f 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -425,11 +425,11 @@ export function generateImageThumbnail(
};
img.src = fileURL;
img.onerror = err => {
- console.warn(`Error loading: ${fileURL} for tmb gen with: ${err} `);
+ console.warn(`Error loading: ${fileURL} for tmb gen`, err);
resolve('');
};
} catch (e) {
- console.warn(`Error creating image thumb for : ${fileURL} with: ${e}`);
+ console.warn(`Error creating image thumb for : ${fileURL}`, e);
resolve('');
}
});
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index e3ca59ce9..fea6b640a 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -1347,7 +1347,7 @@ export function getFolderThumbPath(
);
}
-export function getThumbPath(thumbPath: string, lastThumbnailImageChange: any) {
+export function getThumbPath(thumbPath: string, lastThumbnailImageChange?: any) {
if (!thumbPath) {
return undefined;
}
diff --git a/package-lock.json b/package-lock.json
index ce4b0f14a..5bf7082da 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -21,7 +21,7 @@
"@mui/styles": "5.10.15",
"@mui/x-date-pickers": "^5.0.8",
"@tagspaces/tagspaces-md": "2.1.6",
- "@tagspaces/tagspaces-platforms": "2.1.17",
+ "@tagspaces/tagspaces-platforms": "2.1.19",
"aws-amplify": "^4.3.8",
"aws-sdk": "^2.1036.0",
"babel-polyfill": "^6.26.0",
@@ -13823,9 +13823,9 @@
}
},
"node_modules/@tagspaces/tagspaces-platforms": {
- "version": "2.1.17",
- "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.17.tgz",
- "integrity": "sha512-Eq8tWNL9tiMQ5WW0TEkSMXCfkrVuPxlOuVyNHAeHByeqx1e7BqF/BfA5gOrq4y8J4l5MrkR12KdNmtaS9w7JQQ==",
+ "version": "2.1.19",
+ "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.19.tgz",
+ "integrity": "sha512-YM46T9QNSOZUPoSzjfAJk3/1agG8RtrrvTTm2ahxMOWCD1Z27NE9Ov6sruSQLePyl9h2XhBDnl3208bClnKZhw==",
"hasInstallScript": true
},
"node_modules/@testim/chrome-version": {
@@ -59523,9 +59523,9 @@
}
},
"@tagspaces/tagspaces-platforms": {
- "version": "2.1.17",
- "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.17.tgz",
- "integrity": "sha512-Eq8tWNL9tiMQ5WW0TEkSMXCfkrVuPxlOuVyNHAeHByeqx1e7BqF/BfA5gOrq4y8J4l5MrkR12KdNmtaS9w7JQQ=="
+ "version": "2.1.19",
+ "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.19.tgz",
+ "integrity": "sha512-YM46T9QNSOZUPoSzjfAJk3/1agG8RtrrvTTm2ahxMOWCD1Z27NE9Ov6sruSQLePyl9h2XhBDnl3208bClnKZhw=="
},
"@testim/chrome-version": {
"version": "1.1.3",
diff --git a/package.json b/package.json
index 5451c3385..f28822127 100644
--- a/package.json
+++ b/package.json
@@ -159,7 +159,7 @@
"@mui/styles": "5.10.15",
"@mui/x-date-pickers": "^5.0.8",
"@tagspaces/tagspaces-md": "2.1.6",
- "@tagspaces/tagspaces-platforms": "2.1.18",
+ "@tagspaces/tagspaces-platforms": "2.1.19",
"aws-amplify": "^4.3.8",
"aws-sdk": "^2.1036.0",
"babel-polyfill": "^6.26.0",