Skip to content

Commit 93cfd2f

Browse files
author
yumiura
committed
modify of review points
1 parent 23eba7b commit 93cfd2f

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/image.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,30 @@ Object.defineProperty(Image.prototype, 'src', {
4343
throw err
4444
}
4545
}
46-
const request = fetch(url = val, data = {
47-
method: "POST",
48-
headers: { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' }
49-
})
50-
51-
request.then((res) => {
46+
util
47+
.callbackify(
48+
fetch(val, {
49+
method: 'POST',
50+
headers: {
51+
"User-Agent":
52+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
53+
},
54+
})
55+
)
56+
.then((res) => {
5257
if (res.statusCode < 200 || res.statusCode >= 300) {
53-
return onerror(new Error(`Server responded with ${res.statusCode}`))
58+
return onerror(
59+
new Error(`Server responded with ${res.statusCode}`)
60+
);
5461
}
5562
return res.arrayBuffer()
5663
})
5764
.then((data) => {
58-
return setSource(this, data)
65+
setSource(this, data)
5966
})
6067
.catch((err) => {
61-
return onerror(err)
62-
})
68+
onerror(err);
69+
});
6370
} else { // local file path assumed
6471
setSource(this, val)
6572
}

0 commit comments

Comments
 (0)