rejetto / hfs

HFS is a web file server to run on your computer. Share folders or even a single file thanks to the virtual file system.
GNU General Public License v3.0
2.13k stars 209 forks source link

Get md5 checksum #591

Closed made1990 closed 4 months ago

made1990 commented 4 months ago

Is it possible to get the md5 checksum of a file? Either directly after uploading (using PUT) as a return value or as part of an http GET using the api.

rejetto commented 4 months ago

ok, i studied curl's manual, and -d is for POST instead of PUT, or better, for "form" shaped data. It's not the plain file, it has a different structure.

rejetto commented 4 months ago

https://github.com/rejetto/hfs/wiki/Upload#from-command-line

made1990 commented 4 months ago

Thx for checking.

-d works fine if you put text content as input, e.g. -d "this is my input" instead of uploading an already existing file

made1990 commented 4 months ago

So after some additional testing I would say it works great :) and it would be great to have this feature in a stable hfs version at some point. One more slight request for that ;) Is it possible to let the user who uploads the file decide if the md5 checksum creation is triggered or not. E.g. with some information put in the HEADER when using the PUT command?

rejetto commented 4 months ago

easy, after the "middleware" line you can add something like this

if (!ctx.get('x-request-md5')) return

or if you prefer to append in the URL ?get=md5

if (ctx.query.get !== 'md5') return

hopefully the stable version will arrive in 1 or 2 weeks.

rejetto commented 4 months ago

i updated the wiki to use a more standard header for the md5

ctx.set({ 'Content-Digest': `md5=:${hasher.digest('hex')}:` })

it's functionally the same, but adhering to standards is often a good thing