Skip to content

Commit

Permalink
use fetch api
Browse files Browse the repository at this point in the history
  • Loading branch information
yumiura committed Nov 29, 2023
1 parent ad793da commit 23eba7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 11 additions & 12 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 @@ -46,20 +43,22 @@ Object.defineProperty(Image.prototype, 'src', {
throw err
}
}

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

get.concat({
url: val,
const request = fetch(url = val, data = {
method: "POST",
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)
})

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

setSource(this, data)
return res.arrayBuffer()
})
.then((data) => {
return setSource(this, data)
})
.catch((err) => {
return onerror(err)
})
} 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 @@ -53,8 +53,7 @@
],
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.0",
"node-addon-api": "^7.0.0",
"simple-get": "^3.0.3"
"node-addon-api": "^7.0.0"
},
"devDependencies": {
"@types/node": "^10.12.18",
Expand Down

0 comments on commit 23eba7b

Please sign in to comment.