Skip to content

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

feat: Create a sharing page for s3 containing signed links for the files-ph… (#1953)

Stanimirbdcfe9da7e1d
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsx
index a0fcfdfd5..13ef70202 100644
--- a/app/components/EntryProperties.tsx
+++ b/app/components/EntryProperties.tsx
@@ -1418,7 +1418,7 @@ function EntryProperties(props: Props) {
open={showSharingLinkDialog}
onClose={() => setShowSharingLinkDialog(false)}
path={currentEntry.current.path}
- showNotification={props.showNotification}
+ // showNotification={props.showNotification}
locationId={currentEntry.current.locationId}
switchCurrentLocationType={props.switchCurrentLocationType}
switchLocationType={props.switchLocationType}
diff --git a/app/components/dialogs/LinkGeneratorDialog.tsx b/app/components/dialogs/LinkGeneratorDialog.tsx
index bdc8e74a2..b05a7c0c2 100644
--- a/app/components/dialogs/LinkGeneratorDialog.tsx
+++ b/app/components/dialogs/LinkGeneratorDialog.tsx
@@ -18,6 +18,7 @@
import React, { ChangeEvent, useRef, useReducer, useEffect } from 'react';
import { Theme } from '@mui/material/styles';
+import { useDispatch } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import createStyles from '@mui/styles/createStyles';
import Button from '@mui/material/Button';
@@ -35,15 +36,16 @@ import InputAdornment from '@mui/material/InputAdornment';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import PlatformIO from '-/services/platform-facade';
+import { actions } from '-/reducers/app';
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>;
+ // showNotification: (message: string) => void;
+ locationId?: string;
+ switchLocationType?: (locationId: string) => Promise<string | null>;
+ switchCurrentLocationType?: (currentLocationId: string) => Promise<boolean>;
}
const QRTextField = withStyles((theme: Theme) =>
@@ -58,7 +60,8 @@ const QRTextField = withStyles((theme: Theme) =>
)(TextField);
function LinkGeneratorDialog(props: Props) {
- const { open, onClose, path, showNotification } = props;
+ const { open, onClose, path } = props;
+ const dispatch = useDispatch();
const linkValidityDuration = useRef<number>(60 * 15);
const signedLink = useRef<string>(undefined);
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
@@ -70,14 +73,22 @@ function LinkGeneratorDialog(props: Props) {
}, []);
function setSignedLink() {
- props.switchLocationType(props.locationId).then(currentLocationId => {
+ if (props.switchLocationType) {
+ props.switchLocationType(props.locationId).then(currentLocationId => {
+ signedLink.current = PlatformIO.getURLforPath(
+ path,
+ linkValidityDuration.current
+ );
+ forceUpdate();
+ props.switchCurrentLocationType(currentLocationId);
+ });
+ } else {
signedLink.current = PlatformIO.getURLforPath(
path,
linkValidityDuration.current
);
forceUpdate();
- props.switchCurrentLocationType(currentLocationId);
- });
+ }
}
return (
@@ -129,7 +140,9 @@ function LinkGeneratorDialog(props: Props) {
navigator.clipboard
.writeText(signedLink.current)
.then(() => {
- showNotification(i18n.t('core:linkCopied'));
+ dispatch(
+ actions.showNotification(i18n.t('core:linkCopied'))
+ );
});
}}
color="primary"
diff --git a/app/components/dialogs/settings/SettingsDialog.tsx b/app/components/dialogs/settings/SettingsDialog.tsx
index b969b1c38..8f99cfc22 100644
--- a/app/components/dialogs/settings/SettingsDialog.tsx
+++ b/app/components/dialogs/settings/SettingsDialog.tsx
@@ -151,7 +151,8 @@ function SettingsDialog(props: Props) {
const renderActions = () => (
<DialogActions
style={{
- justifyContent: 'space-between'
+ justifyContent: 'space-between',
+ padding: fullScreen ? '10px 30px 30px 30px' : undefined
}}
>
<Button
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index 8cce0fd0a..03c4437b3 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -19,6 +19,7 @@
import React from 'react';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
+import ShareIcon from '@mui/icons-material/Share';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import Divider from '@mui/material/Divider';
@@ -79,6 +80,7 @@ interface Props {
openDeleteFileDialog: () => void;
openRenameFileDialog: () => void;
openMoveCopyFilesDialog: () => void;
+ openShareFilesDialog?: () => void;
openAddRemoveTagsDialog: () => void;
openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
loadDirectoryContent: (
@@ -159,6 +161,11 @@ function FileMenu(props: Props) {
props.openMoveCopyFilesDialog();
}
+ function showShareFilesDialog() {
+ onClose();
+ props.openShareFilesDialog();
+ }
+
function setFolderThumbnail() {
onClose();
setFolderThumbnailPromise(props.selectedFilePath)
@@ -463,6 +470,20 @@ function FileMenu(props: Props) {
);
}
+ if (Pro && props.openShareFilesDialog) {
+ menuItems.push(
+ <MenuItem
+ key="fileMenuShareFile"
+ data-tid="fileMenuMoveCopyFile"
+ onClick={showShareFilesDialog}
+ >
+ <ListItemIcon>
+ <ShareIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:shareFiles')} />
+ </MenuItem>
+ );
+ }
menuItems.push(
<MenuItem
key="fileMenuMoveCopyFile"
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 0483dc00f..69a801e6b 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -792,5 +792,14 @@
"confirmtsLastOpenedFoldersHistoryDeletion": "Are you sure you want to clear the list of your recently opened folders?",
"confirmtsLastOpenedFilesHistoryDeletion": "Are you sure you want to clear the list of your recently opened files?",
"searchHasTheWords": "Has the words",
+ "saveAsHtml": "Save as HTML",
+ "linkValidityDuration": "Download links are valid until {{linkValidityDistance}}",
+ "shareFiles": "Share Files",
+ "shareFile": "Share File",
+ "saveShare": "Save & Share",
+ "downloadSharedFile": "Download {{fileName}}",
+ "copyToClipboard": "Copy to clipboard",
+ "generatedHTMLCopied": "Download links copied to clipboard",
+ "generatedHTMLFailed": "Error while copying to clipboard",
"-": "-"
}
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index b3a998f67..d9dd2a28c 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -146,6 +146,8 @@ function GridPerspective(props: Props) {
props.directoryMeta.perspectiveSettings[PerspectiveIDs.GRID];
const settings = getSettings(props.directoryMeta);
+ const ShareFilesDialog = Pro && Pro.UI ? Pro.UI.ShareFilesDialog : false;
+
const [mouseX, setMouseX] = useState<number>(undefined);
const [mouseY, setMouseY] = useState<number>(undefined);
// const selectedEntry = useRef<FileSystemEntry>(undefined);
@@ -236,6 +238,9 @@ function GridPerspective(props: Props) {
isMoveCopyFilesDialogOpened,
setIsMoveCopyFilesDialogOpened
] = useState<boolean>(false);
+ const [isShareFilesDialogOpened, setIsShareFilesDialogOpened] = useState<
+ boolean
+ >(false);
const [
isAddRemoveTagsDialogOpened,
setIsAddRemoveTagsDialogOpened
@@ -612,6 +617,10 @@ function GridPerspective(props: Props) {
setIsMoveCopyFilesDialogOpened(true);
};
+ const openShareFilesDialog = () => {
+ setIsShareFilesDialogOpened(true);
+ };
+
const openDeleteFileDialog = () => {
props.toggleDeleteMultipleEntriesDialog();
};
@@ -792,6 +801,9 @@ function GridPerspective(props: Props) {
handleExportCsvMenu={handleExportCsvMenu}
openSettings={openSettings}
directoryPath={currentDirectoryPath}
+ openShareFilesDialog={
+ PlatformIO.haveObjectStoreSupport() ? openShareFilesDialog : undefined
+ }
/>
<GlobalHotKeys
keyMap={keyMap}
@@ -911,6 +923,12 @@ function GridPerspective(props: Props) {
onClose={() => setIsMoveCopyFilesDialogOpened(false)}
/>
)}
+ {isShareFilesDialogOpened && (
+ <ShareFilesDialog
+ open={isShareFilesDialogOpened}
+ onClose={() => setIsShareFilesDialogOpened(false)}
+ />
+ )}
{Boolean(fileContextMenuAnchorEl) && (
<FileMenu
anchorEl={fileContextMenuAnchorEl}
@@ -921,6 +939,11 @@ function GridPerspective(props: Props) {
openDeleteFileDialog={openDeleteFileDialog}
openRenameFileDialog={props.openRenameEntryDialog}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
+ openShareFilesDialog={
+ PlatformIO.haveObjectStoreSupport()
+ ? openShareFilesDialog
+ : undefined
+ }
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
openFsEntry={props.openFsEntry}
openFileNatively={props.openFileNatively}
diff --git a/app/perspectives/grid-perspective/components/MainToolbar.tsx b/app/perspectives/grid-perspective/components/MainToolbar.tsx
index 155c2d332..7c980754e 100644
--- a/app/perspectives/grid-perspective/components/MainToolbar.tsx
+++ b/app/perspectives/grid-perspective/components/MainToolbar.tsx
@@ -22,6 +22,7 @@ import Tooltip from '-/components/Tooltip';
import IconButton from '@mui/material/IconButton';
import SortingIcon from '@mui/icons-material/SwapVerticalCircle';
import TagIcon from '@mui/icons-material/LocalOffer';
+import ShareIcon from '@mui/icons-material/Share';
import { SelectedIcon, UnSelectedIcon } from '-/components/CommonIcons';
import CopyIcon from '@mui/icons-material/FileCopy';
import DeleteIcon from '@mui/icons-material/Delete';
@@ -66,6 +67,7 @@ interface Props {
searchQuery: TS.SearchQuery;
setSearchQuery: (searchQuery: TS.SearchQuery) => void;
openCurrentDirectory: () => void;
+ openShareFilesDialog?: () => void;
directoryPath: string;
keyBindings: Array<any>;
}
@@ -87,7 +89,8 @@ function MainToolbar(props: Props) {
fileOperationsEnabled,
handleSortingMenu,
openSettings,
- keyBindings
+ keyBindings,
+ openShareFilesDialog
} = props;
function showProperties() {
@@ -223,6 +226,21 @@ function MainToolbar(props: Props) {
</span>
</Tooltip>
)}
+ {openShareFilesDialog && (
+ <Tooltip title={i18n.t('core:shareFileDialog')}>
+ <span>
+ <IconButton
+ aria-label={i18n.t('core:shareFileDialog')}
+ data-tid={prefixDataTID + 'PerspectiveShareFiles'}
+ onClick={openShareFilesDialog}
+ disabled={selectedEntries.length < 1}
+ size="large"
+ >
+ <ShareIcon />
+ </IconButton>
+ </span>
+ </Tooltip>
+ )}
<Tooltip title={i18n.t('core:sort')}>
<IconButton
// title={i18n.t('core:sort')}