Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionFS support #84

Closed
ccorcos opened this issue Jan 11, 2015 · 9 comments
Closed

CollectionFS support #84

ccorcos opened this issue Jan 11, 2015 · 9 comments

Comments

@ccorcos
Copy link

ccorcos commented Jan 11, 2015

Would it be possible to add support for hooks on CollectionFS?

@matb33
Copy link
Collaborator

matb33 commented Jan 12, 2015

Interesting idea! I assume it's easy enough, probably just a matter of doing CollectionHooks.wrapCollection(FS.Collection, FS.Collection); and having the right api.use in package.js.

@ccorcos
Copy link
Author

ccorcos commented Jan 12, 2015

Here's an app you can test it with.

https://github.com/ccorcos/meteor-boilerplate

@fpoirier1
Copy link

+1

@fpoirier1
Copy link

After some digging, the Meteor/Mongo.collection resides in the files property of the FS.Collection. So something like this should be working.

Pictures = new FS.Collection('pictures', ...);
Pictures.files.before.insert(function(userId, picture){...});

@afuggini
Copy link

@fpoirier1 You rock! Thanks!

@ccorcos
Copy link
Author

ccorcos commented Jan 16, 2015

Still a quirk:

I've tried offloading some client work onto the server:

      # This now happens in the .before.insert hook
      # img.metadata =  
      #   date: Date.now()
      #   ownerId: Meteor.userId()

      Images.insert img,  (err, fileObj) ->
        if err
          console.log err

On the server, I try to take care of it:

  Images.files.before.insert (userId, doc) ->
    doc.metadata =  
      date: Date.now()
      ownerId: userId
    console.log "before", doc
    return doc

And I'm checking for the metadata here:

Images.allow
  insert: (userId, doc) ->
    console.log "insert", doc
    doc.metadata?.ownerId is userId

Based on the console log statements, when I insert an image, this is what happens:

