From 05c53ca01d71a01a608c9ae345475abd67c9939b Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Mon, 18 Nov 2019 01:47:26 +0000 Subject: Trying to upload an attachment with Meteor-Files --- .meteor/packages | 1 + .meteor/versions | 2 + ...242+\347\254\254\344\272\214\346\263\242).xlsx" | Bin 0 -> 29409 bytes client/components/cards/attachments.js | 24 +++-- client/lib/utils.js | 28 ++++-- models/attachments.js | 47 +++++++-- rebuild-wekan.bat | 112 ++++++++++----------- server/publications/boards.js | 2 +- 8 files changed, 132 insertions(+), 84 deletions(-) create mode 100644 "atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" diff --git a/.meteor/packages b/.meteor/packages index f234baea..a455c639 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -96,3 +96,4 @@ konecty:mongo-counter percolate:synced-cron easylogic:summernote cfs:filesystem +ostrio:files diff --git a/.meteor/versions b/.meteor/versions index 3b45f986..9b5fb93e 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -133,6 +133,8 @@ oauth2@1.2.1 observe-sequence@1.0.16 ongoworks:speakingurl@1.1.0 ordered-dict@1.1.0 +ostrio:cookies@2.5.0 +ostrio:files@1.13.0 peerlibrary:assert@0.2.5 peerlibrary:base-component@0.16.0 peerlibrary:blaze-components@0.15.1 diff --git "a/atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" "b/atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" new file mode 100644 index 00000000..4e89ac5d Binary files /dev/null and "b/atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" differ diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index e4439155..604dc078 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -149,20 +149,28 @@ Template.previewClipboardImagePopup.events({ if (results && results.file) { window.oPasted = pastedResults; const card = this; - const file = new FS.File(results.file); + const settings = { + file: results.file, + streams: 'dynamic', + chunkSize: 'dynamic' + }; if (!results.name) { // if no filename, it's from clipboard. then we give it a name, with ext name from MIME type + // FIXME: Check this behavior if (typeof results.file.type === 'string') { - file.name(results.file.type.replace('image/', 'clipboard.')); + settings.fileName = new Date().getTime() + results.file.type.replace('.+/', ''); } } - file.updatedAt(new Date()); - file.boardId = card.boardId; - file.cardId = card._id; - file.userId = Meteor.userId(); - const attachment = Attachments.insert(file); + settings.meta = {}; + settings.meta.updatedAt = new Date().getTime(); + settings.meta.boardId = card.boardId; + settings.meta.cardId = card._id; + settings.meta.userId = Meteor.userId(); + console.log('settings', settings); + const attachment = Attachments.insert(settings, false); - if (attachment && attachment._id && attachment.isImage()) { + // TODO: Check image cover behavior + if (attachment && attachment._id && attachment.isImage) { card.setCover(attachment._id); } diff --git a/client/lib/utils.js b/client/lib/utils.js index cc3526c0..2694396f 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -34,21 +34,27 @@ Utils = { if (!card) { return next(); } - const file = new FS.File(fileObj); + let settings = { + file: fileObj, + streams: 'dynamic', + chunkSize: 'dynamic' + }; + settings.meta = {}; if (card.isLinkedCard()) { - file.boardId = Cards.findOne(card.linkedId).boardId; - file.cardId = card.linkedId; + settings.meta.boardId = Cards.findOne(card.linkedId).boardId; + settings.meta.cardId = card.linkedId; } else { - file.boardId = card.boardId; - file.swimlaneId = card.swimlaneId; - file.listId = card.listId; - file.cardId = card._id; + settings.meta.boardId = card.boardId; + settings.meta.swimlaneId = card.swimlaneId; + settings.meta.listId = card.listId; + settings.meta.cardId = card._id; } - file.userId = Meteor.userId(); - if (file.original) { + settings.meta.userId = Meteor.userId(); + // FIXME: What is this? +/* if (file.original) { file.original.name = fileObj.name; - } - return next(Attachments.insert(file)); + }*/ + return next(Attachments.insert(settings, false)); }, shrinkImage(options) { // shrink image to certain size diff --git a/models/attachments.js b/models/attachments.js index 9b8ec04f..fd03e6d2 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -1,3 +1,29 @@ +import { FilesCollection } from 'meteor/ostrio:files'; + +Attachments = new FilesCollection({ + storagePath: storagePath(), + debug: true, // FIXME: Remove debug mode + collectionName: 'attachments2', + allowClientCode: false, // Disallow remove files from Client +}); + +if (Meteor.isServer) { + Meteor.startup(() => { + Attachments.collection._ensureIndex({ cardId: 1 }); + }); + + // TODO: Permission related + // TODO: Add Activity update + // TODO: publish and subscribe +// Meteor.publish('files.attachments.all', function () { +// return Attachments.find().cursor; +// }); +} else { +// Meteor.subscribe('files.attachments.all'); +} + +// ---------- Deprecated fallback ---------- // + const localFSStore = process.env.ATTACHMENTS_STORE_PATH; const storeName = 'attachments'; const defaultStoreOptions = { @@ -171,16 +197,16 @@ if (localFSStore) { ...defaultStoreOptions, }); } -Attachments = new FS.Collection('attachments', { +DeprecatedAttachs = new FS.Collection('attachments', { stores: [store], }); if (Meteor.isServer) { Meteor.startup(() => { - Attachments.files._ensureIndex({ cardId: 1 }); + DeprecatedAttachs.files._ensureIndex({ cardId: 1 }); }); - Attachments.allow({ + DeprecatedAttachs.allow({ insert(userId, doc) { return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); }, @@ -206,10 +232,10 @@ if (Meteor.isServer) { }); } -// XXX Enforce a schema for the Attachments CollectionFS +// XXX Enforce a schema for the DeprecatedAttachs CollectionFS if (Meteor.isServer) { - Attachments.files.after.insert((userId, doc) => { + DeprecatedAttachs.files.after.insert((userId, doc) => { // If the attachment doesn't have a source field // or its source is different than import if (!doc.source || doc.source !== 'import') { @@ -227,7 +253,7 @@ if (Meteor.isServer) { } else { // Don't add activity about adding the attachment as the activity // be imported and delete source field - Attachments.update( + DeprecatedAttachs.update( { _id: doc._id, }, @@ -240,7 +266,7 @@ if (Meteor.isServer) { } }); - Attachments.files.before.remove((userId, doc) => { + DeprecatedAttachs.files.before.remove((userId, doc) => { Activities.insert({ userId, type: 'card', @@ -253,11 +279,16 @@ if (Meteor.isServer) { }); }); - Attachments.files.after.remove((userId, doc) => { + DeprecatedAttachs.files.after.remove((userId, doc) => { Activities.remove({ attachmentId: doc._id, }); }); } +function storagePath(defaultPath) { + const storePath = process.env.ATTACHMENTS_STORE_PATH; + return storePath ? storePath : defaultPath; +} + export default Attachments; diff --git a/rebuild-wekan.bat b/rebuild-wekan.bat index 05614899..8ea786cb 100644 --- a/rebuild-wekan.bat +++ b/rebuild-wekan.bat @@ -1,56 +1,56 @@ -@ECHO OFF - -REM NOTE: THIS .BAT DOES NOT WORK !! -REM Use instead this webpage instructions to build on Windows: -REM https://github.com/wekan/wekan/wiki/Install-Wekan-from-source-on-Windows -REM Please add fix PRs, like config of MongoDB etc. - -md C:\repos -cd C:\repos - -REM Install chocolatey -@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" - -choco install -y git curl python2 dotnet4.5.2 nano mongodb-3 mongoclient meteor - -curl -O https://nodejs.org/dist/v8.16.1/node-v8.16.1-x64.msi -call node-v8.16.1-x64.msi - -call npm config -g set msvs_version 2015 -call meteor npm config -g set msvs_version 2015 - -call npm -g install npm -call npm -g install node-gyp -call npm -g install fibers -cd C:\repos -git clone https://github.com/wekan/wekan.git -cd wekan -git checkout edge -echo "Building Wekan." -REM del /S /F /Q packages -REM ## REPOS BELOW ARE INCLUDED TO WEKAN -REM md packages -REM cd packages -REM git clone --depth 1 -b master https://github.com/wekan/flow-router.git kadira-flow-router -REM git clone --depth 1 -b master https://github.com/meteor-useraccounts/core.git meteor-useraccounts-core -REM git clone --depth 1 -b master https://github.com/wekan/meteor-accounts-cas.git -REM git clone --depth 1 -b master https://github.com/wekan/wekan-ldap.git -REM git clone --depth 1 -b master https://github.com/wekan/wekan-scrollbar.git -REM git clone --depth 1 -b master https://github.com/wekan/meteor-accounts-oidc.git -REM git clone --depth 1 -b master --recurse-submodules https://github.com/wekan/markdown.git -REM move meteor-accounts-oidc/packages/switch_accounts-oidc wekan_accounts-oidc -REM move meteor-accounts-oidc/packages/switch_oidc wekan_oidc -REM del /S /F /Q meteor-accounts-oidc -REM sed -i 's/api\.versionsFrom/\/\/api.versionsFrom/' ~/repos/wekan/packages/meteor-useraccounts-core/package.js -cd .. -REM del /S /F /Q node_modules -call meteor npm install -REM del /S /F /Q .build -call meteor build .build --directory -copy fix-download-unicode\cfs_access-point.txt .build\bundle\programs\server\packages\cfs_access-point.js -cd .build\bundle\programs\server -call meteor npm install -REM cd C:\repos\wekan\.meteor\local\build\programs\server -REM del node_modules -cd C:\repos\wekan -call start-wekan.bat +@ECHO OFF + +REM NOTE: THIS .BAT DOES NOT WORK !! +REM Use instead this webpage instructions to build on Windows: +REM https://github.com/wekan/wekan/wiki/Install-Wekan-from-source-on-Windows +REM Please add fix PRs, like config of MongoDB etc. + +md C:\repos +cd C:\repos + +REM Install chocolatey +@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" + +choco install -y git curl python2 dotnet4.5.2 nano mongodb-3 mongoclient meteor + +curl -O https://nodejs.org/dist/v8.16.1/node-v8.16.1-x64.msi +call node-v8.16.1-x64.msi + +call npm config -g set msvs_version 2015 +call meteor npm config -g set msvs_version 2015 + +call npm -g install npm +call npm -g install node-gyp +call npm -g install fibers +cd C:\repos +git clone https://github.com/wekan/wekan.git +cd wekan +git checkout edge +echo "Building Wekan." +REM del /S /F /Q packages +REM ## REPOS BELOW ARE INCLUDED TO WEKAN +REM md packages +REM cd packages +REM git clone --depth 1 -b master https://github.com/wekan/flow-router.git kadira-flow-router +REM git clone --depth 1 -b master https://github.com/meteor-useraccounts/core.git meteor-useraccounts-core +REM git clone --depth 1 -b master https://github.com/wekan/meteor-accounts-cas.git +REM git clone --depth 1 -b master https://github.com/wekan/wekan-ldap.git +REM git clone --depth 1 -b master https://github.com/wekan/wekan-scrollbar.git +REM git clone --depth 1 -b master https://github.com/wekan/meteor-accounts-oidc.git +REM git clone --depth 1 -b master --recurse-submodules https://github.com/wekan/markdown.git +REM move meteor-accounts-oidc/packages/switch_accounts-oidc wekan_accounts-oidc +REM move meteor-accounts-oidc/packages/switch_oidc wekan_oidc +REM del /S /F /Q meteor-accounts-oidc +REM sed -i 's/api\.versionsFrom/\/\/api.versionsFrom/' ~/repos/wekan/packages/meteor-useraccounts-core/package.js +cd .. +REM del /S /F /Q node_modules +call meteor npm install +REM del /S /F /Q .build +call meteor build .build --directory +copy fix-download-unicode\cfs_access-point.txt .build\bundle\programs\server\packages\cfs_access-point.js +cd .build\bundle\programs\server +call meteor npm install +REM cd C:\repos\wekan\.meteor\local\build\programs\server +REM del node_modules +cd C:\repos\wekan +call start-wekan.bat diff --git a/server/publications/boards.js b/server/publications/boards.js index e3095833..79e578b8 100644 --- a/server/publications/boards.js +++ b/server/publications/boards.js @@ -128,7 +128,7 @@ Meteor.publishRelations('board', function(boardId, isArchived) { // Gather queries and send in bulk const cardComments = this.join(CardComments); cardComments.selector = _ids => ({ cardId: _ids }); - const attachments = this.join(Attachments); + const attachments = this.join(Attachments.collection); attachments.selector = _ids => ({ cardId: _ids }); const checklists = this.join(Checklists); checklists.selector = _ids => ({ cardId: _ids }); -- cgit v1.2.3-1-g7c22 From 4dcdec0084414e7dde9e630add01ecd2865bd941 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Wed, 20 Nov 2019 10:40:09 +0000 Subject: Attachment upload from card done, need to fix download link --- client/components/cards/attachments.js | 23 ++++++++++++++++++----- client/components/main/editor.js | 8 ++------ client/lib/utils.js | 14 +++++++++++--- models/attachments.js | 10 +++++----- models/cards.js | 12 +++++++----- models/export.js | 2 +- models/trelloCreator.js | 1 + models/wekanCreator.js | 2 ++ server/migrations.js | 4 ++-- 9 files changed, 49 insertions(+), 27 deletions(-) diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index 604dc078..f24a7f82 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -45,18 +45,31 @@ Template.attachmentsGalery.events({ }, }); +Template.attachmentsGalery.helpers({ + url() { + return Attachments.link(this); + } +}); + Template.previewAttachedImagePopup.events({ 'click .js-large-image-clicked'() { Popup.close(); }, }); +Template.previewAttachedImagePopup.helpers({ + url() { + return Attachments.link(this); + } +}); + Template.cardAttachmentsPopup.events({ 'change .js-attach-file'(event) { const card = this; const processFile = f => { Utils.processUploadedAttachment(card, f, attachment => { - if (attachment && attachment._id && attachment.isImage()) { + console.log('attachment', attachment); + if (attachment && attachment._id && attachment.isImage) { card.setCover(attachment._id); } Popup.close(); @@ -152,13 +165,14 @@ Template.previewClipboardImagePopup.events({ const settings = { file: results.file, streams: 'dynamic', - chunkSize: 'dynamic' + chunkSize: 'dynamic', }; if (!results.name) { // if no filename, it's from clipboard. then we give it a name, with ext name from MIME type // FIXME: Check this behavior if (typeof results.file.type === 'string') { - settings.fileName = new Date().getTime() + results.file.type.replace('.+/', ''); + settings.fileName = + new Date().getTime() + results.file.type.replace('.+/', ''); } } settings.meta = {}; @@ -166,8 +180,7 @@ Template.previewClipboardImagePopup.events({ settings.meta.boardId = card.boardId; settings.meta.cardId = card._id; settings.meta.userId = Meteor.userId(); - console.log('settings', settings); - const attachment = Attachments.insert(settings, false); + const attachment = Attachments.insert(settings); // TODO: Check image cover behavior if (attachment && attachment._id && attachment.isImage) { diff --git a/client/components/main/editor.js b/client/components/main/editor.js index 39c03aa9..bd110868 100755 --- a/client/components/main/editor.js +++ b/client/components/main/editor.js @@ -229,18 +229,14 @@ Template.editor.onRendered(() => { currentCard, fileObj, attachment => { - if ( - attachment && - attachment._id && - attachment.isImage() - ) { + if (attachment && attachment._id && attachment.isImage) { attachment.one('uploaded', function() { const maxTry = 3; const checkItvl = 500; let retry = 0; const checkUrl = function() { // even though uploaded event fired, attachment.url() is still null somehow //TODO - const url = attachment.url(); + const url = attachment.link(); if (url) { insertImage( `${location.protocol}//${location.host}${url}`, diff --git a/client/lib/utils.js b/client/lib/utils.js index 2694396f..d667382d 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -37,7 +37,15 @@ Utils = { let settings = { file: fileObj, streams: 'dynamic', - chunkSize: 'dynamic' + chunkSize: 'dynamic', + onUploaded: function(error, fileObj) { + console.log('after insert', Attachments.find({}).fetch()); + if (error) { + console.log('Error while upload', error); + } else { + next(fileObj); + } + }, }; settings.meta = {}; if (card.isLinkedCard()) { @@ -51,10 +59,10 @@ Utils = { } settings.meta.userId = Meteor.userId(); // FIXME: What is this? -/* if (file.original) { + /* if (file.original) { file.original.name = fileObj.name; }*/ - return next(Attachments.insert(settings, false)); + Attachments.insert(settings); }, shrinkImage(options) { // shrink image to certain size diff --git a/models/attachments.js b/models/attachments.js index fd03e6d2..4537e47c 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -4,7 +4,7 @@ Attachments = new FilesCollection({ storagePath: storagePath(), debug: true, // FIXME: Remove debug mode collectionName: 'attachments2', - allowClientCode: false, // Disallow remove files from Client + allowClientCode: true, // FIXME: Permissions }); if (Meteor.isServer) { @@ -15,11 +15,11 @@ if (Meteor.isServer) { // TODO: Permission related // TODO: Add Activity update // TODO: publish and subscribe -// Meteor.publish('files.attachments.all', function () { -// return Attachments.find().cursor; -// }); + Meteor.publish('attachments', function() { + return Attachments.find().cursor; + }); } else { -// Meteor.subscribe('files.attachments.all'); + Meteor.subscribe('attachments'); } // ---------- Deprecated fallback ---------- // diff --git a/models/cards.js b/models/cards.js index 3944b09f..4c3e2c99 100644 --- a/models/cards.js +++ b/models/cards.js @@ -366,7 +366,7 @@ Cards.helpers({ // Copy attachments oldCard.attachments().forEach(att => { - att.cardId = _id; + att.meta.cardId = _id; delete att._id; return Attachments.insert(att); }); @@ -456,14 +456,16 @@ Cards.helpers({ attachments() { if (this.isLinkedCard()) { return Attachments.find( - { cardId: this.linkedId }, + { 'meta.cardId': this.linkedId }, { sort: { uploadedAt: -1 } }, ); } else { - return Attachments.find( - { cardId: this._id }, + const ret = Attachments.find( + { 'meta.cardId': this._id }, { sort: { uploadedAt: -1 } }, ); + if (ret.first()) console.log('link', Attachments.link(ret.first())); + return ret; } }, @@ -471,7 +473,7 @@ Cards.helpers({ const cover = Attachments.findOne(this.coverId); // if we return a cover before it is fully stored, we will get errors when we try to display it // todo XXX we could return a default "upload pending" image in the meantime? - return cover && cover.url() && cover; + return cover && cover.link(); }, checklists() { diff --git a/models/export.js b/models/export.js index cc979ce0..c93a8bda 100644 --- a/models/export.js +++ b/models/export.js @@ -162,7 +162,7 @@ export class Exporter { readStream.pipe(tmpWriteable); }; const getBase64DataSync = Meteor.wrapAsync(getBase64Data); - result.attachments = Attachments.find(byBoard) + result.attachments = Attachments.find({ 'meta.boardId': byBoard.boardId }) .fetch() .map(attachment => { return { diff --git a/models/trelloCreator.js b/models/trelloCreator.js index cb1a6a67..b38e4652 100644 --- a/models/trelloCreator.js +++ b/models/trelloCreator.js @@ -345,6 +345,7 @@ export class TrelloCreator { // so we make it server only, and let UI catch up once it is done, forget about latency comp. const self = this; if (Meteor.isServer) { + // FIXME: Change to new model file.attachData(att.url, function(error) { file.boardId = boardId; file.cardId = cardId; diff --git a/models/wekanCreator.js b/models/wekanCreator.js index ec85d93f..175c156d 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -415,6 +415,7 @@ export class WekanCreator { const self = this; if (Meteor.isServer) { if (att.url) { + // FIXME: Change to new file library file.attachData(att.url, function(error) { file.boardId = boardId; file.cardId = cardId; @@ -440,6 +441,7 @@ export class WekanCreator { } }); } else if (att.file) { + // FIXME: Change to new file library file.attachData( new Buffer(att.file, 'base64'), { diff --git a/server/migrations.js b/server/migrations.js index 836220f3..7d5a5cca 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -80,7 +80,7 @@ Migrations.add('lowercase-board-permission', () => { Migrations.add('change-attachments-type-for-non-images', () => { const newTypeForNonImage = 'application/octet-stream'; Attachments.find().forEach(file => { - if (!file.isImage()) { + if (!file.isImage) { Attachments.update( file._id, { @@ -97,7 +97,7 @@ Migrations.add('change-attachments-type-for-non-images', () => { Migrations.add('card-covers', () => { Cards.find().forEach(card => { - const cover = Attachments.findOne({ cardId: card._id, cover: true }); + const cover = Attachments.findOne({ 'meta.cardId': card._id, cover: true }); if (cover) { Cards.update(card._id, { $set: { coverId: cover._id } }, noValidate); } -- cgit v1.2.3-1-g7c22 From 6cdd464f54fca423876a27ec2a4269ae5841cdb0 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Wed, 27 Nov 2019 09:40:19 +0000 Subject: Uploaded done, but uploading not --- client/components/cards/attachments.jade | 2 +- client/components/cards/attachments.js | 26 ++++++++++++++------------ client/components/cards/minicard.jade | 2 +- client/components/cards/minicard.js | 3 +++ client/lib/utils.js | 16 ++-------------- models/attachments.js | 6 +++++- models/cards.js | 3 +-- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/client/components/cards/attachments.jade b/client/components/cards/attachments.jade index 2a96f4f4..3ce639bc 100644 --- a/client/components/cards/attachments.jade +++ b/client/components/cards/attachments.jade @@ -23,7 +23,7 @@ template(name="attachmentsGalery") each attachments .attachment-item a.attachment-thumbnail.swipebox(href="{{url}}" title="{{name}}") - if isUploaded + if isUploaded if isImage img.attachment-thumbnail-img(src="{{url}}") else diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index f24a7f82..7346e943 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -13,10 +13,10 @@ Template.attachmentsGalery.events({ event.stopPropagation(); }, 'click .js-add-cover'() { - Cards.findOne(this.cardId).setCover(this._id); + Cards.findOne(this.meta.cardId).setCover(this._id); }, 'click .js-remove-cover'() { - Cards.findOne(this.cardId).unsetCover(); + Cards.findOne(this.meta.cardId).unsetCover(); }, 'click .js-preview-image'(event) { Popup.open('previewAttachedImage').call(this, event); @@ -47,8 +47,11 @@ Template.attachmentsGalery.events({ Template.attachmentsGalery.helpers({ url() { - return Attachments.link(this); - } + return Attachments.link(this); + }, + isUploaded() { + return !!this.meta.uploaded; + }, }); Template.previewAttachedImagePopup.events({ @@ -67,13 +70,14 @@ Template.cardAttachmentsPopup.events({ 'change .js-attach-file'(event) { const card = this; const processFile = f => { - Utils.processUploadedAttachment(card, f, attachment => { - console.log('attachment', attachment); - if (attachment && attachment._id && attachment.isImage) { - card.setCover(attachment._id); + Utils.processUploadedAttachment(card, f, + (err, attachment) => { + if (attachment && attachment._id && attachment.isImage) { + card.setCover(attachment._id); + } + Popup.close(); } - Popup.close(); - }); + ); }; FS.Utility.eachFile(event, f => { @@ -169,7 +173,6 @@ Template.previewClipboardImagePopup.events({ }; if (!results.name) { // if no filename, it's from clipboard. then we give it a name, with ext name from MIME type - // FIXME: Check this behavior if (typeof results.file.type === 'string') { settings.fileName = new Date().getTime() + results.file.type.replace('.+/', ''); @@ -182,7 +185,6 @@ Template.previewClipboardImagePopup.events({ settings.meta.userId = Meteor.userId(); const attachment = Attachments.insert(settings); - // TODO: Check image cover behavior if (attachment && attachment._id && attachment.isImage) { card.setCover(attachment._id); } diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index 79672f8c..0a35bd3a 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -11,7 +11,7 @@ template(name="minicard") .handle .fa.fa-arrows if cover - .minicard-cover(style="background-image: url('{{cover.url}}');") + .minicard-cover(style="background-image: url('{{coverUrl}}');") if labels .minicard-labels each labels diff --git a/client/components/cards/minicard.js b/client/components/cards/minicard.js index 4c76db46..3ddb7e97 100644 --- a/client/components/cards/minicard.js +++ b/client/components/cards/minicard.js @@ -32,4 +32,7 @@ Template.minicard.helpers({ hiddenMinicardLabelText() { return Meteor.user().hasHiddenMinicardLabelText(); }, + coverUrl() { + return Attachments.findOne(this.coverId).link(); + }, }); diff --git a/client/lib/utils.js b/client/lib/utils.js index d667382d..8503b035 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -32,20 +32,12 @@ Utils = { } }; if (!card) { - return next(); + return onUploaded(); } let settings = { file: fileObj, streams: 'dynamic', chunkSize: 'dynamic', - onUploaded: function(error, fileObj) { - console.log('after insert', Attachments.find({}).fetch()); - if (error) { - console.log('Error while upload', error); - } else { - next(fileObj); - } - }, }; settings.meta = {}; if (card.isLinkedCard()) { @@ -58,11 +50,7 @@ Utils = { settings.meta.cardId = card._id; } settings.meta.userId = Meteor.userId(); - // FIXME: What is this? - /* if (file.original) { - file.original.name = fileObj.name; - }*/ - Attachments.insert(settings); + Attachments.insert(settings).on('end', next); }, shrinkImage(options) { // shrink image to certain size diff --git a/models/attachments.js b/models/attachments.js index 4537e47c..5dcc75e6 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -2,9 +2,12 @@ import { FilesCollection } from 'meteor/ostrio:files'; Attachments = new FilesCollection({ storagePath: storagePath(), - debug: true, // FIXME: Remove debug mode + debug: false, // FIXME: Remove debug mode collectionName: 'attachments2', allowClientCode: true, // FIXME: Permissions + onAfterUpload: (fileRef) => { + Attachments.update({_id:fileRef._id}, {$set: {"meta.uploaded": true}}); + } }); if (Meteor.isServer) { @@ -15,6 +18,7 @@ if (Meteor.isServer) { // TODO: Permission related // TODO: Add Activity update // TODO: publish and subscribe + Meteor.publish('attachments', function() { return Attachments.find().cursor; }); diff --git a/models/cards.js b/models/cards.js index 4c3e2c99..86d22c53 100644 --- a/models/cards.js +++ b/models/cards.js @@ -460,11 +460,10 @@ Cards.helpers({ { sort: { uploadedAt: -1 } }, ); } else { - const ret = Attachments.find( + let ret = Attachments.find( { 'meta.cardId': this._id }, { sort: { uploadedAt: -1 } }, ); - if (ret.first()) console.log('link', Attachments.link(ret.first())); return ret; } }, -- cgit v1.2.3-1-g7c22 From 93337c20f83146bb702a5af8cf9cdb37f4c53443 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Tue, 24 Dec 2019 08:57:34 +0000 Subject: Change upload routine, add upload popup --- client/components/cards/attachments.jade | 8 +++++++ client/components/cards/attachments.js | 40 ++++++++++++++++++++++++++++---- client/components/main/editor.js | 1 + client/lib/popup.js | 2 +- client/lib/utils.js | 18 ++++++++------ 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/client/components/cards/attachments.jade b/client/components/cards/attachments.jade index 3ce639bc..04e0d04c 100644 --- a/client/components/cards/attachments.jade +++ b/client/components/cards/attachments.jade @@ -18,6 +18,13 @@ template(name="attachmentDeletePopup") p {{_ "attachment-delete-pop"}} button.js-confirm.negate.full(type="submit") {{_ 'delete'}} +template(name="uploadingPopup") + p Uploading... + p + span.upload-percentage 0% + div.upload-progress-bar + span.upload-size {{fileSize}} + template(name="attachmentsGalery") .attachments-galery each attachments @@ -53,3 +60,4 @@ template(name="attachmentsGalery") unless currentUser.isCommentOnly li.attachment-item.add-attachment a.js-add-attachment {{_ 'add-attachment' }} + diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index 7346e943..026ce170 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -66,18 +66,38 @@ Template.previewAttachedImagePopup.helpers({ } }); +// For uploading popup + +let uploadFileSize = new ReactiveVar(''); +let uploadProgress = new ReactiveVar(0); + Template.cardAttachmentsPopup.events({ - 'change .js-attach-file'(event) { + 'change .js-attach-file'(event, instance) { const card = this; - const processFile = f => { - Utils.processUploadedAttachment(card, f, - (err, attachment) => { + const callbacks = { + onBeforeUpload: (err, fileData) => { + Popup.open('uploading')(this.clickEvent); + return true; + }, + onUploaded: (err, attachment) => { + console.log('onEnd'); if (attachment && attachment._id && attachment.isImage) { card.setCover(attachment._id); } Popup.close(); + }, + onStart: (error, fileData) => { + console.log('fd', fileData); + uploadFileSize.set(`${fileData.size} bytes`); + }, + onError: (err, fileObj) => { + console.log('Error!', err); + }, + onProgress: (progress, fileData) => { } - ); + }; + const processFile = f => { + Utils.processUploadedAttachment(card, f, callbacks); }; FS.Utility.eachFile(event, f => { @@ -117,12 +137,22 @@ Template.cardAttachmentsPopup.events({ }); }, 'click .js-computer-upload'(event, templateInstance) { + this.clickEvent = event; templateInstance.find('.js-attach-file').click(); event.preventDefault(); }, 'click .js-upload-clipboard-image': Popup.open('previewClipboardImage'), }); +Template.uploadingPopup.onRendered(() => { +}); + +Template.uploadingPopup.helpers({ + fileSize: () => { + return uploadFileSize.get(); + } +}); + const MAX_IMAGE_PIXEL = Utils.MAX_IMAGE_PIXEL; const COMPRESS_RATIO = Utils.IMAGE_COMPRESS_RATIO; let pastedResults = null; diff --git a/client/components/main/editor.js b/client/components/main/editor.js index bd110868..64f24f98 100755 --- a/client/components/main/editor.js +++ b/client/components/main/editor.js @@ -225,6 +225,7 @@ Template.editor.onRendered(() => { $summernote.summernote('insertNode', img); }; const processData = function(fileObj) { + // FIXME: Change to new API Utils.processUploadedAttachment( currentCard, fileObj, diff --git a/client/lib/popup.js b/client/lib/popup.js index 8095fbd2..cae22659 100644 --- a/client/lib/popup.js +++ b/client/lib/popup.js @@ -49,7 +49,7 @@ window.Popup = new (class { // has one. This allows us to position a sub-popup exactly at the same // position than its parent. let openerElement; - if (clickFromPopup(evt)) { + if (clickFromPopup(evt) && self._getTopStack()) { openerElement = self._getTopStack().openerElement; } else { self._stack = []; diff --git a/client/lib/utils.js b/client/lib/utils.js index 8503b035..213124f1 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -25,12 +25,7 @@ Utils = { }, MAX_IMAGE_PIXEL: Meteor.settings.public.MAX_IMAGE_PIXEL, COMPRESS_RATIO: Meteor.settings.public.IMAGE_COMPRESS_RATIO, - processUploadedAttachment(card, fileObj, callback) { - const next = attachment => { - if (typeof callback === 'function') { - callback(attachment); - } - }; + processUploadedAttachment(card, fileObj, callbacks) { if (!card) { return onUploaded(); } @@ -50,7 +45,16 @@ Utils = { settings.meta.cardId = card._id; } settings.meta.userId = Meteor.userId(); - Attachments.insert(settings).on('end', next); + if (typeof callbacks === 'function') { + settings.onEnd = callbacks; + } else { + for (const key in callbacks) { + if (key.substring(0, 2) === 'on') { + settings[key] = callbacks[key]; + } + } + } + Attachments.insert(settings); }, shrinkImage(options) { // shrink image to certain size -- cgit v1.2.3-1-g7c22 From 6ebd6defe917a70e84467d64a1c15ec109c73f1b Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Thu, 2 Jan 2020 09:16:28 +0000 Subject: Uploading dialog done --- client/components/cards/attachments.jade | 8 ++++---- client/components/cards/attachments.js | 25 +++++++++++++++++++------ client/components/cards/attachments.styl | 11 +++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/client/components/cards/attachments.jade b/client/components/cards/attachments.jade index 04e0d04c..a5a5c00b 100644 --- a/client/components/cards/attachments.jade +++ b/client/components/cards/attachments.jade @@ -19,10 +19,10 @@ template(name="attachmentDeletePopup") button.js-confirm.negate.full(type="submit") {{_ 'delete'}} template(name="uploadingPopup") - p Uploading... - p - span.upload-percentage 0% - div.upload-progress-bar + .uploading-info + span.upload-percentage {{progress}}% + .upload-progress-frame + .upload-progress-bar(style="width: {{progress}}%;") span.upload-size {{fileSize}} template(name="attachmentsGalery") diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index 026ce170..9e32825e 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -77,23 +77,24 @@ Template.cardAttachmentsPopup.events({ const callbacks = { onBeforeUpload: (err, fileData) => { Popup.open('uploading')(this.clickEvent); + uploadFileSize.set('...'); + uploadProgress.set(0); return true; }, onUploaded: (err, attachment) => { - console.log('onEnd'); if (attachment && attachment._id && attachment.isImage) { card.setCover(attachment._id); } Popup.close(); }, onStart: (error, fileData) => { - console.log('fd', fileData); - uploadFileSize.set(`${fileData.size} bytes`); + uploadFileSize.set(formatBytes(fileData.size)); }, onError: (err, fileObj) => { console.log('Error!', err); }, onProgress: (progress, fileData) => { + uploadProgress.set(progress); } }; const processFile = f => { @@ -144,12 +145,12 @@ Template.cardAttachmentsPopup.events({ 'click .js-upload-clipboard-image': Popup.open('previewClipboardImage'), }); -Template.uploadingPopup.onRendered(() => { -}); - Template.uploadingPopup.helpers({ fileSize: () => { return uploadFileSize.get(); + }, + progress: () => { + return uploadProgress.get(); } }); @@ -225,3 +226,15 @@ Template.previewClipboardImagePopup.events({ } }, }); + +function formatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} diff --git a/client/components/cards/attachments.styl b/client/components/cards/attachments.styl index 4a22fd8a..61ea8232 100644 --- a/client/components/cards/attachments.styl +++ b/client/components/cards/attachments.styl @@ -64,6 +64,17 @@ border: 1px solid black box-shadow: 0 1px 2px rgba(0,0,0,.2) +.uploading-info + .upload-progress-frame + background-color: grey; + border: 1px solid; + height: 22px; + + .upload-progress-bar + background-color: blue; + height: 20px; + padding: 1px; + @media screen and (max-width: 800px) .attachments-galery flex-direction -- cgit v1.2.3-1-g7c22 From d26bf04bfa088b770c85a895700fd704cc08e234 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Tue, 14 Jan 2020 06:29:34 +0000 Subject: Change to relative path and /var/attachments to store --- client/components/cards/attachments.js | 4 +-- client/components/cards/minicard.js | 2 +- client/components/main/editor.js | 47 +++++++++++++++++----------------- models/attachments.js | 2 ++ sandstorm-pkgdef.capnp | 3 ++- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index 9e32825e..82ecabcf 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -47,7 +47,7 @@ Template.attachmentsGalery.events({ Template.attachmentsGalery.helpers({ url() { - return Attachments.link(this); + return Attachments.link(this, 'original', '/'); }, isUploaded() { return !!this.meta.uploaded; @@ -62,7 +62,7 @@ Template.previewAttachedImagePopup.events({ Template.previewAttachedImagePopup.helpers({ url() { - return Attachments.link(this); + return Attachments.link(this, 'original', '/'); } }); diff --git a/client/components/cards/minicard.js b/client/components/cards/minicard.js index 3ddb7e97..430042f4 100644 --- a/client/components/cards/minicard.js +++ b/client/components/cards/minicard.js @@ -33,6 +33,6 @@ Template.minicard.helpers({ return Meteor.user().hasHiddenMinicardLabelText(); }, coverUrl() { - return Attachments.findOne(this.coverId).link(); + return Attachments.findOne(this.coverId).link('original', '/'); }, }); diff --git a/client/components/main/editor.js b/client/components/main/editor.js index 64f24f98..bc2e0bad 100755 --- a/client/components/main/editor.js +++ b/client/components/main/editor.js @@ -225,32 +225,33 @@ Template.editor.onRendered(() => { $summernote.summernote('insertNode', img); }; const processData = function(fileObj) { - // FIXME: Change to new API Utils.processUploadedAttachment( currentCard, - fileObj, - attachment => { - if (attachment && attachment._id && attachment.isImage) { - attachment.one('uploaded', function() { - const maxTry = 3; - const checkItvl = 500; - let retry = 0; - const checkUrl = function() { - // even though uploaded event fired, attachment.url() is still null somehow //TODO - const url = attachment.link(); - if (url) { - insertImage( - `${location.protocol}//${location.host}${url}`, - ); - } else { - retry++; - if (retry < maxTry) { - setTimeout(checkUrl, checkItvl); + fileObj, + { onUploaded: + attachment => { + if (attachment && attachment._id && attachment.isImage) { + attachment.one('uploaded', function() { + const maxTry = 3; + const checkItvl = 500; + let retry = 0; + const checkUrl = function() { + // even though uploaded event fired, attachment.url() is still null somehow //TODO + const url = Attachments.link(attachment, 'original', '/'); + if (url) { + insertImage( + `${location.protocol}//${location.host}${url}`, + ); + } else { + retry++; + if (retry < maxTry) { + setTimeout(checkUrl, checkItvl); + } } - } - }; - checkUrl(); - }); + }; + checkUrl(); + }); + } } }, ); diff --git a/models/attachments.js b/models/attachments.js index 5dcc75e6..25e4b4bb 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -291,6 +291,8 @@ if (Meteor.isServer) { } function storagePath(defaultPath) { + // FIXME + return '/var/attachments'; const storePath = process.env.ATTACHMENTS_STORE_PATH; return storePath ? storePath : defaultPath; } diff --git a/sandstorm-pkgdef.capnp b/sandstorm-pkgdef.capnp index dbdb7640..fc805f6b 100644 --- a/sandstorm-pkgdef.capnp +++ b/sandstorm-pkgdef.capnp @@ -257,6 +257,7 @@ const myCommand :Spk.Manifest.Command = ( (key = "OAUTH2_TOKEN_ENDPOINT", value=""), (key = "LDAP_ENABLE", value="false"), (key = "SANDSTORM", value="1"), - (key = "METEOR_SETTINGS", value = "{\"public\": {\"sandstorm\": true}}") + (key = "METEOR_SETTINGS", value = "{\"public\": {\"sandstorm\": true}}"), + (key = "ATTACHMENTS_STORE_PATH", value = "/var/attachments/") ] ); -- cgit v1.2.3-1-g7c22 From 617fdaeb7418d4e6c2530e7a9d4a3feb62e5a00e Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Tue, 14 Jan 2020 07:06:20 +0000 Subject: Fix sandstorm storage path --- models/attachments.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/attachments.js b/models/attachments.js index 25e4b4bb..903f6490 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -291,8 +291,12 @@ if (Meteor.isServer) { } function storagePath(defaultPath) { +/* + console.log('path', process.env.ATTACHMENTS_STORE_PATH); + console.log('env', process.env); // FIXME return '/var/attachments'; +*/ const storePath = process.env.ATTACHMENTS_STORE_PATH; return storePath ? storePath : defaultPath; } -- cgit v1.2.3-1-g7c22 From b34ed58289a3dae5838d3b621260938a3ecf52d5 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Thu, 13 Feb 2020 08:47:41 +0000 Subject: Start writing migration --- models/attachments.js | 100 +--------------- server/migrate-attachments.js | 263 ++++++++++++++++++++++++++++++++++++++++++ server/migrations.js | 6 + 3 files changed, 272 insertions(+), 97 deletions(-) create mode 100644 server/migrate-attachments.js diff --git a/models/attachments.js b/models/attachments.js index 903f6490..c35d3d4c 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -19,17 +19,17 @@ if (Meteor.isServer) { // TODO: Add Activity update // TODO: publish and subscribe - Meteor.publish('attachments', function() { + Meteor.publish('attachments2', function() { return Attachments.find().cursor; }); } else { - Meteor.subscribe('attachments'); + Meteor.subscribe('attachments2'); } // ---------- Deprecated fallback ---------- // const localFSStore = process.env.ATTACHMENTS_STORE_PATH; -const storeName = 'attachments'; +const storeName = 'attachments2'; const defaultStoreOptions = { beforeWrite: fileObj => { if (!fileObj.isImage()) { @@ -201,102 +201,8 @@ if (localFSStore) { ...defaultStoreOptions, }); } -DeprecatedAttachs = new FS.Collection('attachments', { - stores: [store], -}); - -if (Meteor.isServer) { - Meteor.startup(() => { - DeprecatedAttachs.files._ensureIndex({ cardId: 1 }); - }); - - DeprecatedAttachs.allow({ - insert(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - update(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - remove(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - // We authorize the attachment download either: - // - if the board is public, everyone (even unconnected) can download it - // - if the board is private, only board members can download it - download(userId, doc) { - const board = Boards.findOne(doc.boardId); - if (board.isPublic()) { - return true; - } else { - return board.hasMember(userId); - } - }, - - fetch: ['boardId'], - }); -} - -// XXX Enforce a schema for the DeprecatedAttachs CollectionFS - -if (Meteor.isServer) { - DeprecatedAttachs.files.after.insert((userId, doc) => { - // If the attachment doesn't have a source field - // or its source is different than import - if (!doc.source || doc.source !== 'import') { - // Add activity about adding the attachment - Activities.insert({ - userId, - type: 'card', - activityType: 'addAttachment', - attachmentId: doc._id, - boardId: doc.boardId, - cardId: doc.cardId, - listId: doc.listId, - swimlaneId: doc.swimlaneId, - }); - } else { - // Don't add activity about adding the attachment as the activity - // be imported and delete source field - DeprecatedAttachs.update( - { - _id: doc._id, - }, - { - $unset: { - source: '', - }, - }, - ); - } - }); - - DeprecatedAttachs.files.before.remove((userId, doc) => { - Activities.insert({ - userId, - type: 'card', - activityType: 'deleteAttachment', - attachmentId: doc._id, - boardId: doc.boardId, - cardId: doc.cardId, - listId: doc.listId, - swimlaneId: doc.swimlaneId, - }); - }); - - DeprecatedAttachs.files.after.remove((userId, doc) => { - Activities.remove({ - attachmentId: doc._id, - }); - }); -} function storagePath(defaultPath) { -/* - console.log('path', process.env.ATTACHMENTS_STORE_PATH); - console.log('env', process.env); - // FIXME - return '/var/attachments'; -*/ const storePath = process.env.ATTACHMENTS_STORE_PATH; return storePath ? storePath : defaultPath; } diff --git a/server/migrate-attachments.js b/server/migrate-attachments.js new file mode 100644 index 00000000..7dcc4d39 --- /dev/null +++ b/server/migrate-attachments.js @@ -0,0 +1,263 @@ +const localFSStore = process.env.ATTACHMENTS_STORE_PATH; +const storeName = 'attachments'; +const defaultStoreOptions = { + beforeWrite: fileObj => { + if (!fileObj.isImage()) { + return { + type: 'application/octet-stream', + }; + } + return {}; + }, +}; +let store; +if (localFSStore) { + // have to reinvent methods from FS.Store.GridFS and FS.Store.FileSystem + const fs = Npm.require('fs'); + const path = Npm.require('path'); + const mongodb = Npm.require('mongodb'); + const Grid = Npm.require('gridfs-stream'); + // calulate the absolute path here, because FS.Store.FileSystem didn't expose the aboslutepath or FS.Store didn't expose api calls :( + let pathname = localFSStore; + /*eslint camelcase: ["error", {allow: ["__meteor_bootstrap__"]}] */ + + if (!pathname && __meteor_bootstrap__ && __meteor_bootstrap__.serverDir) { + pathname = path.join( + __meteor_bootstrap__.serverDir, + `../../../cfs/files/${storeName}`, + ); + } + + if (!pathname) + throw new Error('FS.Store.FileSystem unable to determine path'); + + // Check if we have '~/foo/bar' + if (pathname.split(path.sep)[0] === '~') { + const homepath = + process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; + if (homepath) { + pathname = pathname.replace('~', homepath); + } else { + throw new Error('FS.Store.FileSystem unable to resolve "~" in path'); + } + } + + // Set absolute path + const absolutePath = path.resolve(pathname); + + const _FStore = new FS.Store.FileSystem(storeName, { + path: localFSStore, + ...defaultStoreOptions, + }); + const GStore = { + fileKey(fileObj) { + const key = { + _id: null, + filename: null, + }; + + // If we're passed a fileObj, we retrieve the _id and filename from it. + if (fileObj) { + const info = fileObj._getInfo(storeName, { + updateFileRecordFirst: false, + }); + key._id = info.key || null; + key.filename = + info.name || + fileObj.name({ updateFileRecordFirst: false }) || + `${fileObj.collectionName}-${fileObj._id}`; + } + + // If key._id is null at this point, createWriteStream will let GridFS generate a new ID + return key; + }, + db: undefined, + mongoOptions: { useNewUrlParser: true }, + mongoUrl: process.env.MONGO_URL, + init() { + this._init(err => { + this.inited = !err; + }); + }, + _init(callback) { + const self = this; + mongodb.MongoClient.connect(self.mongoUrl, self.mongoOptions, function( + err, + db, + ) { + if (err) { + return callback(err); + } + self.db = db; + return callback(null); + }); + return; + }, + createReadStream(fileKey, options) { + const self = this; + if (!self.inited) { + self.init(); + return undefined; + } + options = options || {}; + + // Init GridFS + const gfs = new Grid(self.db, mongodb); + + // Set the default streamning settings + const settings = { + _id: new mongodb.ObjectID(fileKey._id), + root: `cfs_gridfs.${storeName}`, + }; + + // Check if this should be a partial read + if ( + typeof options.start !== 'undefined' && + typeof options.end !== 'undefined' + ) { + // Add partial info + settings.range = { + startPos: options.start, + endPos: options.end, + }; + } + return gfs.createReadStream(settings); + }, + }; + GStore.init(); + const CRS = 'createReadStream'; + const _CRS = `_${CRS}`; + const FStore = _FStore._transform; + FStore[_CRS] = FStore[CRS].bind(FStore); + FStore[CRS] = function(fileObj, options) { + let stream; + try { + const localFile = path.join( + absolutePath, + FStore.storage.fileKey(fileObj), + ); + const state = fs.statSync(localFile); + if (state) { + stream = FStore[_CRS](fileObj, options); + } + } catch (e) { + // file is not there, try GridFS ? + stream = undefined; + } + if (stream) return stream; + else { + try { + const stream = GStore[CRS](GStore.fileKey(fileObj), options); + return stream; + } catch (e) { + return undefined; + } + } + }.bind(FStore); + store = _FStore; +} else { + store = new FS.Store.GridFS(localFSStore ? `G${storeName}` : storeName, { + // XXX Add a new store for cover thumbnails so we don't load big images in + // the general board view + // If the uploaded document is not an image we need to enforce browser + // download instead of execution. This is particularly important for HTML + // files that the browser will just execute if we don't serve them with the + // appropriate `application/octet-stream` MIME header which can lead to user + // data leaks. I imagine other formats (like PDF) can also be attack vectors. + // See https://github.com/wekan/wekan/issues/99 + // XXX Should we use `beforeWrite` option of CollectionFS instead of + // collection-hooks? + // We should use `beforeWrite`. + ...defaultStoreOptions, + }); +} +CFSAttachments = new FS.Collection('attachments', { + stores: [store], +}); + +if (Meteor.isServer) { + Meteor.startup(() => { + CFSAttachments.files._ensureIndex({ cardId: 1 }); + }); + + CFSAttachments.allow({ + insert(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); + }, + update(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); + }, + remove(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); + }, + // We authorize the attachment download either: + // - if the board is public, everyone (even unconnected) can download it + // - if the board is private, only board members can download it + download(userId, doc) { + const board = Boards.findOne(doc.boardId); + if (board.isPublic()) { + return true; + } else { + return board.hasMember(userId); + } + }, + + fetch: ['boardId'], + }); +} + +// XXX Enforce a schema for the Attachments CollectionFS + +if (Meteor.isServer) { + CFSAttachments.files.after.insert((userId, doc) => { + // If the attachment doesn't have a source field + // or its source is different than import + if (!doc.source || doc.source !== 'import') { + // Add activity about adding the attachment + Activities.insert({ + userId, + type: 'card', + activityType: 'addAttachment', + attachmentId: doc._id, + boardId: doc.boardId, + cardId: doc.cardId, + listId: doc.listId, + swimlaneId: doc.swimlaneId, + }); + } else { + // Don't add activity about adding the attachment as the activity + // be imported and delete source field + CFSAttachments.update( + { + _id: doc._id, + }, + { + $unset: { + source: '', + }, + }, + ); + } + }); + + CFSAttachments.files.before.remove((userId, doc) => { + Activities.insert({ + userId, + type: 'card', + activityType: 'deleteAttachment', + attachmentId: doc._id, + boardId: doc.boardId, + cardId: doc.cardId, + listId: doc.listId, + swimlaneId: doc.swimlaneId, + }); + }); + + CFSAttachments.files.after.remove((userId, doc) => { + Activities.remove({ + attachmentId: doc._id, + }); + }); +} + +export default CFSAttachments; diff --git a/server/migrations.js b/server/migrations.js index 7d5a5cca..e7c18e09 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -17,6 +17,7 @@ import Swimlanes from '../models/swimlanes'; import Triggers from '../models/triggers'; import UnsavedEdits from '../models/unsavedEdits'; import Users from '../models/users'; +import CFSAttachments from './migrate-attachments'; // 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 @@ -777,3 +778,8 @@ Migrations.add('fix-incorrect-dates', () => { }), ); }); + +Migrations.add('fix-incorrect-dates', () => { + cas = CFSAttachments.find(); + console.log('cas', cas); +}); -- cgit v1.2.3-1-g7c22 From 5899b9366c23f31149e9de8ed006a7e30b4830d5 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Mon, 2 Mar 2020 02:10:54 +0000 Subject: Change coagmano:stylus package to 1.1.0 since 2.0.0 building is super slow --- .meteor/packages | 4 ++-- .meteor/release | 2 +- .meteor/versions | 6 +++--- package-lock.json | 8 ++++++++ package.json | 1 + server/migrations.js | 7 +++++++ 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index 83809e48..896627a6 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -6,7 +6,7 @@ meteor-base@1.4.0 # Build system -ecmascript@0.14.0 +ecmascript@0.14.2 standard-minifier-css@1.6.0 standard-minifier-js@2.6.0 mquandalle:jade @@ -85,7 +85,7 @@ msavin:usercache wekan-scrollbar mquandalle:perfect-scrollbar mdg:meteor-apm-agent@3.2.0-rc.0! -coagmano:stylus +coagmano:stylus@1.1.0 lucasantoniassi:accounts-lockout meteorhacks:subs-manager meteorhacks:picker diff --git a/.meteor/release b/.meteor/release index c6ae8ec1..8558e149 100644 --- a/.meteor/release +++ b/.meteor/release @@ -1 +1 @@ -METEOR@1.9 +METEOR@1.9.2 diff --git a/.meteor/versions b/.meteor/versions index 8128b3f4..bccba0d6 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -12,7 +12,7 @@ allow-deny@1.1.0 arillo:flow-router-helpers@0.5.2 audit-argument-checks@1.0.7 autoupdate@1.6.0 -babel-compiler@7.5.1 +babel-compiler@7.5.2 babel-runtime@1.5.0 base64@1.0.12 binary-heap@1.0.11 @@ -44,7 +44,7 @@ cfs:upload-http@0.0.20 cfs:worker@0.1.5 check@1.3.1 chuangbo:cookie@1.1.0 -coagmano:stylus@2.0.0 +coagmano:stylus@1.1.0 coffeescript@1.0.17 cottz:publish-relations@2.0.8 dburles:collection-helpers@1.1.0 @@ -57,7 +57,7 @@ deps@1.0.12 diff-sequence@1.1.1 dynamic-import@0.5.1 easylogic:summernote@0.8.8 -ecmascript@0.14.1 +ecmascript@0.14.2 ecmascript-runtime@0.7.0 ecmascript-runtime-client@0.10.0 ecmascript-runtime-server@0.9.0 diff --git a/package-lock.json b/package-lock.json index eb1a8e3f..4b1e750b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1434,6 +1434,14 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fibers": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/fibers/-/fibers-4.0.2.tgz", + "integrity": "sha512-FhICi1K4WZh9D6NC18fh2ODF3EWy1z0gzIdV9P7+s2pRjfRBnCkMDJ6x3bV1DkVymKH8HGrQa/FNOBjYvnJ/tQ==", + "requires": { + "detect-libc": "^1.0.3" + } + }, "figures": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.0.0.tgz", diff --git a/package.json b/package.json index fa9482ce..0d19b018 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "bson": "^4.0.3", "bunyan": "^1.8.12", "es6-promise": "^4.2.4", + "fibers": "^4.0.2", "gridfs-stream": "^0.5.3", "ldapjs": "^1.0.2", "meteor-node-stubs": "^0.4.1", diff --git a/server/migrations.js b/server/migrations.js index d7c4c724..3861f227 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1038,3 +1038,10 @@ Migrations.add('fix-incorrect-dates', () => { cas = CFSAttachments.find(); console.log('cas', cas); }); + +Migrations.add('change-attachment-library', () => { + console.log('migration called here'); + Migrations.rollback('change-attachment-library'); + console.log('migration rollbacked'); +}); + -- cgit v1.2.3-1-g7c22 From 0a1bfd37b3b1b2f4108a734c0449c1bd5a1b691f Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Tue, 5 May 2020 14:08:36 +0800 Subject: Migrating attachments --- server/migrations.js | 38 ++++++- server/old-attachments-migration.js | 212 ++++++++++++++++++++++++++++++++++++ 2 files changed, 247 insertions(+), 3 deletions(-) create mode 100644 server/old-attachments-migration.js diff --git a/server/migrations.js b/server/migrations.js index 3861f227..33f061f5 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1039,9 +1039,41 @@ Migrations.add('fix-incorrect-dates', () => { console.log('cas', cas); }); +import { MongoInternals } from 'meteor/mongo'; + Migrations.add('change-attachment-library', () => { - console.log('migration called here'); - Migrations.rollback('change-attachment-library'); - console.log('migration rollbacked'); + const http = require('http'); + const fs = require('fs'); + CFSAttachments.find().forEach(file => { + const bucket = new MongoInternals.NpmModule.GridFSBucket(MongoInternals.defaultRemoteCollectionDriver().mongo.db, {bucketName: 'cfs_gridfs.attachments'}); + const gfsId = new MongoInternals.NpmModule.ObjectID(file.copies.attachments.key); + const reader = bucket.openDownloadStream(gfsId); + const path = `/var/attachments/${file.name()}`; + const fd = fs.createWriteStream(path); + reader.pipe(fd); + let opts = { + fileName: file.name(), + type: file.type(), + fileId: file._id, + meta: { + userId: file.userId, + boardId: file.boardId, + cardId: file.cardId + } + }; + if (file.listId) { + opts.meta.listId = file.listId; + } + if (file.swimlaneId) { + opts.meta.swimlaneId = file.swimlaneId; + } + Attachments.addFile(path, opts, (err, fileRef) => { + if (err) { + console.log('error when migrating ', fileName, err); + } else { + file.remove(); + } + }); + }); }); diff --git a/server/old-attachments-migration.js b/server/old-attachments-migration.js new file mode 100644 index 00000000..3a6aa85d --- /dev/null +++ b/server/old-attachments-migration.js @@ -0,0 +1,212 @@ +const localFSStore = process.env.ATTACHMENTS_STORE_PATH; +const storeName = 'attachments'; +const defaultStoreOptions = { + beforeWrite: fileObj => { + if (!fileObj.isImage()) { + return { + type: 'application/octet-stream', + }; + } + return {}; + }, +}; +let store; +if (localFSStore) { + // have to reinvent methods from FS.Store.GridFS and FS.Store.FileSystem + const fs = Npm.require('fs'); + const path = Npm.require('path'); + const mongodb = Npm.require('mongodb'); + const Grid = Npm.require('gridfs-stream'); + // calulate the absolute path here, because FS.Store.FileSystem didn't expose the aboslutepath or FS.Store didn't expose api calls :( + let pathname = localFSStore; + /*eslint camelcase: ["error", {allow: ["__meteor_bootstrap__"]}] */ + + if (!pathname && __meteor_bootstrap__ && __meteor_bootstrap__.serverDir) { + pathname = path.join( + __meteor_bootstrap__.serverDir, + `../../../cfs/files/${storeName}`, + ); + } + + if (!pathname) + throw new Error('FS.Store.FileSystem unable to determine path'); + + // Check if we have '~/foo/bar' + if (pathname.split(path.sep)[0] === '~') { + const homepath = + process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; + if (homepath) { + pathname = pathname.replace('~', homepath); + } else { + throw new Error('FS.Store.FileSystem unable to resolve "~" in path'); + } + } + + // Set absolute path + const absolutePath = path.resolve(pathname); + + const _FStore = new FS.Store.FileSystem(storeName, { + path: localFSStore, + ...defaultStoreOptions, + }); + const GStore = { + fileKey(fileObj) { + const key = { + _id: null, + filename: null, + }; + + // If we're passed a fileObj, we retrieve the _id and filename from it. + if (fileObj) { + const info = fileObj._getInfo(storeName, { + updateFileRecordFirst: false, + }); + key._id = info.key || null; + key.filename = + info.name || + fileObj.name({ updateFileRecordFirst: false }) || + `${fileObj.collectionName}-${fileObj._id}`; + } + + // If key._id is null at this point, createWriteStream will let GridFS generate a new ID + return key; + }, + db: undefined, + mongoOptions: { useNewUrlParser: true }, + mongoUrl: process.env.MONGO_URL, + init() { + this._init(err => { + this.inited = !err; + }); + }, + _init(callback) { + const self = this; + mongodb.MongoClient.connect(self.mongoUrl, self.mongoOptions, function( + err, + db, + ) { + if (err) { + return callback(err); + } + self.db = db; + return callback(null); + }); + return; + }, + createReadStream(fileKey, options) { + const self = this; + if (!self.inited) { + self.init(); + return undefined; + } + options = options || {}; + + // Init GridFS + const gfs = new Grid(self.db, mongodb); + + // Set the default streamning settings + const settings = { + _id: new mongodb.ObjectID(fileKey._id), + root: `cfs_gridfs.${storeName}`, + }; + + // Check if this should be a partial read + if ( + typeof options.start !== 'undefined' && + typeof options.end !== 'undefined' + ) { + // Add partial info + settings.range = { + startPos: options.start, + endPos: options.end, + }; + } + return gfs.createReadStream(settings); + }, + }; + GStore.init(); + const CRS = 'createReadStream'; + const _CRS = `_${CRS}`; + const FStore = _FStore._transform; + FStore[_CRS] = FStore[CRS].bind(FStore); + FStore[CRS] = function(fileObj, options) { + let stream; + try { + const localFile = path.join( + absolutePath, + FStore.storage.fileKey(fileObj), + ); + const state = fs.statSync(localFile); + if (state) { + stream = FStore[_CRS](fileObj, options); + } + } catch (e) { + // file is not there, try GridFS ? + stream = undefined; + } + if (stream) return stream; + else { + try { + const stream = GStore[CRS](GStore.fileKey(fileObj), options); + return stream; + } catch (e) { + return undefined; + } + } + }.bind(FStore); + store = _FStore; +} else { + store = new FS.Store.GridFS(localFSStore ? `G${storeName}` : storeName, { + // XXX Add a new store for cover thumbnails so we don't load big images in + // the general board view + // If the uploaded document is not an image we need to enforce browser + // download instead of execution. This is particularly important for HTML + // files that the browser will just execute if we don't serve them with the + // appropriate `application/octet-stream` MIME header which can lead to user + // data leaks. I imagine other formats (like PDF) can also be attack vectors. + // See https://github.com/wekan/wekan/issues/99 + // XXX Should we use `beforeWrite` option of CollectionFS instead of + // collection-hooks? + // We should use `beforeWrite`. + ...defaultStoreOptions, + }); +} +CFSAttachments = new FS.Collection('attachments', { + stores: [store], +}); + +if (Meteor.isServer) { + Meteor.startup(() => { + CFSAttachments.files._ensureIndex({ cardId: 1 }); + }); + + CFSAttachments.allow({ + insert(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); + }, + update(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); + }, + remove(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); + }, + // We authorize the attachment download either: + // - if the board is public, everyone (even unconnected) can download it + // - if the board is private, only board members can download it + download(userId, doc) { + if (Meteor.isServer) { + return true; + } + const board = Boards.findOne(doc.boardId); + if (board.isPublic()) { + return true; + } else { + return board.hasMember(userId); + } + }, + + fetch: ['boardId'], + }); +} + +export default CFSAttachments; -- cgit v1.2.3-1-g7c22 From 269698ba780a0af5fe0b24fc3c2c43d1f3f1b49d Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Tue, 5 May 2020 14:18:10 +0800 Subject: Attachments download --- client/components/cards/attachments.jade | 4 +- server/migrate-attachments.js | 263 ------------------------------- 2 files changed, 2 insertions(+), 265 deletions(-) delete mode 100644 server/migrate-attachments.js diff --git a/client/components/cards/attachments.jade b/client/components/cards/attachments.jade index e6e50d7a..57e46e39 100644 --- a/client/components/cards/attachments.jade +++ b/client/components/cards/attachments.jade @@ -29,7 +29,7 @@ template(name="attachmentsGalery") .attachments-galery each attachments .attachment-item - a.attachment-thumbnail.swipebox(href="{{url}}" title="{{name}}") + a.attachment-thumbnail.swipebox(href="{{url}}" download="{{name}}" title="{{name}}") if isUploaded if isImage img.attachment-thumbnail-img(src="{{url}}") @@ -40,7 +40,7 @@ template(name="attachmentsGalery") p.attachment-details = name span.attachment-details-actions - a.js-download(href="{{url download=true}}") + a.js-download(href="{{url download=true}}" download="{{name}}") i.fa.fa-download | {{_ 'download'}} if currentUser.isBoardMember diff --git a/server/migrate-attachments.js b/server/migrate-attachments.js deleted file mode 100644 index 7dcc4d39..00000000 --- a/server/migrate-attachments.js +++ /dev/null @@ -1,263 +0,0 @@ -const localFSStore = process.env.ATTACHMENTS_STORE_PATH; -const storeName = 'attachments'; -const defaultStoreOptions = { - beforeWrite: fileObj => { - if (!fileObj.isImage()) { - return { - type: 'application/octet-stream', - }; - } - return {}; - }, -}; -let store; -if (localFSStore) { - // have to reinvent methods from FS.Store.GridFS and FS.Store.FileSystem - const fs = Npm.require('fs'); - const path = Npm.require('path'); - const mongodb = Npm.require('mongodb'); - const Grid = Npm.require('gridfs-stream'); - // calulate the absolute path here, because FS.Store.FileSystem didn't expose the aboslutepath or FS.Store didn't expose api calls :( - let pathname = localFSStore; - /*eslint camelcase: ["error", {allow: ["__meteor_bootstrap__"]}] */ - - if (!pathname && __meteor_bootstrap__ && __meteor_bootstrap__.serverDir) { - pathname = path.join( - __meteor_bootstrap__.serverDir, - `../../../cfs/files/${storeName}`, - ); - } - - if (!pathname) - throw new Error('FS.Store.FileSystem unable to determine path'); - - // Check if we have '~/foo/bar' - if (pathname.split(path.sep)[0] === '~') { - const homepath = - process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; - if (homepath) { - pathname = pathname.replace('~', homepath); - } else { - throw new Error('FS.Store.FileSystem unable to resolve "~" in path'); - } - } - - // Set absolute path - const absolutePath = path.resolve(pathname); - - const _FStore = new FS.Store.FileSystem(storeName, { - path: localFSStore, - ...defaultStoreOptions, - }); - const GStore = { - fileKey(fileObj) { - const key = { - _id: null, - filename: null, - }; - - // If we're passed a fileObj, we retrieve the _id and filename from it. - if (fileObj) { - const info = fileObj._getInfo(storeName, { - updateFileRecordFirst: false, - }); - key._id = info.key || null; - key.filename = - info.name || - fileObj.name({ updateFileRecordFirst: false }) || - `${fileObj.collectionName}-${fileObj._id}`; - } - - // If key._id is null at this point, createWriteStream will let GridFS generate a new ID - return key; - }, - db: undefined, - mongoOptions: { useNewUrlParser: true }, - mongoUrl: process.env.MONGO_URL, - init() { - this._init(err => { - this.inited = !err; - }); - }, - _init(callback) { - const self = this; - mongodb.MongoClient.connect(self.mongoUrl, self.mongoOptions, function( - err, - db, - ) { - if (err) { - return callback(err); - } - self.db = db; - return callback(null); - }); - return; - }, - createReadStream(fileKey, options) { - const self = this; - if (!self.inited) { - self.init(); - return undefined; - } - options = options || {}; - - // Init GridFS - const gfs = new Grid(self.db, mongodb); - - // Set the default streamning settings - const settings = { - _id: new mongodb.ObjectID(fileKey._id), - root: `cfs_gridfs.${storeName}`, - }; - - // Check if this should be a partial read - if ( - typeof options.start !== 'undefined' && - typeof options.end !== 'undefined' - ) { - // Add partial info - settings.range = { - startPos: options.start, - endPos: options.end, - }; - } - return gfs.createReadStream(settings); - }, - }; - GStore.init(); - const CRS = 'createReadStream'; - const _CRS = `_${CRS}`; - const FStore = _FStore._transform; - FStore[_CRS] = FStore[CRS].bind(FStore); - FStore[CRS] = function(fileObj, options) { - let stream; - try { - const localFile = path.join( - absolutePath, - FStore.storage.fileKey(fileObj), - ); - const state = fs.statSync(localFile); - if (state) { - stream = FStore[_CRS](fileObj, options); - } - } catch (e) { - // file is not there, try GridFS ? - stream = undefined; - } - if (stream) return stream; - else { - try { - const stream = GStore[CRS](GStore.fileKey(fileObj), options); - return stream; - } catch (e) { - return undefined; - } - } - }.bind(FStore); - store = _FStore; -} else { - store = new FS.Store.GridFS(localFSStore ? `G${storeName}` : storeName, { - // XXX Add a new store for cover thumbnails so we don't load big images in - // the general board view - // If the uploaded document is not an image we need to enforce browser - // download instead of execution. This is particularly important for HTML - // files that the browser will just execute if we don't serve them with the - // appropriate `application/octet-stream` MIME header which can lead to user - // data leaks. I imagine other formats (like PDF) can also be attack vectors. - // See https://github.com/wekan/wekan/issues/99 - // XXX Should we use `beforeWrite` option of CollectionFS instead of - // collection-hooks? - // We should use `beforeWrite`. - ...defaultStoreOptions, - }); -} -CFSAttachments = new FS.Collection('attachments', { - stores: [store], -}); - -if (Meteor.isServer) { - Meteor.startup(() => { - CFSAttachments.files._ensureIndex({ cardId: 1 }); - }); - - CFSAttachments.allow({ - insert(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - update(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - remove(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - // We authorize the attachment download either: - // - if the board is public, everyone (even unconnected) can download it - // - if the board is private, only board members can download it - download(userId, doc) { - const board = Boards.findOne(doc.boardId); - if (board.isPublic()) { - return true; - } else { - return board.hasMember(userId); - } - }, - - fetch: ['boardId'], - }); -} - -// XXX Enforce a schema for the Attachments CollectionFS - -if (Meteor.isServer) { - CFSAttachments.files.after.insert((userId, doc) => { - // If the attachment doesn't have a source field - // or its source is different than import - if (!doc.source || doc.source !== 'import') { - // Add activity about adding the attachment - Activities.insert({ - userId, - type: 'card', - activityType: 'addAttachment', - attachmentId: doc._id, - boardId: doc.boardId, - cardId: doc.cardId, - listId: doc.listId, - swimlaneId: doc.swimlaneId, - }); - } else { - // Don't add activity about adding the attachment as the activity - // be imported and delete source field - CFSAttachments.update( - { - _id: doc._id, - }, - { - $unset: { - source: '', - }, - }, - ); - } - }); - - CFSAttachments.files.before.remove((userId, doc) => { - Activities.insert({ - userId, - type: 'card', - activityType: 'deleteAttachment', - attachmentId: doc._id, - boardId: doc.boardId, - cardId: doc.cardId, - listId: doc.listId, - swimlaneId: doc.swimlaneId, - }); - }); - - CFSAttachments.files.after.remove((userId, doc) => { - Activities.remove({ - attachmentId: doc._id, - }); - }); -} - -export default CFSAttachments; -- cgit v1.2.3-1-g7c22 From 7dc0bbd7b26ef50ebd6c0a4d719658c2d288c2d3 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Wed, 6 May 2020 11:15:01 +0800 Subject: Set correct storage location --- server/migrations.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/migrations.js b/server/migrations.js index 33f061f5..b02ca246 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1048,7 +1048,11 @@ Migrations.add('change-attachment-library', () => { const bucket = new MongoInternals.NpmModule.GridFSBucket(MongoInternals.defaultRemoteCollectionDriver().mongo.db, {bucketName: 'cfs_gridfs.attachments'}); const gfsId = new MongoInternals.NpmModule.ObjectID(file.copies.attachments.key); const reader = bucket.openDownloadStream(gfsId); - const path = `/var/attachments/${file.name()}`; + let store = Attachments.storagePath(); + if (store.charAt(store.length - 1) === '/') { + store = store.substring(0, store.length - 1); + } + const path = `${store}/${file.name()}`; const fd = fs.createWriteStream(path); reader.pipe(fd); let opts = { -- cgit v1.2.3-1-g7c22 From 444848876759173ad80203129250d2f0311f30fc Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Fri, 8 May 2020 09:32:19 +0800 Subject: Done attachments activities operating --- client/components/activities/activities.js | 7 +- models/activities.js | 6 +- models/attachments.js | 241 ++++++++--------------------- 3 files changed, 70 insertions(+), 184 deletions(-) diff --git a/client/components/activities/activities.js b/client/components/activities/activities.js index b082273a..9697d28c 100644 --- a/client/components/activities/activities.js +++ b/client/components/activities/activities.js @@ -152,17 +152,18 @@ BlazeComponent.extendComponent({ attachmentLink() { const attachment = this.currentData().attachment(); + const link = attachment.link('original', '/'); // trying to display url before file is stored generates js errors return ( attachment && - attachment.url({ download: true }) && + link && Blaze.toHTML( HTML.A( { - href: attachment.url({ download: true }), + href: link, target: '_blank', }, - attachment.name(), + attachment.get('name'), ), ) ); diff --git a/models/activities.js b/models/activities.js index 19e3fb7d..3f8a0d35 100644 --- a/models/activities.js +++ b/models/activities.js @@ -214,7 +214,11 @@ if (Meteor.isServer) { } if (activity.attachmentId) { const attachment = activity.attachment(); - params.attachment = attachment.original.name; + if (attachment.original) { + params.attachment = attachment.original.name; + } else { + params.attachment = attachment.versions.original.name; + } params.attachmentId = attachment._id; } if (activity.checklistId) { diff --git a/models/attachments.js b/models/attachments.js index c35d3d4c..798d04be 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -1,13 +1,15 @@ import { FilesCollection } from 'meteor/ostrio:files'; +const collectionName = 'attachments2'; + Attachments = new FilesCollection({ storagePath: storagePath(), - debug: false, // FIXME: Remove debug mode + debug: false, + allowClientCode: true, collectionName: 'attachments2', - allowClientCode: true, // FIXME: Permissions - onAfterUpload: (fileRef) => { - Attachments.update({_id:fileRef._id}, {$set: {"meta.uploaded": true}}); - } + onAfterUpload: onAttachmentUploaded, + onBeforeRemove: onAttachmentRemoving, + onAfterRemove: onAttachmentRemoved }); if (Meteor.isServer) { @@ -17,194 +19,73 @@ if (Meteor.isServer) { // TODO: Permission related // TODO: Add Activity update - // TODO: publish and subscribe - Meteor.publish('attachments2', function() { + Meteor.publish(collectionName, function() { return Attachments.find().cursor; }); } else { - Meteor.subscribe('attachments2'); + Meteor.subscribe(collectionName); } -// ---------- Deprecated fallback ---------- // - -const localFSStore = process.env.ATTACHMENTS_STORE_PATH; -const storeName = 'attachments2'; -const defaultStoreOptions = { - beforeWrite: fileObj => { - if (!fileObj.isImage()) { - return { - type: 'application/octet-stream', - }; - } - return {}; - }, -}; -let store; -if (localFSStore) { - // have to reinvent methods from FS.Store.GridFS and FS.Store.FileSystem - const fs = Npm.require('fs'); - const path = Npm.require('path'); - const mongodb = Npm.require('mongodb'); - const Grid = Npm.require('gridfs-stream'); - // calulate the absolute path here, because FS.Store.FileSystem didn't expose the aboslutepath or FS.Store didn't expose api calls :( - let pathname = localFSStore; - /*eslint camelcase: ["error", {allow: ["__meteor_bootstrap__"]}] */ +function storagePath(defaultPath) { + const storePath = process.env.ATTACHMENTS_STORE_PATH; + return storePath ? storePath : defaultPath; +} - if (!pathname && __meteor_bootstrap__ && __meteor_bootstrap__.serverDir) { - pathname = path.join( - __meteor_bootstrap__.serverDir, - `../../../cfs/files/${storeName}`, +function onAttachmentUploaded(fileRef) { + Attachments.update({_id:fileRef._id}, {$set: {"meta.uploaded": true}}); + if (!fileRef.meta.source || fileRef.meta.source !== 'import') { + // Add activity about adding the attachment + Activities.insert({ + userId: fileRef.userId, + type: 'card', + activityType: 'addAttachment', + attachmentId: fileRef._id, + boardId: fileRef.meta.boardId, + cardId: fileRef.meta.cardId, + listId: fileRef.meta.listId, + swimlaneId: fileRef.meta.swimlaneId, + }); + } else { + // Don't add activity about adding the attachment as the activity + // be imported and delete source field + CFSAttachments.update( + { + _id: fileRef._id, + }, + { + $unset: { + source: '', + }, + }, ); } +} - if (!pathname) - throw new Error('FS.Store.FileSystem unable to determine path'); - - // Check if we have '~/foo/bar' - if (pathname.split(path.sep)[0] === '~') { - const homepath = - process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; - if (homepath) { - pathname = pathname.replace('~', homepath); - } else { - throw new Error('FS.Store.FileSystem unable to resolve "~" in path'); - } - } - - // Set absolute path - const absolutePath = path.resolve(pathname); - - const _FStore = new FS.Store.FileSystem(storeName, { - path: localFSStore, - ...defaultStoreOptions, - }); - const GStore = { - fileKey(fileObj) { - const key = { - _id: null, - filename: null, - }; - - // If we're passed a fileObj, we retrieve the _id and filename from it. - if (fileObj) { - const info = fileObj._getInfo(storeName, { - updateFileRecordFirst: false, - }); - key._id = info.key || null; - key.filename = - info.name || - fileObj.name({ updateFileRecordFirst: false }) || - `${fileObj.collectionName}-${fileObj._id}`; - } - - // If key._id is null at this point, createWriteStream will let GridFS generate a new ID - return key; - }, - db: undefined, - mongoOptions: { useNewUrlParser: true }, - mongoUrl: process.env.MONGO_URL, - init() { - this._init(err => { - this.inited = !err; - }); - }, - _init(callback) { - const self = this; - mongodb.MongoClient.connect(self.mongoUrl, self.mongoOptions, function( - err, - db, - ) { - if (err) { - return callback(err); - } - self.db = db; - return callback(null); - }); - return; - }, - createReadStream(fileKey, options) { - const self = this; - if (!self.inited) { - self.init(); - return undefined; - } - options = options || {}; - - // Init GridFS - const gfs = new Grid(self.db, mongodb); - - // Set the default streamning settings - const settings = { - _id: new mongodb.ObjectID(fileKey._id), - root: `cfs_gridfs.${storeName}`, - }; - - // Check if this should be a partial read - if ( - typeof options.start !== 'undefined' && - typeof options.end !== 'undefined' - ) { - // Add partial info - settings.range = { - startPos: options.start, - endPos: options.end, - }; - } - return gfs.createReadStream(settings); - }, - }; - GStore.init(); - const CRS = 'createReadStream'; - const _CRS = `_${CRS}`; - const FStore = _FStore._transform; - FStore[_CRS] = FStore[CRS].bind(FStore); - FStore[CRS] = function(fileObj, options) { - let stream; - try { - const localFile = path.join( - absolutePath, - FStore.storage.fileKey(fileObj), - ); - const state = fs.statSync(localFile); - if (state) { - stream = FStore[_CRS](fileObj, options); - } - } catch (e) { - // file is not there, try GridFS ? - stream = undefined; - } - if (stream) return stream; - else { - try { - const stream = GStore[CRS](GStore.fileKey(fileObj), options); - return stream; - } catch (e) { - return undefined; - } - } - }.bind(FStore); - store = _FStore; -} else { - store = new FS.Store.GridFS(localFSStore ? `G${storeName}` : storeName, { - // XXX Add a new store for cover thumbnails so we don't load big images in - // the general board view - // If the uploaded document is not an image we need to enforce browser - // download instead of execution. This is particularly important for HTML - // files that the browser will just execute if we don't serve them with the - // appropriate `application/octet-stream` MIME header which can lead to user - // data leaks. I imagine other formats (like PDF) can also be attack vectors. - // See https://github.com/wekan/wekan/issues/99 - // XXX Should we use `beforeWrite` option of CollectionFS instead of - // collection-hooks? - // We should use `beforeWrite`. - ...defaultStoreOptions, +function onAttachmentRemoving(cursor) { + const file = cursor.get()[0]; + const meta = file.meta; + Activities.insert({ + userId: this.userId, + type: 'card', + activityType: 'deleteAttachment', + attachmentId: file._id, + boardId: meta.boardId, + cardId: meta.cardId, + listId: meta.listId, + swimlaneId: meta.swimlaneId, }); + return true; } -function storagePath(defaultPath) { - const storePath = process.env.ATTACHMENTS_STORE_PATH; - return storePath ? storePath : defaultPath; +function onAttachmentRemoved(files) { + // Don't know why we need to remove the activity +/* for (let i in files) { + let doc = files[i]; + Activities.remove({ + attachmentId: doc._id, + }); + }*/ } export default Attachments; -- cgit v1.2.3-1-g7c22 From 012ca39a8dc29517aef191e85325f3e5889daf37 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Fri, 8 May 2020 11:50:43 +0800 Subject: Attachment activities merging done --- .meteor/packages | 1 + .meteor/versions | 1 + client/components/activities/activities.js | 2 +- models/activities.js | 6 +----- models/attachments.js | 21 +++++---------------- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index ba278f34..b0df2be8 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -98,3 +98,4 @@ percolate:synced-cron easylogic:summernote cfs:filesystem ostrio:cookies +ostrio:files diff --git a/.meteor/versions b/.meteor/versions index 5157f679..23aa4804 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -134,6 +134,7 @@ observe-sequence@1.0.16 ongoworks:speakingurl@1.1.0 ordered-dict@1.1.0 ostrio:cookies@2.6.0 +ostrio:files@1.14.2 peerlibrary:assert@0.3.0 peerlibrary:base-component@0.16.0 peerlibrary:blaze-components@0.15.1 diff --git a/client/components/activities/activities.js b/client/components/activities/activities.js index 72af4c35..186200ec 100644 --- a/client/components/activities/activities.js +++ b/client/components/activities/activities.js @@ -163,7 +163,7 @@ BlazeComponent.extendComponent({ href: link, target: '_blank', }, - attachment.name(), + attachment.name, ), )) || this.currentData().activity.attachmentName diff --git a/models/activities.js b/models/activities.js index df207bca..2663dd29 100644 --- a/models/activities.js +++ b/models/activities.js @@ -217,11 +217,7 @@ if (Meteor.isServer) { } if (activity.attachmentId) { const attachment = activity.attachment(); - if (attachment.original) { - params.attachment = attachment.original.name; - } else { - params.attachment = attachment.versions.original.name; - } + params.attachment = attachment.name; params.attachmentId = attachment._id; } if (activity.checklistId) { diff --git a/models/attachments.js b/models/attachments.js index cab3d9e3..d469f702 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -8,8 +8,7 @@ Attachments = new FilesCollection({ allowClientCode: true, collectionName: 'attachments2', onAfterUpload: onAttachmentUploaded, - onBeforeRemove: onAttachmentRemoving, - onAfterRemove: onAttachmentRemoved + onBeforeRemove: onAttachmentRemoving }); if (Meteor.isServer) { @@ -41,9 +40,9 @@ function onAttachmentUploaded(fileRef) { type: 'card', activityType: 'addAttachment', attachmentId: fileRef._id, - // this preserves the name so that notifications can be meaningful after + // this preserves the name so that notifications can be meaningful after // this file is removed - attachmentName: fileRef.versions.original.name, + attachmentName: fileRef.name, boardId: fileRef.meta.boardId, cardId: fileRef.meta.cardId, listId: fileRef.meta.listId, @@ -73,9 +72,9 @@ function onAttachmentRemoving(cursor) { type: 'card', activityType: 'deleteAttachment', attachmentId: file._id, - // this preserves the name so that notifications can be meaningful after + // this preserves the name so that notifications can be meaningful after // this file is removed - attachmentName: file.versions.original.name, + attachmentName: file.name, boardId: meta.boardId, cardId: meta.cardId, listId: meta.listId, @@ -84,14 +83,4 @@ function onAttachmentRemoving(cursor) { return true; } -function onAttachmentRemoved(files) { - // Don't know why we need to remove the activity -/* for (let i in files) { - let doc = files[i]; - Activities.remove({ - attachmentId: doc._id, - }); - }*/ -} - export default Attachments; -- cgit v1.2.3-1-g7c22 From 4c5a2fbd1f8ad2f2447235442bf96b893f18a409 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Thu, 14 May 2020 14:55:54 +0800 Subject: Card clone OK --- models/attachments.js | 35 +++++++++++++++++++++++++++++++++-- models/cards.js | 12 ++++++++---- server/migrations.js | 3 +-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/models/attachments.js b/models/attachments.js index d469f702..1a55cb85 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -1,4 +1,5 @@ import { FilesCollection } from 'meteor/ostrio:files'; +const fs = require('fs'); const collectionName = 'attachments2'; @@ -19,6 +20,36 @@ if (Meteor.isServer) { // TODO: Permission related // TODO: Add Activity update + Meteor.methods({ + cloneAttachment(file, overrides) { + check(file, Object); + check(overrides, Match.Maybe(Object)); + const path = file.path; + const opts = { + fileName: file.name, + type: file.type, + meta: file.meta, + userId: file.userId + }; + for (let key in overrides) { + if (key === 'meta') { + for (let metaKey in overrides.meta) { + opts.meta[metaKey] = overrides.meta[metaKey]; + } + } else { + opts[key] = overrides[key]; + } + } + const buffer = fs.readFileSync(path); + Attachments.write(buffer, opts, (err, fileRef) => { + if (err) { + console.log('Error when cloning record', err); + } + }); + return true; + } + }); + Meteor.publish(collectionName, function() { return Attachments.find().cursor; }); @@ -51,13 +82,13 @@ function onAttachmentUploaded(fileRef) { } else { // Don't add activity about adding the attachment as the activity // be imported and delete source field - CFSAttachments.update( + Attachments.collection.update( { _id: fileRef._id, }, { $unset: { - source: '', + 'meta.source': '', }, }, ); diff --git a/models/cards.js b/models/cards.js index 1236de1a..ae52ff04 100644 --- a/models/cards.js +++ b/models/cards.js @@ -402,10 +402,14 @@ Cards.helpers({ const _id = Cards.insert(this); // Copy attachments - oldCard.attachments().forEach(att => { - att.meta.cardId = _id; - delete att._id; - return Attachments.insert(att); + oldCard.attachments().forEach((file) => { + Meteor.call('cloneAttachment', file, + { + meta: { + cardId: _id + } + } + ); }); // copy checklists diff --git a/server/migrations.js b/server/migrations.js index e330f043..3577c78d 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1061,6 +1061,7 @@ Migrations.add('change-attachment-library', () => { let opts = { fileName: file.name(), type: file.type(), + size: file.size(), fileId: file._id, meta: { userId: file.userId, @@ -1077,8 +1078,6 @@ Migrations.add('change-attachment-library', () => { Attachments.addFile(path, opts, (err, fileRef) => { if (err) { console.log('error when migrating ', fileName, err); - } else { - file.remove(); } }); }); -- cgit v1.2.3-1-g7c22 From 09ce3e464fd609b3ecc8bec5263ab06093c3a442 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Thu, 14 May 2020 16:43:59 +0800 Subject: Fix typo --- server/migrations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/migrations.js b/server/migrations.js index 3577c78d..840ab170 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1077,7 +1077,7 @@ Migrations.add('change-attachment-library', () => { } Attachments.addFile(path, opts, (err, fileRef) => { if (err) { - console.log('error when migrating ', fileName, err); + console.log('error when migrating ', fileRef.name, err); } }); }); -- cgit v1.2.3-1-g7c22 From b80396f627665119cd38f11f2d466ce53ec573ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E4=BB=B2=E6=98=8E=20=28Romulus=20Urakagi=20Tsai?= =?UTF-8?q?=29?= Date: Thu, 14 May 2020 17:36:57 +0800 Subject: Purge unneeded require --- server/migrations.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/migrations.js b/server/migrations.js index 840ab170..bf019312 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1045,7 +1045,6 @@ Migrations.add('add-sort-field-to-boards', () => { import { MongoInternals } from 'meteor/mongo'; Migrations.add('change-attachment-library', () => { - const http = require('http'); const fs = require('fs'); CFSAttachments.find().forEach(file => { const bucket = new MongoInternals.NpmModule.GridFSBucket(MongoInternals.defaultRemoteCollectionDriver().mongo.db, {bucketName: 'cfs_gridfs.attachments'}); -- cgit v1.2.3-1-g7c22 From 4064f3f4063136c97aa7bcbcdc18fec923934b74 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Wed, 20 May 2020 15:11:22 +0800 Subject: Fix migrated attachment not readable bug Remove reduandant files --- ...242+\347\254\254\344\272\214\346\263\242).xlsx" | Bin 29409 -> 0 bytes client/components/cards/attachments.js | 5 ++- client/lib/utils.js | 4 +- models/attachments.js | 16 ++++++-- server/migrations.js | 44 +++++++++++---------- 5 files changed, 43 insertions(+), 26 deletions(-) delete mode 100644 "atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" diff --git "a/atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" "b/atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" deleted file mode 100644 index 4e89ac5d..00000000 Binary files "a/atachments/attachments-gAjLYeSrtAneFBdzt-\346\217\220\350\255\260\350\200\205\351\233\273\345\255\220\351\203\265\344\273\266(\347\254\254\344\270\200\346\263\242+\347\254\254\344\272\214\346\263\242).xlsx" and /dev/null differ diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index 82ecabcf..81f6c6e1 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -50,7 +50,10 @@ Template.attachmentsGalery.helpers({ return Attachments.link(this, 'original', '/'); }, isUploaded() { - return !!this.meta.uploaded; + return !this.meta.uploading; + }, + isImage() { + return !!this.isImage; }, }); diff --git a/client/lib/utils.js b/client/lib/utils.js index d712cc73..e72f177e 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -70,7 +70,9 @@ Utils = { streams: 'dynamic', chunkSize: 'dynamic', }; - settings.meta = {}; + settings.meta = { + uploading: true + }; if (card.isLinkedCard()) { settings.meta.boardId = Cards.findOne(card.linkedId).boardId; settings.meta.cardId = card.linkedId; diff --git a/models/attachments.js b/models/attachments.js index 1a55cb85..03999f55 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -6,7 +6,7 @@ const collectionName = 'attachments2'; Attachments = new FilesCollection({ storagePath: storagePath(), debug: false, - allowClientCode: true, +// allowClientCode: true, collectionName: 'attachments2', onAfterUpload: onAttachmentUploaded, onBeforeRemove: onAttachmentRemoving @@ -18,7 +18,17 @@ if (Meteor.isServer) { }); // TODO: Permission related - // TODO: Add Activity update + Attachments.allow({ + insert() { + return false; + }, + update() { + return true; + }, + remove() { + return true; + } + }); Meteor.methods({ cloneAttachment(file, overrides) { @@ -63,7 +73,7 @@ function storagePath(defaultPath) { } function onAttachmentUploaded(fileRef) { - Attachments.update({_id:fileRef._id}, {$set: {"meta.uploaded": true}}); + Attachments.update({_id:fileRef._id}, {$set: {"meta.uploading": false}}); if (!fileRef.meta.source || fileRef.meta.source !== 'import') { // Add activity about adding the attachment Activities.insert({ diff --git a/server/migrations.js b/server/migrations.js index 840ab170..887a60e4 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -80,7 +80,7 @@ Migrations.add('lowercase-board-permission', () => { Migrations.add('change-attachments-type-for-non-images', () => { const newTypeForNonImage = 'application/octet-stream'; Attachments.find().forEach(file => { - if (!file.isImage()) { + if (!file.isImage) { Attachments.update( file._id, { @@ -1058,27 +1058,29 @@ Migrations.add('change-attachment-library', () => { const path = `${store}/${file.name()}`; const fd = fs.createWriteStream(path); reader.pipe(fd); - let opts = { - fileName: file.name(), - type: file.type(), - size: file.size(), - fileId: file._id, - meta: { - userId: file.userId, - boardId: file.boardId, - cardId: file.cardId - } - }; - if (file.listId) { - opts.meta.listId = file.listId; - } - if (file.swimlaneId) { - opts.meta.swimlaneId = file.swimlaneId; - } - Attachments.addFile(path, opts, (err, fileRef) => { - if (err) { - console.log('error when migrating ', fileRef.name, err); + reader.on('end', () => { + let opts = { + fileName: file.name(), + type: file.type(), + size: file.size(), + fileId: file._id, + meta: { + userId: file.userId, + boardId: file.boardId, + cardId: file.cardId + } + }; + if (file.listId) { + opts.meta.listId = file.listId; } + if (file.swimlaneId) { + opts.meta.swimlaneId = file.swimlaneId; + } + Attachments.addFile(path, opts, (err, fileRef) => { + if (err) { + console.log('error when migrating', file.name(), err); + } + }); }); }); }); -- cgit v1.2.3-1-g7c22 From 4156073b1a5d18ec70a00571ffccdd504b99098a Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Fri, 22 May 2020 14:53:10 +0800 Subject: Fix translation error --- i18n/zh-TW.i18n.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i18n/zh-TW.i18n.json b/i18n/zh-TW.i18n.json index ac923fef..c4b155dc 100644 --- a/i18n/zh-TW.i18n.json +++ b/i18n/zh-TW.i18n.json @@ -747,7 +747,7 @@ "error-ldap-login": "嘗試登入時出現錯誤", "display-authentication-method": "顯示認證方式", "default-authentication-method": "預設認證方式", - "duplicate-board": "重複的看板", + "duplicate-board": "複製看板", "people-number": "人數是:", "swimlaneDeletePopup-title": "是否刪除泳道?", "swimlane-delete-pop": "所有動作將從活動來源中刪除,您將無法恢復泳道。此操作無法還原。", -- cgit v1.2.3-1-g7c22 From 921460db4031134db863e32101c0ad60a17416b5 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Fri, 22 May 2020 14:59:56 +0800 Subject: Fix export attachments (not tested) --- models/export.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/export.js b/models/export.js index 35e55804..1eb47e54 100644 --- a/models/export.js +++ b/models/export.js @@ -146,7 +146,7 @@ export class Exporter { `tmpexport${process.pid}${Math.random()}`, ); const tmpWriteable = fs.createWriteStream(tmpFile); - const readStream = doc.createReadStream(); + const readStream = fs.createReadStream(doc.path); readStream.on('data', function(chunk) { buffer = Buffer.concat([buffer, chunk]); }); @@ -173,11 +173,11 @@ export class Exporter { return { _id: attachment._id, - cardId: attachment.cardId, + cardId: attachment.meta.cardId, //url: FlowRouter.url(attachment.url()), file: filebase64, - name: attachment.original.name, - type: attachment.original.type, + name: attachment.name, + type: attachment.type, }; }); -- cgit v1.2.3-1-g7c22