TagSpaces is an offline, open source, document manager with tagging support
feature: finalizing the generation of the links for sharing functionality
Ilian Sapundshievd5b7990adfa5
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex bd2277df4..6f60169c4 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -66,7 +66,8 @@ import {getThumbFileLocationForFile,getThumbFileLocationForDirectory,extractFileName,- extractDirectoryName+ extractDirectoryName,+ generateSharingLink} from '-/utils/paths';import AppConfig from '../config';import { Pro } from '../pro';@@ -144,11 +145,7 @@ const styles: any = (theme: any) => ({button: {position: 'relative',padding: '8px 12px 6px 8px',- margin: '0 10px 0 0',- cursor: 'pointer'- },- buttonIcon: {- cursor: 'pointer'+ margin: '0'},fluidGrid: {width: '100%',@@ -592,12 +589,20 @@ const EntryProperties = (props: Props) => {const geoLocation: any = getGeoLocation(currentEntry.tags);- let sharingLink = window.location.href;- if (sharingLink.indexOf('?') > 0) {- const sharingURL = new URL(sharingLink);+ let sharingLink = '';+ if (window.location.href.indexOf('?') > 0) {+ const sharingURL = new URL(window.location.href);const params = new URLSearchParams(sharingURL.search);- params.delete('tsdpath');- sharingLink = 'ts:?' + params;+ if (params.has('tslid')) {+ const locationId = params.get('tslid');+ if (currentEntry.isFile && params.has('tsepath')) {+ const entryPath = params.get('tsepath');+ sharingLink = generateSharingLink(locationId, entryPath);+ } else if (currentEntry.isFile && params.has('tsepath')) {+ const dirPath = params.get('tsdpath');+ sharingLink = generateSharingLink(locationId, undefined, dirPath);+ }+ }}const isCloudLocation = currentEntry.url && currentEntry.url.length > 5;diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex e02bad5e1..8dc37d00b 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -36,6 +36,7 @@ import MapiquePerspectiveIcon from '@material-ui/icons/Map';import KanBanPerspectiveIcon from '@material-ui/icons/Dashboard';import NewFileIcon from '@material-ui/icons/InsertDriveFile';import NewFolderIcon from '@material-ui/icons/CreateNewFolder';+import ShareIcon from '@material-ui/icons/Link';import RenameFolderIcon from '@material-ui/icons/FormatTextdirectionLToR';import DeleteForeverIcon from '@material-ui/icons/DeleteForever';import SettingsIcon from '@material-ui/icons/Settings';@@ -50,7 +51,8 @@ import {extractContainingDirectoryPath,extractDirectoryName,getThumbFileLocationForDirectory,- normalizePath+ normalizePath,+ generateSharingLink} from '-/utils/paths';import PlatformIO from '-/services/platform-io';import { formatDateTime4Tag } from '-/utils/misc';@@ -92,8 +94,8 @@ interface Props {perspectiveMode?: boolean;showNotification?: (text: string,- notificationType: string,- autohide: boolean+ notificationType?: string,+ autohide?: boolean) => void;isReadOnlyMode?: boolean;toggleUploadDialog: () => void;@@ -111,28 +113,74 @@ interface Props {mouseX?: number;mouseY?: number;openURLExternally?: (url: string, skipConfirmation: boolean) => void;+ currentLocation?: TS.Location;+ locations?: Array<TS.Location>;}const DirectoryMenu = (props: Props) => {const fileUploadContainerRef = useRef<FileUploadContainerRef>(null);+ const {+ selectedEntries,+ isReadOnlyMode,+ currentLocation,+ locations,+ showNotification,+ onClose+ } = props;++ function copySharingLink() {+ onClose();+ if (selectedEntries.length === 1) {+ const entryFromIndex = selectedEntries[0].locationID;+ const locationID = entryFromIndex+ ? selectedEntries[0].locationID+ : currentLocation.uuid;+ let relativePath = selectedEntries[0].path;+ const tmpLoc = locations.find(location => location.uuid === locationID);+ const locationPath = tmpLoc.path;+ if (+ locationPath &&+ relativePath &&+ relativePath.startsWith(locationPath)+ ) {+ // remove location path from entry path if possible+ relativePath = relativePath.substr(locationPath.length);+ }+ const sharingLink = generateSharingLink(+ locationID,+ undefined,+ relativePath+ );+ navigator.clipboard+ .writeText(sharingLink)+ .then(() => {+ showNotification(i18n.t('core:sharingLinkCopied'));+ return true;+ })+ .catch(() => {+ showNotification(i18n.t('core:sharingLinkFailed'));+ });+ }+ }+const [isCreateDirectoryDialogOpened,setIsCreateDirectoryDialogOpened] = useState(false);function reloadDirectory() {- props.onClose();+ onClose();props.loadDirectoryContent(props.directoryPath, true);}function openDirectory() {- props.onClose();+ onClose();props.loadDirectoryContent(props.directoryPath, true);}function showProperties() {- props.onClose();+ onClose();getAllPropertiesPromise(props.directoryPath).then((fsEntry: TS.FileSystemEntry) => {props.openFsEntry(fsEntry);@@ -149,7 +197,7 @@ const DirectoryMenu = (props: Props) => {}function switchPerspective(perspectiveId) {- props.onClose();+ onClose();if (Pro) {if (props.switchPerspective) {props.switchPerspective(perspectiveId);@@ -190,7 +238,7 @@ const DirectoryMenu = (props: Props) => {}function showDeleteDirectoryDialog() {- props.onClose();+ onClose();props.setSelectedEntries([{ isFile: false, name: props.directoryPath, path: props.directoryPath }]);@@ -198,32 +246,32 @@ const DirectoryMenu = (props: Props) => {}function showRenameDirectoryDialog() {- props.onClose();+ onClose();props.openRenameDirectoryDialog();}function showCreateDirectoryDialog() {- props.onClose();+ onClose();setIsCreateDirectoryDialogOpened(true);}function createNewFile() {- props.onClose();+ onClose();props.toggleCreateFileDialog();}function showInFileManager() {- props.onClose();+ onClose();props.openDirectory(props.directoryPath);}function addExistingFile() {- props.onClose();+ onClose();fileUploadContainerRef.current.onFileUpload();}function importMacTags() {- props.onClose();+ onClose();if (Pro && Pro.MacTagsImport && Pro.MacTagsImport.importTags) {if (!confirm(`Experimental feature\n@@ -331,7 +379,7 @@ Do you want to continue?`)// }function cameraTakePicture() {- props.onClose();+ onClose();// @ts-ignorenavigator.camera.getPicture(onCameraSuccess, onFail, {// quality: 50,@@ -344,7 +392,7 @@ Do you want to continue?`)}function setFolderThumbnail() {- props.onClose();+ onClose();const parentDirectoryPath = extractContainingDirectoryPath(props.directoryPath,PlatformIO.getDirSeparator()@@ -385,7 +433,7 @@ Do you want to continue?`)const menuItems = [];- if (props.selectedEntries.length < 2) {+ if (selectedEntries.length < 2) {if (props.perspectiveMode) {menuItems.push(<MenuItem@@ -413,7 +461,7 @@ Do you want to continue?`)</MenuItem>);}- if (!props.isReadOnlyMode) {+ if (!isReadOnlyMode) {menuItems.push(<MenuItemkey="renameDirectory"@@ -429,7 +477,7 @@ Do you want to continue?`)}}- if (!props.isReadOnlyMode) {+ if (!isReadOnlyMode) {menuItems.push(<MenuItemkey="deleteDirectory"@@ -445,7 +493,7 @@ Do you want to continue?`)}if (- props.selectedEntries.length < 2 &&+ selectedEntries.length < 2 &&!(PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb)) {menuItems.push(@@ -464,7 +512,7 @@ Do you want to continue?`)if (!props.perspectiveMode) {menuItems.push(<Divider key="divider1" />);}- if (!props.isReadOnlyMode && !props.perspectiveMode) {+ if (!isReadOnlyMode && !props.perspectiveMode) {menuItems.push(<MenuItemkey="newSubDirectory"@@ -502,7 +550,7 @@ Do you want to continue?`)</MenuItem>);}- if (Pro && props.perspectiveMode && props.selectedEntries.length < 2) {+ if (Pro && props.perspectiveMode && selectedEntries.length < 2) {menuItems.push(<MenuItemkey="setAsThumb"@@ -516,8 +564,22 @@ Do you want to continue?`)</MenuItem>);}+ if (selectedEntries.length === 1) {+ menuItems.push(+ <MenuItem+ key="copySharingLink"+ data-tid="copyDirectorySharingLink"+ onClick={copySharingLink}+ >+ <ListItemIcon>+ <ShareIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:copySharingLink')} />+ </MenuItem>+ );+ }- if (props.selectedEntries.length < 2 && process.platform === 'darwin') {+ if (selectedEntries.length < 2 && process.platform === 'darwin') {menuItems.push(<MenuItemkey="importMacTags"@@ -634,7 +696,7 @@ Do you want to continue?`));}- if (props.selectedEntries.length < 2) {+ if (selectedEntries.length < 2) {menuItems.push(<Divider key="divider3" />);menuItems.push(<MenuItemdiff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsxindex b5c0271e9..a92d1ff4c 100644--- a/app/components/menus/FileMenu.tsx+++ b/app/components/menus/FileMenu.tsx@@ -30,6 +30,7 @@ import AddRemoveTags from '@material-ui/icons/Loyalty';import MoveCopy from '@material-ui/icons/FileCopy';import DuplicateFile from '@material-ui/icons/PostAdd';import ImageIcon from '@material-ui/icons/Image';+import ShareIcon from '@material-ui/icons/Link';import RenameFile from '@material-ui/icons/FormatTextdirectionLToR';import DeleteForever from '@material-ui/icons/DeleteForever';import i18n from '-/services/i18n';@@ -45,7 +46,8 @@ import {extractContainingDirectoryPath,extractFileName,extractParentDirectoryPath,- extractTags+ extractTags,+ generateSharingLink} from '-/utils/paths';import { TS } from '-/tagspaces.namespace';import { formatDateTime4Tag } from '-/utils/misc';@@ -73,47 +75,76 @@ interface Props {selectedFilePath?: string;isReadOnlyMode: boolean;selectedEntries: Array<any>;+ currentLocation: TS.Location;+ locations: Array<TS.Location>;}const FileMenu = (props: Props) => {+ const {+ selectedEntries,+ isReadOnlyMode,+ currentLocation,+ onClose,+ selectedFilePath,+ showNotification,+ locations+ } = props;++ function copySharingLink() {+ onClose();+ if (selectedEntries.length === 1) {+ const entryFromIndex = selectedEntries[0].locationID;+ const locationID = entryFromIndex+ ? selectedEntries[0].locationID+ : currentLocation.uuid;+ let relativePath = selectedEntries[0].path;+ const tmpLoc = locations.find(location => location.uuid === locationID);+ const locationPath = tmpLoc.path;+ if (+ locationPath &&+ relativePath &&+ relativePath.startsWith(locationPath)+ ) {+ // remove location path from entry path if possible+ relativePath = relativePath.substr(locationPath.length);+ }+ const sharingLink = generateSharingLink(locationID, relativePath);+ navigator.clipboard+ .writeText(sharingLink)+ .then(() => {+ showNotification(i18n.t('core:sharingLinkCopied'));+ return true;+ })+ .catch(() => {+ showNotification(i18n.t('core:sharingLinkFailed'));+ });+ }+ }+function showDeleteFileDialog() {- props.onClose();+ onClose();props.openDeleteFileDialog();}function showRenameFileDialog() {- props.onClose();+ onClose();props.openRenameFileDialog();}function showMoveCopyFilesDialog() {- props.onClose();+ onClose();props.openMoveCopyFilesDialog();}function setFolderThumbnail() {- props.onClose();+ onClose();setFolderThumbnailPromise(props.selectedFilePath)- .then(- (directoryPath: string) => {- props.showNotification('Thumbnail created for: ' + directoryPath);- return true;- }-- // getAllPropertiesPromise(directoryPath)- // .then((fsEntry: FileSystemEntry) => {- // props.openFsEntry(fsEntry);- // return true;- // })- // .catch(error =>- // console.warn(- // 'Error getAllPropertiesPromise for: ' + directoryPath,- // error- // )- // )- )+ .then((directoryPath: string) => {+ showNotification('Thumbnail created for: ' + directoryPath);+ return true;+ }).catch(error => {- props.showNotification('Thumbnail creation failed.');+ showNotification('Thumbnail creation failed.');console.warn('Error setting Thumb for entry: ' + props.selectedFilePath,error@@ -123,32 +154,32 @@ const FileMenu = (props: Props) => {}function showAddRemoveTagsDialog() {- props.onClose();+ onClose();props.openAddRemoveTagsDialog();}function showInFileManager() {- props.onClose();+ onClose();if (props.selectedFilePath) {props.showInFileManager(props.selectedFilePath);}}function duplicateFile() {- props.onClose();- if (props.selectedFilePath) {+ onClose();+ if (selectedFilePath) {const dirPath = extractContainingDirectoryPath(- props.selectedFilePath,+ selectedFilePath,PlatformIO.getDirSeparator());const fileName = extractFileName(- props.selectedFilePath,+ selectedFilePath,PlatformIO.getDirSeparator());const extractedTags = extractTags(- props.selectedFilePath,+ selectedFilePath,AppConfig.tagDelimiter,PlatformIO.getDirSeparator());@@ -159,29 +190,29 @@ const FileMenu = (props: Props) => {(dirPath ? dirPath + PlatformIO.getDirSeparator() : '') +generateFileName(fileName, extractedTags, AppConfig.tagDelimiter);- PlatformIO.copyFilePromise(props.selectedFilePath, newFilePath)+ PlatformIO.copyFilePromise(selectedFilePath, newFilePath).then(() => {props.loadDirectoryContent(dirPath, true);return true;}).catch(error => {- props.showNotification('Error creating duplicate: ' + error.message);+ showNotification('Error creating duplicate: ' + error.message);});}}function openFileNatively() {- props.onClose();+ onClose();if (props.selectedFilePath) {props.openFileNatively(props.selectedFilePath);}}function openParentFolderInternally() {- props.onClose();- if (props.selectedFilePath) {+ onClose();+ if (selectedFilePath) {const parentFolder = extractParentDirectoryPath(- props.selectedFilePath,+ selectedFilePath,PlatformIO.getDirSeparator());props.loadDirectoryContent(parentFolder, false);@@ -189,9 +220,9 @@ const FileMenu = (props: Props) => {}function openFile() {- props.onClose();- if (props.selectedFilePath) {- getAllPropertiesPromise(props.selectedFilePath)+ onClose();+ if (selectedFilePath) {+ getAllPropertiesPromise(selectedFilePath).then((fsEntry: TS.FileSystemEntry) => {props.openFsEntry(fsEntry);return true;@@ -208,7 +239,7 @@ const FileMenu = (props: Props) => {}const menuItems = [];- if (props.selectedEntries.length < 2) {+ if (selectedEntries.length < 2) {menuItems.push(<MenuItemkey="fileMenuOpenFile"@@ -236,7 +267,7 @@ const FileMenu = (props: Props) => {}if (!(PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb) &&- props.selectedEntries.length < 2+ selectedEntries.length < 2) {menuItems.push(<MenuItem@@ -265,7 +296,7 @@ const FileMenu = (props: Props) => {menuItems.push(<Divider key="fmDivider" />);}- if (!props.isReadOnlyMode) {+ if (!isReadOnlyMode) {menuItems.push(<MenuItemkey="fileMenuAddRemoveTags"@@ -314,7 +345,7 @@ const FileMenu = (props: Props) => {<ListItemText primary={i18n.t('core:moveCopyFile')} /></MenuItem>);- if (Pro && props.selectedEntries.length < 2) {+ if (Pro && selectedEntries.length < 2) {menuItems.push(<MenuItemkey="setAsThumbTID"@@ -328,6 +359,20 @@ const FileMenu = (props: Props) => {</MenuItem>);}+ if (selectedEntries.length === 1) {+ menuItems.push(+ <MenuItem+ key="copySharingLink"+ data-tid="copyFileSharingLink"+ onClick={copySharingLink}+ >+ <ListItemIcon>+ <ShareIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:copySharingLink')} />+ </MenuItem>+ );+ }menuItems.push(<MenuItemkey="fileMenuDeleteFile"diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex a16c014e9..3402ab539 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -621,5 +621,8 @@"warningOpeningFilesExternally": "Show warning on opening files externally","geoTaggingFormat": "Geo Tagging Format","searchDisabledWhileIndexing": "Search disabled while indexing",+ "copySharingLink": "Copy Sharing Link",+ "sharingLinkCopied": "Link for sharing copied to the clipboard",+ "sharingLinkFailed": "Copying the link to clipboard failed","-": "-"}diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex cc85e8fc2..545ec281f 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -59,7 +59,7 @@ import CellContent from './CellContent';import MainToolbar from './MainToolbar';import SortingMenu from './SortingMenu';import GridOptionsMenu from './GridOptionsMenu';-import { getLocation } from '-/reducers/locations';+import { getLocation, getLocations } from '-/reducers/locations';import PlatformIO from '-/services/platform-io';import { getLocationPath } from '-/utils/paths';import GridPagination from '-/perspectives/grid-perspective/components/GridPagination';@@ -103,6 +103,7 @@ interface Props {autohide: boolean) => void;currentLocation: TS.Location;+ locations: Array<TS.Location>;isDesktopMode: boolean;toggleDeleteMultipleEntriesDialog: () => void;}@@ -840,6 +841,8 @@ const GridPerspective = (props: Props) => {isReadOnlyMode={props.isReadOnlyMode}selectedFilePath={getSelEntryPath()}selectedEntries={props.selectedEntries}+ currentLocation={props.currentLocation}+ locations={props.locations}/>)}{/* {Boolean(dirContextMenuAnchorEl) && ( // todo move dialogs from DirectoryMenu */}@@ -856,6 +859,8 @@ const GridPerspective = (props: Props) => {openFsEntry={props.openFsEntry}isReadOnlyMode={props.isReadOnlyMode}perspectiveMode={getSelEntryPath() !== props.currentDirectoryPath}+ currentLocation={props.currentLocation}+ locations={props.locations}/>{/* {Boolean(tagContextMenuAnchorEl) && ( // TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}<EntryTagMenu@@ -929,6 +934,7 @@ function mapStateToProps(state) {selectedEntries: getSelectedEntries(state),keyBindings: getKeyBindingObject(state),currentLocation: getLocation(state, state.app.currentLocationId),+ locations: getLocations(state),isDesktopMode: isDesktopMode(state),isDeleteMultipleEntriesDialogOpened: isDeleteMultipleEntriesDialogOpened(statediff --git a/app/utils/paths.ts b/app/utils/paths.tsindex b147cc99e..01d60fa83 100644--- a/app/utils/paths.ts+++ b/app/utils/paths.ts@@ -465,3 +465,29 @@ export function joinPaths(...paths) {}return result;}++// Generates sharing links+// for files ts:?tslid=53ea7417-6267-4f7c-9c25-dc44aa41f6c8&tsepath=%2FSelect-Dion%5B20210901%5D.jpeg+// for folders ts:?tslid=53ea7417-6267-4f7c-9c25-dc44aa41f6c8&tsepath=%2FMath+export function generateSharingLink(+ locationID: string,+ entryPath?: string,+ directoryPath?: string,+ entryID?: string+) {+ const escapedEntryPath = entryPath && encodeURIComponent(entryPath);+ const escapedDirPath = directoryPath && encodeURIComponent(directoryPath);+ let tsepath = '';+ if (escapedEntryPath) {+ tsepath = '&tsepath=' + escapedEntryPath;+ }+ let tsdpath = '';+ if (escapedDirPath) {+ tsdpath = '&tsdpath=' + escapedDirPath;+ }+ let tseid = '';+ if (entryID) {+ tseid = '&tseid=' + entryID;+ }+ return 'ts:?tslid=' + locationID + tsepath + tsdpath + tseid;+}