TagSpaces is an offline, open source, document manager with tagging support
feat: making location export and import a lite feature
Ilian Sapundshievf59443df4f93
diff --git a/src/renderer/components/dialogs/ExportImportPanel.tsx b/src/renderer/components/dialogs/ExportImportPanel.tsxindex 9773c4d64..3ef148685 100644--- a/src/renderer/components/dialogs/ExportImportPanel.tsx+++ b/src/renderer/components/dialogs/ExportImportPanel.tsx@@ -49,6 +49,7 @@ import {validateTagGroups,} from '-/services/export-import-utils';import { prepareTagGroupsForExport } from '-/services/taglibrary-utils';+import { prepareLocationForExport } from '-/services/locations-transfer';import { TS } from '-/tagspaces.namespace';import { CommonLocation } from '-/utils/CommonLocation';import Box from '@mui/material/Box';@@ -107,8 +108,8 @@ function ExportImportPanel(props: Props) {const { addLocations } = useCurrentLocationContext();const hasPro = Boolean(Pro && Pro.UI);- const sectionIsPro = (s: TransferSection) =>- s === 'locations' || s === 'searches';+ // Locations export/import is a free feature; only saved searches stay Pro.+ const sectionIsPro = (s: TransferSection) => s === 'searches';const sectionEnabled = (s: TransferSection) => !sectionIsPro(s) || hasPro;// Locations available for export (mirrors the former ExportLocationsDialog).@@ -352,9 +353,8 @@ function ExportImportPanel(props: Props) {}const ids = picked[s] || new Set<string>();if (s === 'locations') {- const prep = Pro?.UI?.prepareLocationForExport;const sel = editableLocations.filter((l) => ids.has(l.uuid));- return prep ? sel.map((l) => prep(l)) : undefined;+ return sel.map((l) => prepareLocationForExport(l));}if (s === 'tagGroups') {const sel = (tagGroups || []).filter((g) => ids.has(g.uuid));diff --git a/src/renderer/components/menus/LocationManagerMenu.tsx b/src/renderer/components/menus/LocationManagerMenu.tsxindex f059fec71..508a0ad50 100644--- a/src/renderer/components/menus/LocationManagerMenu.tsx+++ b/src/renderer/components/menus/LocationManagerMenu.tsx@@ -26,13 +26,11 @@ import {MoreMenuIcon,UpdateIndexIcon,} from '-/components/CommonIcons';-import { ProLabel } from '-/components/HelperComponents';import TsIconButton from '-/components/TsIconButton';import TsMenuList from '-/components/TsMenuList';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';import { Pro } from '-/pro';-import { isHideProFeatures } from '-/reducers/settings';import { openURLExternally } from '-/services/utils-io';import { TS } from '-/tagspaces.namespace';import { Divider } from '@mui/material';@@ -43,7 +41,6 @@ import MenuItem from '@mui/material/MenuItem';import Links from 'assets/links';import { useContext, useState } from 'react';import { useTranslation } from 'react-i18next';-import { useSelector } from 'react-redux';import SidePanelTitle from '../SidePanelTitle';interface Props {@@ -58,7 +55,6 @@ function LocationManagerMenu(props: Props) {const { createLocationsIndexes } = useLocationIndexContext();const { closeAllLocations } = useCurrentLocationContext();- const hideProFeatures: boolean = useSelector(isHideProFeatures);//const { openLinkDialog } = useLinkDialogContext();const [locationManagerMenuAnchorEl, setLocationManagerMenuAnchorEl] =useState<null | HTMLElement>(null);@@ -93,59 +89,39 @@ function LocationManagerMenu(props: Props) {menuItems.push(<Divider key={`divider-${menuItems.length}`} />);}- // Export/Import locations are Pro features. In the Lite build, hide them- // entirely when the user opted out of Pro teasers (isHideProFeatures);- // otherwise show them (functional on Pro, disabled with a PRO badge on Lite).- if (!hideProFeatures || Pro) {+ // Export/Import locations are free features available in every build.+ menuItems.push(+ <MenuItem+ key="locationManagerMenuExportLocationsTID"+ data-tid="locationManagerMenuExportLocationsTID"+ onClick={() => {+ setLocationManagerMenuAnchorEl(null);+ exportLocations();+ }}+ >+ <ListItemIcon>+ <ExportIcon />+ </ListItemIcon>+ <ListItemText primary={t('core:exportLocationTitle')} />+ </MenuItem>,+ );+ if (!AppConfig.ExtLocationsReadOnly) {menuItems.push(<MenuItem- disabled={!Pro}- key="locationManagerMenuExportLocationsTID"- data-tid="locationManagerMenuExportLocationsTID"+ key="locationManagerMenuImportLocations"+ data-tid="locationManagerMenuImportLocationsTID"onClick={() => {setLocationManagerMenuAnchorEl(null);- exportLocations();+ importLocations();}}><ListItemIcon>- <ExportIcon />+ <ImportIcon /></ListItemIcon>- <ListItemText- primary={- <>- {t('core:exportLocationTitle')}- <ProLabel />- </>- }- />+ <ListItemText primary={t('core:importLocationTitle')} /></MenuItem>,);- if (!AppConfig.ExtLocationsReadOnly) {- menuItems.push(- <MenuItem- disabled={!Pro}- key="locationManagerMenuImportLocations"- data-tid="locationManagerMenuImportLocationsTID"- onClick={() => {- setLocationManagerMenuAnchorEl(null);- importLocations();- }}- >- <ListItemIcon>- <ImportIcon />- </ListItemIcon>- <ListItemText- primary={- <>- {t('core:importLocationTitle')}- <ProLabel />- </>- }- />- </MenuItem>,- );- menuItems.push(<Divider key={`divider-${menuItems.length}`} />);- }+ menuItems.push(<Divider key={`divider-${menuItems.length}`} />);}menuItems.push(diff --git a/src/renderer/services/locations-transfer.ts b/src/renderer/services/locations-transfer.tsnew file mode 100644index 000000000..af021529b--- /dev/null+++ b/src/renderer/services/locations-transfer.ts@@ -0,0 +1,98 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces GmbH+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import { TS } from '-/tagspaces.namespace';++/**+ * Sanitizes a location into the plain shape that is written to an+ * export/backup file. Only known, serializable properties are copied over so+ * that transient/runtime fields never leak into the exported data.+ */+export function prepareLocationForExport(+ location: TS.S3Location,+): TS.S3Location {+ const preparedLocation: TS.S3Location = {+ isDefault: location.isDefault,+ name: location.name,+ uuid: location.uuid,+ type: location.type,+ };+ if (location.endpointURL) {+ preparedLocation.endpointURL = location.endpointURL;+ }+ if (location.accessKeyId) {+ preparedLocation.accessKeyId = location.accessKeyId;+ }+ if (location.secretAccessKey) {+ preparedLocation.secretAccessKey = location.secretAccessKey;+ }+ if (location.bucketName) {+ preparedLocation.bucketName = location.bucketName;+ }+ if (location.region) {+ preparedLocation.region = location.region;+ }+ if (location.hasOwnProperty('isDefault')) {+ preparedLocation.isDefault = location.isDefault;+ }+ if (location.hasOwnProperty('isReadOnly')) {+ preparedLocation.isReadOnly = location.isReadOnly;+ }+ if (location.hasOwnProperty('disableIndexing')) {+ preparedLocation.disableIndexing = location.disableIndexing;+ }+ if (location.hasOwnProperty('fullTextIndex')) {+ preparedLocation.fullTextIndex = location.fullTextIndex;+ }+ if (location.hasOwnProperty('watchForChanges')) {+ preparedLocation.watchForChanges = location.watchForChanges;+ }+ if (location.hasOwnProperty('isNotEditable')) {+ preparedLocation.isNotEditable = location.isNotEditable;+ }+ if (location.hasOwnProperty('reloadOnFocus')) {+ preparedLocation.reloadOnFocus = location.reloadOnFocus;+ }+ if (location.hasOwnProperty('disableThumbnailGeneration')) {+ preparedLocation.disableThumbnailGeneration =+ location.disableThumbnailGeneration;+ }+ if (location.hasOwnProperty('persistTagsInSidecarFile')) {+ preparedLocation.persistTagsInSidecarFile =+ location.persistTagsInSidecarFile;+ }+ if (location.creationDate) {+ preparedLocation.creationDate = location.creationDate;+ }+ if (location.ignorePatternPaths) {+ preparedLocation.ignorePatternPaths = location.ignorePatternPaths;+ }+ if (location.path) {+ preparedLocation.path = location.path;+ }+ if (location.maxIndexAge) {+ preparedLocation.maxIndexAge = location.maxIndexAge;+ }+ if (location.autoOpenedFilename) {+ preparedLocation.autoOpenedFilename = location.autoOpenedFilename;+ }+ if (location.maxLoops) {+ preparedLocation.maxLoops = location.maxLoops;+ }+ return preparedLocation;+}