AtoraSuunva / booru

Searches boorus for images using some js magic
https://www.npmjs.com/package/booru
MIT License
75 stars 18 forks source link

Provide `Content-Type` or File Type #102

Open lewxdev opened 4 months ago

lewxdev commented 4 months ago

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 commented 4 months ago

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

AtoraSuunva commented 4 months ago

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

lewxdev commented 4 months ago

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;
}