I20150115-17:17:42.358(-8)? insert { createdByTransform: true,
I20150115-17:17:42.359(-8)?   original: { type: 'image/png', size: 122935 },
I20150115-17:17:42.359(-8)?   metadata: { date: 1421371062351, ownerId: 'KtMrS3DhBbqCzyTzm' },
I20150115-17:17:42.359(-8)?   _id: '5yev5oapPzK7ADmBe',
I20150115-17:17:42.360(-8)?   collectionName: 'images' }
I20150115-17:17:42.360(-8)? before { original: { type: 'image/png', size: 122935 },
I20150115-17:17:42.360(-8)?   metadata: { date: 1421371062358, ownerId: 'KtMrS3DhBbqCzyTzm' },
I20150115-17:17:42.360(-8)?   _id: '5yev5oapPzK7ADmBe' }
I20150115-17:17:42.460(-8)? insert { createdByTransform: true,
I20150115-17:17:42.460(-8)?   _id: '5yev5oapPzK7ADmBe',
I20150115-17:17:42.460(-8)?   chunkCount: 0,
I20150115-17:17:42.460(-8)?   chunkSize: 2097152,
I20150115-17:17:42.460(-8)?   chunkSum: 1,
I20150115-17:17:42.460(-8)?   metadata: { date: 1421371062358, ownerId: 'KtMrS3DhBbqCzyTzm' },
I20150115-17:17:42.461(-8)?   original: { type: 'image/png', size: 122935 },
I20150115-17:17:42.461(-8)?   collectionName: 'images',
I20150115-17:17:42.461(-8)?   collection: 
I20150115-17:17:42.461(-8)?    { storesLookup: { images: [Object] },
I20150115-17:17:42.461(-8)?      primaryStore: 
I20150115-17:17:42.461(-8)?       { mongoUrl: 'mongodb://127.0.0.1:3001/meteor',
I20150115-17:17:42.461(-8)?         mongoOptions: [Object],
I20150115-17:17:42.461(-8)?         name: 'images',
I20150115-17:17:42.462(-8)?         typeName: 'storage.gridfs',
I20150115-17:17:42.462(-8)?         adapter: [Object],
I20150115-17:17:42.462(-8)?         _removeAsync: [Function],
I20150115-17:17:42.462(-8)?         remove: [Function],
I20150115-17:17:42.462(-8)?         _transform: [Object],
I20150115-17:17:42.462(-8)?         _events: [Object] },
I20150115-17:17:42.462(-8)?      options: { filter: [Object], stores: [Object], chunkSize: null },
I20150115-17:17:42.463(-8)?      name: 'images',
I20150115-17:17:42.463(-8)?      files: 
I20150115-17:17:42.463(-8)?       { _makeNewID: [Function],
I20150115-17:17:42.463(-8)?         _transform: [Function],
I20150115-17:17:42.463(-8)?         _connection: [Object],
I20150115-17:17:42.463(-8)?         _collection: [Object],
I20150115-17:17:42.463(-8)?         _name: 'cfs.images.filerecord',
I20150115-17:17:42.463(-8)?         _restricted: true,
I20150115-17:17:42.463(-8)?         _insecure: undefined,
I20150115-17:17:42.464(-8)?         _validators: [Object],
I20150115-17:17:42.464(-8)?         _prefix: '/cfs.images.filerecord/',
I20150115-17:17:42.464(-8)?         before: [Object],
I20150115-17:17:42.464(-8)?         _hookAspects: [Object],
I20150115-17:17:42.464(-8)?         after: [Object],
I20150115-17:17:42.464(-8)?         hookOptions: [Object],
I20150115-17:17:42.464(-8)?         direct: [Object] },
I20150115-17:17:42.464(-8)?      _validators: { download: [Object] } },
I20150115-17:17:42.464(-8)?   domain: null,
I20150115-17:17:42.465(-8)?   _events: {},
I20150115-17:17:42.465(-8)?   _maxListeners: 10,
I20150115-17:17:42.465(-8)?   attachData: [Function: fsFileAttachData],
I20150115-17:17:42.465(-8)?   uploadProgress: [Function],
I20150115-17:17:42.465(-8)?   controlledByDeps: [Function],
I20150115-17:17:42.465(-8)?   getCollection: [Function],
I20150115-17:17:42.465(-8)?   isMounted: [Function],
I20150115-17:17:42.465(-8)?   getFileRecord: [Function],
I20150115-17:17:42.465(-8)?   update: [Function],
I20150115-17:17:42.465(-8)?   _saveChanges: [Function],
I20150115-17:17:42.466(-8)?   remove: [Function],
I20150115-17:17:42.466(-8)?   getExtension: [Function],
I20150115-17:17:42.466(-8)?   isImage: [Function],
I20150115-17:17:42.466(-8)?   isVideo: [Function],
I20150115-17:17:42.466(-8)?   isAudio: [Function],
I20150115-17:17:42.466(-8)?   formattedSize: [Function: fsFileFormattedSize],
I20150115-17:17:42.466(-8)?   isUploaded: [Function],
I20150115-17:17:42.467(-8)?   hasStored: [Function],
I20150115-17:17:42.467(-8)?   hasCopy: [Function],
I20150115-17:17:42.467(-8)?   getCopyInfo: [Function],
I20150115-17:17:42.467(-8)?   _getInfo: [Function],
I20150115-17:17:42.467(-8)?   _setInfo: [Function],
I20150115-17:17:42.467(-8)?   name: [Function],
I20150115-17:17:42.467(-8)?   extension: [Function],
I20150115-17:17:42.467(-8)?   size: [Function],
I20150115-17:17:42.467(-8)?   type: [Function],
I20150115-17:17:42.468(-8)?   updatedAt: [Function],
I20150115-17:17:42.468(-8)?   logCopyFailure: [Function],
I20150115-17:17:42.468(-8)?   failedPermanently: [Function],
I20150115-17:17:42.468(-8)?   createReadStream: [Function],
I20150115-17:17:42.468(-8)?   createWriteStream: [Function],
I20150115-17:17:42.468(-8)?   copy: [Function],
I20150115-17:17:42.468(-8)?   url: [Function],
I20150115-17:17:42.469(-8)?   setMaxListeners: [Function: setMaxListeners],
I20150115-17:17:42.469(-8)?   emit: [Function: emit],
I20150115-17:17:42.469(-8)?   addListener: [Function: addListener],
I20150115-17:17:42.469(-8)?   on: [Function: addListener],
I20150115-17:17:42.469(-8)?   once: [Function: once],
I20150115-17:17:42.469(-8)?   removeListener: [Function: removeListener],
I20150115-17:17:42.469(-8)?   removeAllListeners: [Function: removeAllListeners],
I20150115-17:17:42.470(-8)?   listeners: [Function: listeners] }

The insert gets called twice and the before happens in the middle...

@matb33
Copy link
Collaborator

matb33 commented Jan 19, 2015

I wrote some tests in v0.7.9 to verify that hooks work with CollectionFS. I'm not getting any double inserts... I do get several update before/after hooks firing but that makes sense since CollectionFS updates properties as the file uploads.

@yasaricli
Copy link

@fpoirier1 👍

@matb33
Copy link
Collaborator

matb33 commented Jan 28, 2015

@ccorcos are you still experiencing any issues? I'm not sure what to do at this point since my tests are passing... if you've resolved your issue I would be able to close this one off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants