Attachment upload from card done, need to fix download link

This commit is contained in:
Romulus Urakagi Tsai 2019-11-20 10:40:09 +00:00
parent 05c53ca01d
commit 4dcdec0084
9 changed files with 49 additions and 27 deletions

View file

@ -45,18 +45,31 @@ Template.attachmentsGalery.events({
}, },
}); });
Template.attachmentsGalery.helpers({
url() {
return Attachments.link(this);
}
});
Template.previewAttachedImagePopup.events({ Template.previewAttachedImagePopup.events({
'click .js-large-image-clicked'() { 'click .js-large-image-clicked'() {
Popup.close(); Popup.close();
}, },
}); });
Template.previewAttachedImagePopup.helpers({
url() {
return Attachments.link(this);
}
});
Template.cardAttachmentsPopup.events({ Template.cardAttachmentsPopup.events({
'change .js-attach-file'(event) { 'change .js-attach-file'(event) {
const card = this; const card = this;
const processFile = f => { const processFile = f => {
Utils.processUploadedAttachment(card, f, attachment => { 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); card.setCover(attachment._id);
} }
Popup.close(); Popup.close();
@ -152,13 +165,14 @@ Template.previewClipboardImagePopup.events({
const settings = { const settings = {
file: results.file, file: results.file,
streams: 'dynamic', streams: 'dynamic',
chunkSize: 'dynamic' chunkSize: 'dynamic',
}; };
if (!results.name) { if (!results.name) {
// if no filename, it's from clipboard. then we give it a name, with ext name from MIME type // if no filename, it's from clipboard. then we give it a name, with ext name from MIME type
// FIXME: Check this behavior // FIXME: Check this behavior
if (typeof results.file.type === 'string') { 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 = {}; settings.meta = {};
@ -166,8 +180,7 @@ Template.previewClipboardImagePopup.events({
settings.meta.boardId = card.boardId; settings.meta.boardId = card.boardId;
settings.meta.cardId = card._id; settings.meta.cardId = card._id;
settings.meta.userId = Meteor.userId(); settings.meta.userId = Meteor.userId();
console.log('settings', settings); const attachment = Attachments.insert(settings);
const attachment = Attachments.insert(settings, false);
// TODO: Check image cover behavior // TODO: Check image cover behavior
if (attachment && attachment._id && attachment.isImage) { if (attachment && attachment._id && attachment.isImage) {

View file

@ -229,18 +229,14 @@ Template.editor.onRendered(() => {
currentCard, currentCard,
fileObj, fileObj,
attachment => { attachment => {
if ( if (attachment && attachment._id && attachment.isImage) {
attachment &&
attachment._id &&
attachment.isImage()
) {
attachment.one('uploaded', function() { attachment.one('uploaded', function() {
const maxTry = 3; const maxTry = 3;
const checkItvl = 500; const checkItvl = 500;
let retry = 0; let retry = 0;
const checkUrl = function() { const checkUrl = function() {
// even though uploaded event fired, attachment.url() is still null somehow //TODO // even though uploaded event fired, attachment.url() is still null somehow //TODO
const url = attachment.url(); const url = attachment.link();
if (url) { if (url) {
insertImage( insertImage(
`${location.protocol}//${location.host}${url}`, `${location.protocol}//${location.host}${url}`,

View file

@ -37,7 +37,15 @@ Utils = {
let settings = { let settings = {
file: fileObj, file: fileObj,
streams: 'dynamic', 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 = {}; settings.meta = {};
if (card.isLinkedCard()) { if (card.isLinkedCard()) {
@ -51,10 +59,10 @@ Utils = {
} }
settings.meta.userId = Meteor.userId(); settings.meta.userId = Meteor.userId();
// FIXME: What is this? // FIXME: What is this?
/* if (file.original) { /* if (file.original) {
file.original.name = fileObj.name; file.original.name = fileObj.name;
}*/ }*/
return next(Attachments.insert(settings, false)); Attachments.insert(settings);
}, },
shrinkImage(options) { shrinkImage(options) {
// shrink image to certain size // shrink image to certain size

View file

@ -4,7 +4,7 @@ Attachments = new FilesCollection({
storagePath: storagePath(), storagePath: storagePath(),
debug: true, // FIXME: Remove debug mode debug: true, // FIXME: Remove debug mode
collectionName: 'attachments2', collectionName: 'attachments2',
allowClientCode: false, // Disallow remove files from Client allowClientCode: true, // FIXME: Permissions
}); });
if (Meteor.isServer) { if (Meteor.isServer) {
@ -15,11 +15,11 @@ if (Meteor.isServer) {
// TODO: Permission related // TODO: Permission related
// TODO: Add Activity update // TODO: Add Activity update
// TODO: publish and subscribe // TODO: publish and subscribe
// Meteor.publish('files.attachments.all', function () { Meteor.publish('attachments', function() {
// return Attachments.find().cursor; return Attachments.find().cursor;
// }); });
} else { } else {
// Meteor.subscribe('files.attachments.all'); Meteor.subscribe('attachments');
} }
// ---------- Deprecated fallback ---------- // // ---------- Deprecated fallback ---------- //

View file

@ -366,7 +366,7 @@ Cards.helpers({
// Copy attachments // Copy attachments
oldCard.attachments().forEach(att => { oldCard.attachments().forEach(att => {
att.cardId = _id; att.meta.cardId = _id;
delete att._id; delete att._id;
return Attachments.insert(att); return Attachments.insert(att);
}); });
@ -456,14 +456,16 @@ Cards.helpers({
attachments() { attachments() {
if (this.isLinkedCard()) { if (this.isLinkedCard()) {
return Attachments.find( return Attachments.find(
{ cardId: this.linkedId }, { 'meta.cardId': this.linkedId },
{ sort: { uploadedAt: -1 } }, { sort: { uploadedAt: -1 } },
); );
} else { } else {
return Attachments.find( const ret = Attachments.find(
{ cardId: this._id }, { 'meta.cardId': this._id },
{ sort: { uploadedAt: -1 } }, { 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); 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 // 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? // todo XXX we could return a default "upload pending" image in the meantime?
return cover && cover.url() && cover; return cover && cover.link();
}, },
checklists() { checklists() {

View file

@ -162,7 +162,7 @@ export class Exporter {
readStream.pipe(tmpWriteable); readStream.pipe(tmpWriteable);
}; };
const getBase64DataSync = Meteor.wrapAsync(getBase64Data); const getBase64DataSync = Meteor.wrapAsync(getBase64Data);
result.attachments = Attachments.find(byBoard) result.attachments = Attachments.find({ 'meta.boardId': byBoard.boardId })
.fetch() .fetch()
.map(attachment => { .map(attachment => {
return { return {

View file

@ -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. // so we make it server only, and let UI catch up once it is done, forget about latency comp.
const self = this; const self = this;
if (Meteor.isServer) { if (Meteor.isServer) {
// FIXME: Change to new model
file.attachData(att.url, function(error) { file.attachData(att.url, function(error) {
file.boardId = boardId; file.boardId = boardId;
file.cardId = cardId; file.cardId = cardId;

View file

@ -415,6 +415,7 @@ export class WekanCreator {
const self = this; const self = this;
if (Meteor.isServer) { if (Meteor.isServer) {
if (att.url) { if (att.url) {
// FIXME: Change to new file library
file.attachData(att.url, function(error) { file.attachData(att.url, function(error) {
file.boardId = boardId; file.boardId = boardId;
file.cardId = cardId; file.cardId = cardId;
@ -440,6 +441,7 @@ export class WekanCreator {
} }
}); });
} else if (att.file) { } else if (att.file) {
// FIXME: Change to new file library
file.attachData( file.attachData(
new Buffer(att.file, 'base64'), new Buffer(att.file, 'base64'),
{ {

View file

@ -80,7 +80,7 @@ Migrations.add('lowercase-board-permission', () => {
Migrations.add('change-attachments-type-for-non-images', () => { Migrations.add('change-attachments-type-for-non-images', () => {
const newTypeForNonImage = 'application/octet-stream'; const newTypeForNonImage = 'application/octet-stream';
Attachments.find().forEach(file => { Attachments.find().forEach(file => {
if (!file.isImage()) { if (!file.isImage) {
Attachments.update( Attachments.update(
file._id, file._id,
{ {
@ -97,7 +97,7 @@ Migrations.add('change-attachments-type-for-non-images', () => {
Migrations.add('card-covers', () => { Migrations.add('card-covers', () => {
Cards.find().forEach(card => { 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) { if (cover) {
Cards.update(card._id, { $set: { coverId: cover._id } }, noValidate); Cards.update(card._id, { $set: { coverId: cover._id } }, noValidate);
} }