Code Monkey home page Code Monkey logo

Comments (2)

Pitu avatar Pitu commented on May 18, 2024 1

After much considering, the solution I came up with is the following:

If you are a registered user and upload a file, that file belongs to you. If another user uploads the exact same file, it will also get uploaded and will be attached to that user. That way each user will get a different link. At the same time, if the user uploads the exact same file again, file will be deleted and API will return the original file link instead.

This also applies to anonymous uploads, if the file was anonymously uploaded before and someone attempts to upload the exact same file, they will get the original link instead. This felt the best way to achieve this without over-complicating the logic behind it.

from chibisafe.

Aareksio avatar Aareksio commented on May 18, 2024

Deleting the files is an interesting topic.

Let's take two users, A and B.
A uploads file, it's saved on the disk and added to the database, with userid set to A.
Application returns:

{
    name: 'abc',
    ...
}

Now B uploads the same file. As the hash matches file already existing in the database, application returns the same JSON as above, although the database isn't modified in any way - B isn't saved as the owner of the file.

Right now the file is accessible by it's filename (https://github.com/WeebDev/loli-safe/blob/master/lolisafe.js#L25 - btwthis line is broken, config.uploads.folder is ignored, that happens not only in this line).

Assuming you solved the first problem by adding many-to-many relation, there's another problem - the file is saved on the disk once, with one filename (abc). If the user decides to delete it, you need'll to make sure the file is no longer accessible by that name (or else what's the point of deleting the file).
Changing the filename is not an option, it would break existing links used by other users.

Good luck :)
Can't wait to see the progress.

from chibisafe.

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.