Skip to content

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

add getUuid

sytolkb9ef3613ef8a
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsx
index 4036cbb03..f10ac5296 100644
--- a/app/components/EntryProperties.tsx
+++ b/app/components/EntryProperties.tsx
@@ -19,7 +19,6 @@
import React, { ChangeEvent, useEffect, useRef, useState } from 'react';
import { useStateWithCallbackLazy } from 'use-state-with-callback';
import { getBgndFileLocationForDirectory } from '@tagspaces/tagspaces-common/paths';
-import { v1 as uuidv1 } from 'uuid';
import L from 'leaflet';
import { Theme } from '@mui/material/styles';
import withStyles from '@mui/styles/withStyles';
@@ -66,7 +65,8 @@ import {
convertMarkDown,
fileNameValidation,
dirNameValidation,
- normalizeUrl
+ normalizeUrl,
+ getUuid
} from '-/services/utils-io';
import { parseGeoLocation } from '-/utils/geo';
import { Pro } from '../pro';
@@ -1296,7 +1296,7 @@ function EntryProperties(props: Props) {
)}
{isMoveCopyFilesDialogOpened && (
<MoveCopyFilesDialog
- key={uuidv1()}
+ key={getUuid()}
open={isMoveCopyFilesDialogOpened}
onClose={toggleMoveCopyFilesDialog}
selectedFiles={[currentEntry.path]}
diff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsx
index 3709370a0..4df3f2392 100644
--- a/app/components/MobileNavigation.tsx
+++ b/app/components/MobileNavigation.tsx
@@ -17,7 +17,6 @@
*/
import React, { useState } from 'react';
-import { v1 as uuidv1 } from 'uuid';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import classNames from 'classnames';
@@ -65,6 +64,7 @@ import {
import Links from '-/links';
import StoredSearches from '-/components/StoredSearches';
import UserDetailsPopover from '-/components/UserDetailsPopover';
+import { getUuid } from '-/services/utils-io';
const styles: any = (theme: any) => ({
selectedButton: {
@@ -360,7 +360,7 @@ function MobileNavigation(props: Props) {
open={isProTeaserVisible}
onClose={toggleProTeaser}
openURLExternally={openURLExternally}
- key={uuidv1()} // TODO rethink to remove this
+ key={getUuid()} // TODO rethink to remove this
/>
)}
</Box>
diff --git a/app/components/TagsSelect.tsx b/app/components/TagsSelect.tsx
index 141fac198..f1c868c79 100644
--- a/app/components/TagsSelect.tsx
+++ b/app/components/TagsSelect.tsx
@@ -17,7 +17,6 @@
*/
import React, { useState } from 'react';
-import { v1 as uuidv1 } from 'uuid';
import { useSelector } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import TextField from '@mui/material/TextField';
@@ -27,6 +26,7 @@ import { getTagColor, getTagTextColor } from '-/reducers/settings';
import EntryTagMenu from '-/components/menus/EntryTagMenu';
import { TS } from '-/tagspaces.namespace';
import TagContainer from '-/components/TagContainer';
+import { getUuid } from '-/services/utils-io';
const styles: any = (theme: any) => ({
root: {
@@ -125,7 +125,7 @@ function TagsSelect(props: Props) {
const newTags = [];
tags.map(tag => {
const newTag: TS.Tag = {
- id: uuidv1(),
+ id: getUuid(),
title: '' + tag,
color: defaultBackgroundColor,
textcolor: defaultTextColor
diff --git a/app/components/dialogs/CreateEditLocationDialog.tsx b/app/components/dialogs/CreateEditLocationDialog.tsx
index a13e4af26..3b1923e0e 100644
--- a/app/components/dialogs/CreateEditLocationDialog.tsx
+++ b/app/components/dialogs/CreateEditLocationDialog.tsx
@@ -18,7 +18,6 @@
import React, { ChangeEvent, useEffect, useState } from 'react';
import Button from '@mui/material/Button';
-import { v1 as uuidv1 } from 'uuid';
import withStyles from '@mui/styles/withStyles';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
@@ -70,6 +69,7 @@ import PlatformIO from '-/services/platform-facade';
import WebdavForm from '-/components/dialogs/WebdavForm';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
+import { getUuid } from '-/services/utils-io';
const styles: any = theme => ({
formControl: {
@@ -176,7 +176,7 @@ function CreateEditLocationDialog(props: Props) {
}
const [type, setType] = useState<string>(defaultType);
const [newuuid, setNewUuid] = useState<string>(
- location ? location.uuid : uuidv1()
+ location ? location.uuid : getUuid()
);
const [cloudErrorTextName, setCloudErrorTextName] = useState<boolean>(false);
const [webdavErrorUrl, setWebdavErrorUrl] = useState<boolean>(false);
diff --git a/app/components/dialogs/CreateTagGroupDialog.tsx b/app/components/dialogs/CreateTagGroupDialog.tsx
index e4e7a3396..7425a18fb 100644
--- a/app/components/dialogs/CreateTagGroupDialog.tsx
+++ b/app/components/dialogs/CreateTagGroupDialog.tsx
@@ -17,7 +17,6 @@
*/
import React, { ChangeEvent, useReducer, useRef, useState } from 'react';
-import { v1 as uuidv1 } from 'uuid';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import DialogActions from '@mui/material/DialogActions';
@@ -38,6 +37,7 @@ import { getCurrentLocationId } from '-/reducers/app';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
+import { getUuid } from '-/services/utils-io';
interface Props {
open: boolean;
@@ -109,7 +109,7 @@ function CreateTagGroupDialog(props: Props) {
if (!disableConfirmButton.current) {
createTagGroup({
- uuid: uuidv1(),
+ uuid: getUuid(),
title: title.current,
color: color.current,
textcolor: textcolor.current,
diff --git a/app/components/dialogs/settings/SettingsDialog.tsx b/app/components/dialogs/settings/SettingsDialog.tsx
index 65e371206..bff0d8706 100644
--- a/app/components/dialogs/settings/SettingsDialog.tsx
+++ b/app/components/dialogs/settings/SettingsDialog.tsx
@@ -29,7 +29,6 @@ import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
-import { v1 as uuidv1 } from 'uuid';
import { useStateWithCallbackLazy } from 'use-state-with-callback';
import { extend } from '@tagspaces/tagspaces-platforms/misc';
import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
@@ -46,6 +45,7 @@ import {
import { clearAllURLParams } from '-/utils/dom';
import SettingsAdvanced from '-/components/dialogs/settings/SettingsAdvanced';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
+import { getUuid } from '-/services/utils-io';
const styles: any = () => ({
mainContent: {
@@ -81,7 +81,7 @@ function SettingsDialog(props: Props) {
const initSupportedFileTypes = props.supportedFileTypes.reduce(
(accumulator, fileType) => {
const modifiedFileType = extend({}, fileType, {
- id: fileType.id || uuidv1()
+ id: fileType.id || getUuid()
});
if (fileType.viewer !== '') {
accumulator.push(modifiedFileType);
@@ -142,7 +142,7 @@ function SettingsDialog(props: Props) {
};
const defaultFileTypeObject = {
- id: uuidv1(),
+ id: getUuid(),
type: '',
viewer: '',
editor: '',
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 4a71d123d..f69128b15 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -16,7 +16,6 @@
*
*/
-import { v1 as uuidv1 } from 'uuid';
import {
formatDateTime4Tag,
locationType
@@ -53,7 +52,8 @@ import {
getPrevFile,
loadJSONFile,
merge,
- setLocationType
+ setLocationType,
+ getUuid
} from '-/services/utils-io';
import i18n from '../services/i18n';
import { Pro } from '../pro';
@@ -2123,7 +2123,7 @@ export const actions = {
dispatch: (action) => void
) => {
const newEntry = {
- uuid: uuidv1(),
+ uuid: getUuid(),
name: isFile
? extractFileName(path, PlatformIO.getDirSeparator())
: extractDirectoryName(path, PlatformIO.getDirSeparator()),
diff --git a/app/reducers/locations.ts b/app/reducers/locations.ts
index 25e4db9bc..078225cc2 100644
--- a/app/reducers/locations.ts
+++ b/app/reducers/locations.ts
@@ -16,7 +16,6 @@
*
*/
-import { v1 as uuidv1 } from 'uuid';
import {
immutablySwapItems,
locationType
@@ -25,6 +24,7 @@ import { actions as AppActions } from '-/reducers/app';
import i18n from '-/services/i18n';
import PlatformIO from '-/services/platform-facade';
import { TS } from '-/tagspaces.namespace';
+import { getUuid } from '-/services/utils-io';
export const types = {
ADD_LOCATION: 'APP/ADD_LOCATION',
@@ -50,7 +50,7 @@ export default (state: Array<TS.Location> = initialState, action: any) => {
...state,
{
...action.location,
- uuid: action.location.uuid || uuidv1(),
+ uuid: action.location.uuid || getUuid(),
creationDate: new Date().toJSON()
}
];
@@ -155,7 +155,7 @@ export const actions = {
dispatch(
actions.addLocation(
{
- uuid: uuidv1(),
+ uuid: getUuid(),
type: locationType.TYPE_LOCAL,
name: i18n.t(key),
path: devicePaths[key],
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index a46b46558..9228638ed 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -17,7 +17,6 @@
*/
import semver from 'semver';
-import { v1 as uuidv1 } from 'uuid';
import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
import i18n from '-/services/i18n';
import defaultSettings from './settings-default';
@@ -27,6 +26,7 @@ import versionMeta from '-/version.json';
import { actions as AppActions } from './app';
import { TS } from '-/tagspaces.namespace';
import { Pro } from '../pro';
+import { getUuid } from '-/services/utils-io';
export const types = {
UPGRADE_SETTINGS: 'SETTINGS/UPGRADE_SETTINGS',
@@ -406,13 +406,13 @@ export default (state: any = defaultSettings, action: any) => {
let mapTileServers;
if (action.isDefault) {
mapTileServers = [
- { ...action.tileServer, uuid: uuidv1() },
+ { ...action.tileServer, uuid: getUuid() },
...state.mapTileServers
];
} else {
mapTileServers = [
...state.mapTileServers,
- { ...action.tileServer, uuid: uuidv1() }
+ { ...action.tileServer, uuid: getUuid() }
];
}
return {
diff --git a/app/reducers/taglibrary-default.ts b/app/reducers/taglibrary-default.ts
index 870b88ff7..6ddfdbbd1 100644
--- a/app/reducers/taglibrary-default.ts
+++ b/app/reducers/taglibrary-default.ts
@@ -16,7 +16,7 @@
*
*/
-import { v1 as uuidv1 } from 'uuid';
+import { getUuid } from '-/services/utils-io';
export default [
{
@@ -26,7 +26,7 @@ export default [
textcolor: '#ffffff',
children: [
{
- id: uuidv1(),
+ id: getUuid(),
title: 'done',
type: 'plain',
color: '#008000',
@@ -34,28 +34,28 @@ export default [
keyBinding: ''
},
{
- id: uuidv1(),
+ id: getUuid(),
title: 'next',
type: 'plain',
color: '#008000',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
title: 'maybe',
type: 'plain',
color: '#008000',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
title: 'waiting',
type: 'plain',
color: '#008000',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'todo',
color: '#008000',
@@ -70,21 +70,21 @@ export default [
textcolor: '#ffffff',
children: [
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'book',
color: '#008000',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'paper',
color: '#008000',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'article',
color: '#008000',
@@ -99,21 +99,21 @@ export default [
textcolor: '#ffffff',
children: [
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'high',
color: '#ff7537',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'medium',
color: '#ffad46',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: 'low',
color: '#7bd148',
@@ -128,35 +128,35 @@ export default [
textcolor: '#ffffff',
children: [
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: '1star',
color: '#ffcc24',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: '2star',
color: '#ffcc24',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: '3star',
color: '#ffcc24',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: '4star',
color: '#ffcc24',
textcolor: '#ffffff'
},
{
- id: uuidv1(),
+ id: getUuid(),
type: 'plain',
title: '5star',
color: '#ffcc24',
diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.ts
index 02b3980a7..212b8c521 100644
--- a/app/reducers/taglibrary.ts
+++ b/app/reducers/taglibrary.ts
@@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
-import { v1 as uuidv1 } from 'uuid';
import {
immutablySwapItems,
formatDateTime4Tag,
@@ -23,7 +22,7 @@ import {
prepareTagGroupForExport
} from '@tagspaces/tagspaces-platforms/misc';
import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
-import { parseNewTags, saveAsTextFile } from '-/services/utils-io';
+import { getUuid, parseNewTags, saveAsTextFile } from '-/services/utils-io';
import versionMeta from '../version.json';
import defaultTagLibrary from './taglibrary-default';
import { TS } from '-/tagspaces.namespace';
@@ -113,7 +112,7 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {
return [
...state,
{
- uuid: action.entry.uuid || uuidv1(),
+ uuid: action.entry.uuid || getUuid(),
title: action.entry.title,
color: action.entry.color,
textcolor: action.entry.textcolor,
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 2e74ba6d5..00058aa94 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -16,7 +16,7 @@
*
*/
-import { v1 as uuidv1 } from 'uuid';
+import { v1 as uuidv1, v4 as uuidv4 } from 'uuid';
import { marked } from 'marked';
import DOMPurify from 'dompurify';
import {
@@ -864,7 +864,7 @@ export function loadDirMetaDataPromise(
}
return {
...metaData,
- id: metaData.id || uuidv1(),
+ id: metaData.id || getUuid(),
isFile: false,
description: metaData.description || '',
color: metaData.color || '',
@@ -1047,7 +1047,7 @@ export async function saveMetaDataPromise(
if (!cleanedMetaData.id) {
// add id for directories
- cleanedMetaData.id = uuidv1();
+ cleanedMetaData.id = getUuid();
}
metaFilePath = getMetaFileLocationForDir(
@@ -1380,3 +1380,7 @@ export function setLocationType(location: TS.Location): Promise<boolean> {
}
return Promise.resolve(false);
}
+
+export function getUuid(version = 1): string {
+ return version === 1 ? uuidv1() : uuidv4();
+}