algolia / youtube-captions-scraper

Fetch youtube user submitted or fallback to auto-generated captions
249 stars 67 forks source link

feat(data): fetch using fetch instead of axios if available #25

Closed Fiattarone closed 7 months ago

Fiattarone commented 10 months ago

Love how the npm demo of this worked with the timestamp, but unfortunately in my current project, I'm not able to use axios at all (browser extensions do not support axios). Figured I'd throw a PR your way to use the classic fetch if the program decides it's inside of a browser extension.

Overview of changes:

All ava tests passed before submitting this PR.

Let me know if there's any additional considerations I should be making before this can merge with master, happy to help!

humphd commented 7 months ago

This would also allow using the module in a CloudFlare worker, which is also currently broken:

[wrangler:err] TypeError: adapter is not a function
    at dispatchRequest (file:///Users/humphd/repos/chatcraft.org/node_modules/.pnpm/axios@0.17.1/node_modules/axios/lib/core/dispatchRequest.js:59:10)
[wrangler:inf] GET /api/proxy 500 Internal Server Error (85ms)

I'd love to see fetch() be the default with fallback to axios() only if necessary.

humphd commented 7 months ago

Thanks for this, works great in CloudFlare now!