mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-01-05 15:12:11 +00:00
Remove dependency on bestIcon api
Use page-icon instead
This commit is contained in:
parent
e0e5b16f0b
commit
c8d6cef815
@ -43,6 +43,7 @@
|
|||||||
"hasbin": "^1.2.0",
|
"hasbin": "^1.2.0",
|
||||||
"lodash": "^4.0.0",
|
"lodash": "^4.0.0",
|
||||||
"ncp": "^2.0.0",
|
"ncp": "^2.0.0",
|
||||||
|
"page-icon": "^0.1.0",
|
||||||
"request": "^2.67.0",
|
"request": "^2.67.0",
|
||||||
"sanitize-filename": "^1.5.3",
|
"sanitize-filename": "^1.5.3",
|
||||||
"shelljs": "^0.5.3",
|
"shelljs": "^0.5.3",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import pageIcon from 'page-icon';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
@ -14,34 +14,13 @@ const BEST_ICON_API = 'http://45.55.116.63:8080/icon';
|
|||||||
*/
|
*/
|
||||||
function inferIconFromUrlToPath(targetUrl, outDir, callback) {
|
function inferIconFromUrlToPath(targetUrl, outDir, callback) {
|
||||||
const outfilePath = path.join(outDir, '/icon.png');
|
const outfilePath = path.join(outDir, '/icon.png');
|
||||||
request({
|
pageIcon(targetUrl, {ext: 'png'})
|
||||||
url: BEST_ICON_API,
|
.then(icon => {
|
||||||
qs: {
|
fs.writeFile(outfilePath, icon.data, error => {
|
||||||
url: targetUrl,
|
|
||||||
size: 57,
|
|
||||||
formats: 'png'
|
|
||||||
},
|
|
||||||
encoding: null
|
|
||||||
}, (error, response, body) => {
|
|
||||||
if (error) {
|
|
||||||
callback(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parsedError = JSON.parse(body).error;
|
|
||||||
callback(parsedError);
|
|
||||||
} catch (exception) {
|
|
||||||
if (/<html>/i.test(body)) {
|
|
||||||
callback('BestIcon server 502 error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// body is an image
|
|
||||||
fs.writeFile(outfilePath, body, error => {
|
|
||||||
callback(error, outfilePath);
|
callback(error, outfilePath);
|
||||||
});
|
});
|
||||||
}
|
})
|
||||||
});
|
.catch(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user