Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
use fetch api
  • Loading branch information
yumiura authored and chearon committed Jan 11, 2025
commit c0785c50c7c6ef30913643bc80f21dc82f77c228
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
(Unreleased)
==================
### Changed
* Replaced `simple-get ` with ` Node.js builtin` `fetch` (#2309)
### Added
### Fixed

Expand Down
27 changes: 12 additions & 15 deletions lib/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ const bindings = require('./bindings')
const Image = module.exports = bindings.Image
const util = require('util')

// Lazily loaded simple-get
let get

const { GetSource, SetSource } = bindings

Object.defineProperty(Image.prototype, 'src', {
Expand Down Expand Up @@ -47,20 +44,20 @@ Object.defineProperty(Image.prototype, 'src', {
}
}

if (!get) get = require('simple-get')

get.concat({
url: val,
fetch(val, {
method: 'GET',
headers: { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' }
}, (err, res, data) => {
if (err) return onerror(err)

if (res.statusCode < 200 || res.statusCode >= 300) {
return onerror(new Error(`Server responded with ${res.statusCode}`))
}

setSource(this, data)
})
.then(res => {
if (!res.ok) {
throw new Error(`Server responded with ${res.statusCode}`)
}
return res.arrayBuffer()
})
.then(data => {
setSource(this, Buffer.from(data))
})
.catch(onerror)
} else { // local file path assumed
setSource(this, val)
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
],
"dependencies": {
"node-addon-api": "^7.0.0",
"prebuild-install": "^7.1.1",
"simple-get": "^3.0.3"
"prebuild-install": "^7.1.1"
},
"devDependencies": {
"@types/node": "^10.12.18",
Expand Down