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({
'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) {

View file

@ -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}`,

View file

@ -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()) {
@ -54,7 +62,7 @@ Utils = {
/* if (file.original) {
file.original.name = fileObj.name;
}*/
return next(Attachments.insert(settings, false));
Attachments.insert(settings);
},
shrinkImage(options) {
// shrink image to certain size

View file

@ -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 ---------- //

View file

@ -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() {

View file

@ -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 {

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.
const self = this;
if (Meteor.isServer) {
// FIXME: Change to new model
file.attachData(att.url, function(error) {
file.boardId = boardId;
file.cardId = cardId;

View file

@ -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'),
{

View file

@ -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);
}