Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios replaced request #2203

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading