Skip to content

Commit 1d1296e

Browse files
committed
typo
1 parent 9c7c6ea commit 1d1296e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,21 @@ let options = {
6060
};
6161

6262
async function downloadImage(url, folder = '.') {
63+
const { headers } = await axios.head(url);
6364
const hash = crypto.createHash('sha1').update(url).digest('hex');
65+
const existing = fs.readdirSync(folder).find(e => e.startsWith(hash));
66+
if (existing) {
67+
return existing;
68+
}
69+
70+
const [type, ext] = headers['content-type'].split('/');
71+
if (type !== 'image') return null;
72+
6473
const filename = `${hash}.${ext}`;
6574
const saveTo = path.resolve(folder, filename);
6675

6776
if (fs.existsSync(path)) return filename;
6877

69-
const { headers } = await axios.head(url);
70-
71-
const [type, ext] = headers['content-type'].split('/');
72-
if (type !== 'image') return null;
73-
7478
const writer = fs.createWriteStream(saveTo);
7579
const response = await axios({
7680
url,

0 commit comments

Comments
 (0)