booru icon indicating copy to clipboard operation
booru copied to clipboard

Provide `Content-Type` or File Type

Open lewxdev opened this issue 2 years ago • 3 comments

It'd be helpful for the Post to also provide this information to be able to differentiate between images and videos without processing/requesting media manually

lewxdev avatar Feb 16 '24 00:02 lewxdev

I am also unable to access _data to handle this myself. @AtoraSuunva this seems like a bug

lewxdev avatar Feb 17 '24 13:02 lewxdev

It's data not _data (whoops my docs are wrong there), though there's no way for me to provide Content-Type since no booru API does that (afaik) and doing a HEAD request for every post to get that header would be wasteful

You can probably rely on file extensions in file urls though, every booru I've seen has been pretty good about using the right extensions and it's roughly what I do in my own project using booru https://github.com/AtoraSuunva/BooruBot/blob/main/src/boorubot/search/searchUtils.ts#L324

AtoraSuunva avatar Feb 18 '24 20:02 AtoraSuunva

It's data not _data (whoops my docs are wrong there)

Ah, I hadn't realized this before, but in order to access @private and @protected properties in typescript you have to use bracket notation (e.g. post["data"]). Maybe this property shouldn't be protected/private if it's essentially just a simple Record<string, any>

You can probably rely on file extensions in file urls though, every booru I've seen has been pretty good about using the right extensions and it's roughly what I do in my own project using booru

Is it possible for booru to provide it's best guess of what the file type would be based on the file url or data received from the APIs? I started to do this on my end, but it feels like important information that this package could provide.

interface Post {
  // ...
  /** the content type as determined by the file url, (e.g. `"image/png"`) */
  contentType: string | null;
}

lewxdev avatar Feb 26 '24 00:02 lewxdev