From a7d51cf21b663d87f83e2585502ed9323b3d3788 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 21 Oct 2020 12:39:49 -0500 Subject: [PATCH] use tempdirs --- models/attachments.js | 3 +++ models/avatars.js | 3 +++ server/migrations.js | 29 ++++++++++++++++------------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/models/attachments.js b/models/attachments.js index 614dd3332..773bb4a43 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -5,6 +5,8 @@ import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload'; import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload'; import { createOnAfterRemove } from './lib/fsHooks/createOnAfterRemove'; +const os = require('os'); + let attachmentBucket; if (Meteor.isServer) { attachmentBucket = createBucket('attachments'); @@ -31,6 +33,7 @@ const insertActivity = (fileObj, activityType) => Attachments = new FilesCollection({ debug: false, // Change to `true` for debugging collectionName: 'attachments', + storagePath: os.tmpdir(), allowClientCode: true, onAfterUpload: function onAfterUpload(fileRef) { createOnAfterUpload(attachmentBucket).call(this, fileRef); diff --git a/models/avatars.js b/models/avatars.js index d45dc3df6..b739f8eb3 100644 --- a/models/avatars.js +++ b/models/avatars.js @@ -5,6 +5,8 @@ import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload'; import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload'; import { createOnAfterRemove } from './lib/fsHooks/createOnAfterRemove'; +const os = require('os'); + let avatarsBucket; if (Meteor.isServer) { avatarsBucket = createBucket('avatars'); @@ -13,6 +15,7 @@ if (Meteor.isServer) { Avatars = new FilesCollection({ debug: false, // Change to `true` for debugging collectionName: 'avatars', + storagePath: os.tmpdir(), allowClientCode: true, onBeforeUpload(file) { if (file.size <= 72000 && file.type.startsWith('image/')) { diff --git a/server/migrations.js b/server/migrations.js index f9fd779a7..45a12e3bf 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -21,9 +21,6 @@ import Swimlanes from '../models/swimlanes'; import Triggers from '../models/triggers'; import UnsavedEdits from '../models/unsavedEdits'; import Users from '../models/users'; - -const fs = require('fs'); - // Anytime you change the schema of one of the collection in a non-backward // compatible way you have to write a migration in this file using the following // API: @@ -1066,15 +1063,18 @@ Migrations.add('add-hide-logo-by-default', () => { noValidateMulti, ); }); -Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => { +Migrations.add('migrate-attachments-collectionFS-to-ostrioFilesX', () => { + const os = require('os'); + const fs = require('fs'); + const path = require('path'); + tmdir = os.tmpdir(); + AttachmentsOld.find().forEach(function(fileObj) { //console.log('File: ', fileObj.userId); // This directory must be writable on server, so a test run first - // We are going to copy the files locally, then move them to S3 - const fileName = `./assets/app/uploads/attachments/${ - fileObj._id - }-${fileObj.name()}`; + // We are going to copy the files locally, then move them to mongo bucket + const fileName = path.join(tmpdir, `${fileObj._id}-${fileObj.name()}`); const newFileName = fileObj.name(); // This is "example" variable, change it to the userId that you might be using. @@ -1132,15 +1132,18 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => { readStream.pipe(writeStream); }); }); -Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => { +Migrations.add('migrate-avatars-collectionFS-to-ostrioFilesX', () => { + const os = require('os'); + const fs = require('fs'); + const path = require('path'); + tmdir = os.tmpdir(); + AvatarsOld.find().forEach(function(fileObj) { //console.log('File: ', fileObj.userId); // This directory must be writable on server, so a test run first - // We are going to copy the files locally, then move them to S3 - const fileName = `./assets/app/uploads/avatars/${ - fileObj._id - }-${fileObj.name()}`; + // We are going to copy the files locally, then move them to mongo bucket + const fileName = path.join(tmpdir, `${fileObj._id}-${fileObj.name()}`); const newFileName = fileObj.name(); // This is "example" variable, change it to the userId that you might be using.