Skip to content

Commit 5a17d52

Browse files
committed
fix: use validate.io-uri
1 parent 1ba6a98 commit 5a17d52

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

bin/image-manager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require("isomorphic-fetch");
44
const fse = require("fs-extra");
55
const path = require("path");
66
const mime = require("mime/lite");
7+
const isURI = require("validate.io-uri");
78

89
const identifierForItem = "item";
910

@@ -52,6 +53,8 @@ class ImageManager {
5253
);
5354
await fse.writeFile(imagePath, await response.buffer());
5455
this.imagePathMap_[imageUrl] = imagePath;
56+
}).catch(er => {
57+
throw new Error(`When fetch ${imageUrl}, ${er}`);
5558
}));
5659
}
5760
/**
@@ -70,7 +73,7 @@ class ImageManager {
7073
/**@type {Set<string>} */
7174
const imageList = this.imageListMap[itemId][identifier] || new Set();
7275
for(const imageUrl of imageUrls) {
73-
if(null == imageUrl) continue;
76+
if(null == imageUrl || !isURI(imageUrl)) continue;
7477
this.NotifyCacheImage_(imageUrl);
7578
imageList.add(imageUrl);
7679
}

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"mime": "^2.3.1",
3434
"mkdirp-promise": "^5.0.1",
3535
"parse-link-header": "^1.0.1",
36-
"sanitize-filename": "^1.6.1"
36+
"sanitize-filename": "^1.6.1",
37+
"validate.io-uri": "^1.0.0"
3738
}
3839
}

0 commit comments

Comments
 (0)