jalik / meteor-jalik-ufs-gridfs

GridFS store for UploadFS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delete file logs error if several stores share a single collection

opened this issue · comments

Hi,

I use multiple stores to check the file extensions, but all stores share a single collection. When deleting a file by calling Files.remove(fileId); an error is logged in the delete method because the file is not found in each store:

 this.delete = function (fileId, callback) {
    if (typeof callback !== 'function') {
        callback = function (err) {
            if (err) {
                console.error(err);
            }
        }
    }
    // TODO check if fileId really exists in this mongostore before calling delete
    return mongoStore.delete(fileId, callback);
};

...

export const Files = new Mongo.Collection('uploads');

export const PdfStore = new MultiGridFSStore({
    collection: Files,
    collectionName: 'pdf_store',
    name: 'pdf',
    filter: new UploadFS.Filter({onCheck: file => checkUploadFile(file, ['pdf'])})
});

export const PresentationStore = new MultiGridFSStore({
    collection: Files,
    collectionName: 'presentation_store',
    name: 'presentation',
    filter: new UploadFS.Filter({onCheck: file => checkUploadFile(file, ['ppt', 'pptx'])})
});

I've inserted a TODO, but I am not sure if this is possible. Currently I modified the implementation and removed the console logging.

Thanks
Oliver

Hello, in fact it was not intended to manage this case, having several stores pointing to the same collection since each store should have its own collection. But your fix should do it, however I cannot guarantee that you will not have other side effects..

By the way I've suspended this project, so it won't receive any updates (just to let you know, don't use it in production unless you can fix or improve the code yourself).

Thanks for your quick reply. I did this because you mentioned it here:
jalik/meteor-jalik-ufs#119 (comment)

Currently, I am just ignoring the error logged to the console. It works fine this way. Hm, we will use it in production, it fits perfectly for our project!

Indeed I said that, but my answer was incomplete since it was just a quick fix, it doesn't mean it will work normally, you already noticed it with file deletion warnings... hopefully this does not affect the process like crashing the app.

I still plan to rewrite another file upload kit (client/server), but this time for npm and not only meteor, can I ask you in which context you are using this lib ? (ex: storing bills for an ecommerce platform).
Thank you.