Skip to content

Commit a8159e9

Browse files
committed
chore(deps): Remove isomorphic-fetch
1 parent 8dbe550 commit a8159e9

File tree

3 files changed

+74
-73
lines changed

3 files changed

+74
-73
lines changed

package-lock.json

Lines changed: 6 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"dotenv": "^16.4.5",
1414
"express": "^4.18.3",
1515
"express-handlebars": "^7.1.2",
16-
"isomorphic-fetch": "^3.0.0",
1716
"jsonschema": "^1.4.1",
1817
"morgan": "^1.10.0",
1918
"msgpack-lite": "^0.1.26",
@@ -32,10 +31,16 @@
3231
},
3332
"ava": {
3433
"failFast": true,
35-
"files": ["test/*", "test/middleware/*", "!test/*_fixtures"]
34+
"files": [
35+
"test/*",
36+
"test/middleware/*",
37+
"!test/*_fixtures"
38+
]
3639
},
3740
"xo": {
38-
"extends": ["prettier"],
41+
"extends": [
42+
"prettier"
43+
],
3944
"rules": {
4045
"no-unused-vars": [
4146
2,
@@ -45,7 +50,9 @@
4550
}
4651
]
4752
},
48-
"ignores": ["main.js"]
53+
"ignores": [
54+
"main.js"
55+
]
4956
},
5057
"volta": {
5158
"node": "20.11.1"

src/provider/custom-v1.js

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,66 @@
1-
const fetch = require('isomorphic-fetch')
2-
const Validator = require('jsonschema').Validator
3-
const CustomV1Schema = require('../../schema/custom-v1.json')
4-
const UrlSchema = require('../../schema/url.json')
5-
const BaseProvider = require('./base-provider')
1+
const Validator = require("jsonschema").Validator;
2+
const CustomV1Schema = require("../../schema/custom-v1.json");
3+
const UrlSchema = require("../../schema/url.json");
4+
const BaseProvider = require("./base-provider");
65

7-
class CustomV1 extends BaseProvider
8-
{
9-
randomImage(query) {
10-
const providerUrl = this._provider.substring(this._provider.indexOf(':')+1)
11-
return this.validateAndFetchProvider(providerUrl)
12-
.then(imagePool => this.imageFromPool(query, imagePool))
13-
.catch(err => { throw err })
14-
}
6+
class CustomV1 extends BaseProvider {
7+
randomImage(query) {
8+
const providerUrl = this._provider.substring(
9+
this._provider.indexOf(":") + 1,
10+
);
11+
return this.validateAndFetchProvider(providerUrl)
12+
.then((imagePool) => this.imageFromPool(query, imagePool))
13+
.catch((err) => {
14+
throw err;
15+
});
16+
}
1517

16-
validateAndFetchProvider(providerUrl) {
17-
const validator = new Validator()
18-
return new Promise((resolve, reject) => {
19-
if (validator.validate(providerUrl, UrlSchema).valid !== true) {
20-
reject(new Error("Invalid URL"))
21-
}
18+
validateAndFetchProvider(providerUrl) {
19+
const validator = new Validator();
20+
return new Promise((resolve, reject) => {
21+
if (validator.validate(providerUrl, UrlSchema).valid !== true) {
22+
reject(new Error("Invalid URL"));
23+
}
2224

23-
fetch(providerUrl, {
24-
headers: {
25-
Accept: "application/json"
26-
}
27-
})
28-
.then(res => res.json())
29-
.catch(err => {
30-
console.error(err)
31-
throw new Error("This is not a valid image pool!")
32-
})
33-
.then(data => {
34-
if (
35-
validator.validate(data, CustomV1Schema).valid !== true
36-
|| data.version !== 1
37-
) {
38-
reject(new Error("Invalid image pool!"))
39-
}
40-
resolve(data)
41-
})
42-
.catch(reject)
25+
fetch(providerUrl, {
26+
headers: {
27+
Accept: "application/json",
28+
},
29+
})
30+
.then((res) => res.json())
31+
.catch((err) => {
32+
console.error(err);
33+
throw new Error("This is not a valid image pool!");
4334
})
44-
}
45-
46-
imageFromPool(query, pool) {
47-
const image = pool.pictures[Math.floor(Math.random()*pool.pictures.length)]
48-
const imageServiceParams = []
35+
.then((data) => {
36+
if (
37+
validator.validate(data, CustomV1Schema).valid !== true ||
38+
data.version !== 1
39+
) {
40+
reject(new Error("Invalid image pool!"));
41+
}
42+
resolve(data);
43+
})
44+
.catch(reject);
45+
});
46+
}
4947

50-
if (query.size) {
51-
if (query.size.width > 0) imageServiceParams.push(`width=${query.size.width}`)
52-
if (query.size.height > 0) imageServiceParams.push(`height=${query.size.height}`)
53-
image.url = `${image.url}?${imageServiceParams.join('&')}`
54-
image.size = query.size
55-
}
48+
imageFromPool(query, pool) {
49+
const image =
50+
pool.pictures[Math.floor(Math.random() * pool.pictures.length)];
51+
const imageServiceParams = [];
5652

57-
return this._normalizeResponse(image)
53+
if (query.size) {
54+
if (query.size.width > 0)
55+
imageServiceParams.push(`width=${query.size.width}`);
56+
if (query.size.height > 0)
57+
imageServiceParams.push(`height=${query.size.height}`);
58+
image.url = `${image.url}?${imageServiceParams.join("&")}`;
59+
image.size = query.size;
5860
}
61+
62+
return this._normalizeResponse(image);
63+
}
5964
}
6065

61-
module.exports = CustomV1
66+
module.exports = CustomV1;

0 commit comments

Comments
 (0)