cobalt icon indicating copy to clipboard operation
cobalt copied to clipboard

Include file name in response, and support "Accept" header that contain charset property

Open johan-perso opened this issue 1 year ago • 4 comments

This PR has been made to allow clients to use the API with an Accept header defined to application/json; charset=utf-8, which is especially useful for Flutter apps, as they automatically set it instead of the regular application/json.

Additionally, when requesting a download, the API will now return the name of the file. This enhancement aims to improve the developer experience when programmatically accessing Cobalt.

johan-perso avatar Apr 01 '24 18:04 johan-perso

This PR has been made to allow clients to use the API with an Accept header defined to application/json; charset=utf-8, which is especially useful for Flutter apps, as they automatically set it instead of the regular application/json.

this is a good idea, but if you're going to update this, the check should be (or rather should have been) probably done using req.is for content-type and req.accepts for accept

dumbmoron avatar Apr 01 '24 18:04 dumbmoron

Additionally, when requesting a download, the API will now return the name of the file. This enhancement aims to improve the developer experience when programmatically accessing Cobalt.

i'm not entirely opposed to it, but I think it would be a better option to simply get the filename from the stream request as an API consumer, since you are usually going to download the stream anyways - if you don't want the data you could probably make a HEAD request (something to check here, if you'd like to contribute a fix, is whether this spawns a ffmpeg process when it's not necessary - i believe it does, but it doesn't need to.)

dumbmoron avatar Apr 01 '24 18:04 dumbmoron

this is a good idea, but if you're going to update this, the check should be (or rather should have been) probably done using req.is for content-type and req.accepts for accept

It seems that req.accepts also refuses Accept header that contains charset and only accepts the application/json value

johan-perso avatar Apr 01 '24 19:04 johan-perso

I think it would be a better option to simply get the filename from the stream request as an API consumer

This would work for stream requests but not for medias that aren't downloaded through the Cobalt backend (such as Twitter, they don't return file names when fetching the media url).

johan-perso avatar Apr 01 '24 19:04 johan-perso

closing this since both parts were re-done are are now implemented

dumbmoron avatar Sep 18 '24 18:09 dumbmoron