From 93cfd2f012cf40bbf0d7a7f88f60b9c3659106a2 Mon Sep 17 00:00:00 2001 From: yumiura Date: Thu, 30 Nov 2023 03:36:04 +0900 Subject: [PATCH] modify of review points --- lib/image.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/image.js b/lib/image.js index ff89c65d3..860a0431c 100644 --- a/lib/image.js +++ b/lib/image.js @@ -43,23 +43,30 @@ Object.defineProperty(Image.prototype, 'src', { throw err } } - 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' } - }) - - request.then((res) => { + util + .callbackify( + fetch(val, { + 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", + }, + }) + ) + .then((res) => { if (res.statusCode < 200 || res.statusCode >= 300) { - return onerror(new Error(`Server responded with ${res.statusCode}`)) + return onerror( + new Error(`Server responded with ${res.statusCode}`) + ); } return res.arrayBuffer() }) .then((data) => { - return setSource(this, data) + setSource(this, data) }) .catch((err) => { - return onerror(err) - }) + onerror(err); + }); } else { // local file path assumed setSource(this, val) }