weebsquad / msafe

MIT License
2 stars 1 forks source link

Content-Disposition filename saving #28

Closed camjac251 closed 2 years ago

camjac251 commented 3 years ago

I hope you don't mind this feature request. When I had requested it on BobbyWibowo's repo, sadly it got put on hold. https://github.com/BobbyWibowo/lolisafe/issues/192 I've been trying to find a way to get files to save as their original filenames after uploading and doing it directly with nginx modules might be a bit too advanced for its purpose. Could it be possible with the serveFilesWithNode option enabled? It would have to look at the filename on disk it's loading and match it to the originalname pair on the database.

The idea is basically like this on Go https://github.com/uhthomas/kipp/blob/ef9de480f2e63b2f1358f91a20edf3b37a6736a6/server.go#L139-L141

Adding a Content-Disposition response header with the filename field matching the original name so when the client saves the file, the url https://msafe.tld/2ibn.png would save as the original name that is in the DB test-image-revb.png.

I found something similar to what the serveFilesWithNode option outputs, with Content-Disposition. However it is without the table matching https://github.com/dhknudsen/downloadheaders/blob/master/download.js#L14

A few others I found as well https://github.com/jshttp/content-disposition https://github.com/SeregPie/saveFile

metal0 commented 3 years ago

I don't mind the feature request, and in fact I'm happy that you've taken interest in my fork.

I'm not currently working on this fork actively, if I were to I would just be too tempted to rewrite the whole thing, base lolisafe has a lot of issues, and so does my fork, and attempting to work-around them is frankly too much hassle.

Regarding Content-Disposition, I'm not really familiar with the header in general, and honestly I'm not sure I understand your feature request, Do you want the files to be saved on disk with their original upload name, but retain a random-generated URL for accessing via CDN? Am I understanding that correctly?

Sorry, it's been a while since I've messed with code for this, so sorry for any mistakes, however:

It seems that the original filenames are already saved in the db image

I believe that simply changing https://github.com/weebsquad/msafe/blob/master/controllers/uploadController.js#L34 const name = file.originalname

and redoing to check for matches in the db instead of existing files for the cdn would likely be what you're looking for https://github.com/weebsquad/msafe/blob/master/lolisafe.js#L155

If you happen to work on it and end up getting it to function, feel free to open a PR or clarify me exactly what you need and I'll try to help, however, at this time I'm realistically only maintaining my own hosted instance of this fork, and resolving issues that arise from it at a very low priority, sorry.