Giter Site home page Giter Site logo

Comments (9)

jankapunkt avatar jankapunkt commented on June 12, 2024

I think the Meteor._lastSessionId value is stored in the x-mtok cookie, which you can use to get the connection from Meteor.connection or Meteor.server (I'm not 100% sure which one of both you have to look into).

from meteor-files.

dr-dimitru avatar dr-dimitru commented on June 12, 2024

how i can get connection info at server side

@Kaczkazniszczenia please elaborate what hook/callback you're talking about, and what exactly are you trying to accomplish?

from meteor-files.

dr-dimitru avatar dr-dimitru commented on June 12, 2024

@Kaczkazniszczenia post your code as well, let's speak code please

from meteor-files.

Kaczkazniszczenia avatar Kaczkazniszczenia commented on June 12, 2024
const Files = new FileCollection({
  collectionName: 'files',
  allowClientCode: false,
 ...
  onAfterUpload: function (file) {
    const userId = this.userId; // not important for example
    const userIp = this.connection?.clientAddress; <--- example of what i need
    console.log(`uploaded by user:${userId} from ${userIp}`);
    return createAfterUpdate(imageBucket).call(this, file);
  },
  onAfterRemove: function (file) {
    const userId = this.userId; // not important for example
    const userIp = this.connection?.clientAddress <---- example of what i need
    console.log(`Removed by user:${userId} from ${userIp}`);
  }
});

@dr-dimitru
My main objectives are to get info on users ( IP is a must ) who are uploading and removing files, so i imagine onAfterUpload and onAfterRemove would be perfect place to log their actions.
While we are at it, it would be nice to have user connection info on all hooks (onBeforeUpload, protected, ...).

This is just an example and I will be happy and grateful as long as there is secure way to get user IP, somewhere in pipeline while uploading,

I think the Meteor._lastSessionId value is stored in the x-mtok cookie, which you can use to get the connection from Meteor.connection or Meteor.server (I'm not 100% sure which one of both you have to look into).

@jankapunkt Might get messy/not secure if users start logging on multiple computers or do something malicious. Anyway this is a fine idea i'm sure to explore if i wont be able to get/put connection info in to FileCollection methods. Big thx.

edited formmating

from meteor-files.

dr-dimitru avatar dr-dimitru commented on June 12, 2024

@Kaczkazniszczenia onAfterUpload and onAfterRemove and other hooks/callbacks are state-less by nature. I recommend to:

  1. use .onLogin to fetch user's current session and IP
  2. Update user's object with up-do date details
  3. Find user's object in Meteor-File's hooks/callback and use user's details as needed

from meteor-files.

dr-dimitru avatar dr-dimitru commented on June 12, 2024

@Kaczkazniszczenia have you figured it out?

from meteor-files.

Kaczkazniszczenia avatar Kaczkazniszczenia commented on June 12, 2024

Still working on it, but I decided to create token before file upload and place them inside file meta.
On server side token will be matched with session info allowing me to fetch it after upload.

@dr-dimitru would you like me to put my code here after I'm done ?

from meteor-files.

Kaczkazniszczenia avatar Kaczkazniszczenia commented on June 12, 2024

Thanks for help.

from meteor-files.

dr-dimitru avatar dr-dimitru commented on June 12, 2024

@Kaczkazniszczenia not sure how token related to obtaining user's IP from you original question. Please share code, I'm curious

from meteor-files.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.