diff --git a/lib/statescontroller.js b/lib/statescontroller.js index 4c9e7102..ffd02be7 100644 --- a/lib/statescontroller.js +++ b/lib/statescontroller.js @@ -5,7 +5,7 @@ const statesMapping = require('./devices'); const getAdId = require('./utils').getAdId; const getZbId = require('./utils').getZbId; const fs = require('fs'); -const request = require('request'); +const axios = require('axios'); let savedDeviceNamesDB = {}; const knownUndefinedDevices = {}; @@ -540,16 +540,18 @@ class StatesController extends EventEmitter { async downloadIcon(url, image_path) { if (!fs.existsSync(image_path)) { return new Promise((resolve, reject) => { - request.head(url, (err, res, body) => { - if (err) { - return reject(err + ' ' + res + ' ' + body); - } - const stream = request(url); - stream.pipe( - fs.createWriteStream(image_path) - .on('error', err => reject(err))) - .on('close', () => resolve()); - }); + axios({ + method: 'get', + url: url, + responseType: 'stream' // Dies ist wichtig, um den Stream direkt zu erhalten + }).then(response => { + const writer = fs.createWriteStream(image_path); + response.data.pipe(writer); + writer.on('finish', resolve); + writer.on('error', reject); + }).catch(err => { + reject(err); + }); }); } }