Skip to content

Commit

Permalink
Merge pull request #2203 from ioBroker/axiosTest
Browse files Browse the repository at this point in the history
axios replaced request
  • Loading branch information
arteck authored Sep 9, 2024
2 parents 0ea6d33 + 93349b6 commit 3ac407b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/statescontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
});
});
}
}
Expand Down

0 comments on commit 3ac407b

Please sign in to comment.