From f6d7377977950b21b2a44ef7161bd0768e8abf11 Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Fri, 16 Sep 2022 19:52:48 +0200 Subject: [PATCH] Remove duplicate IDs issue --- client/components/cards/attachments.js | 6 ++++-- models/lib/fileStoreStrategy.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index 0ac0b0f00..fb2306f05 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -1,3 +1,5 @@ +import { ObjectID } from 'bson'; + const filesize = require('filesize'); const prettyMilliseconds = require('pretty-ms'); @@ -46,7 +48,7 @@ Template.cardAttachmentsPopup.events({ if (files) { let uploads = []; for (const file of files) { - const fileId = Random.id(); + const fileId = new ObjectID().toString(); const config = { file: file, fileId: fileId, @@ -130,7 +132,7 @@ Template.previewClipboardImagePopup.events({ if (pastedResults && pastedResults.file) { const file = pastedResults.file; window.oPasted = pastedResults; - const fileId = Random.id(); + const fileId = new ObjectID().toString(); const config = { file, fileId: fileId, diff --git a/models/lib/fileStoreStrategy.js b/models/lib/fileStoreStrategy.js index 94d94de03..d7f6f6ebb 100644 --- a/models/lib/fileStoreStrategy.js +++ b/models/lib/fileStoreStrategy.js @@ -2,6 +2,7 @@ import fs from 'fs'; import path from 'path'; import { createObjectId } from './grid/createObjectId'; import { httpStreamOutput } from './httpStream.js' +import { ObjectID } from 'bson'; export const STORAGE_NAME_FILESYSTEM = "fs"; export const STORAGE_NAME_GRIDFS = "gridfs"; @@ -371,7 +372,7 @@ export const copyFile = function(fileObj, newCardId, fileStoreStrategyFactory) { // https://forums.meteor.com/t/meteor-code-must-always-run-within-a-fiber-try-wrapping-callbacks-that-you-pass-to-non-meteor-libraries-with-meteor-bindenvironmen/40099/8 readStream.on('end', Meteor.bindEnvironment(() => { - const fileId = Random.id(); + const fileId = new ObjectID().toString(); Attachments.addFile( tempPath, {