Commit 4d2b4e61 by Denys Tito Urbano

Helpers agregados

parent f4eeef04
const axios = require('axios').default;
const { createWriteStream } = require('fs');
const stream = require('stream');
const { promisify } = require('util');
const finished = promisify(stream.finished);
const download_file = async (fileUrl, outputLocationPath) => {
try {
console.log(fileUrl);
const writer = createWriteStream(outputLocationPath);
const response = await axios({ method: 'get', url: fileUrl, responseType: 'stream', });
response.data.pipe(writer);
return await finished(writer);
} catch (error) {
console.log(error.message);
}
};
module.exports = {
download_file
};
const format_timestamp = (date) => {
const padL = (nr, len = 2, chr = `0`) => `${nr}`.padStart(2, chr);
return `${padL(date.getDate())}${padL(date.getMonth() + 1)}${date.getFullYear()}_${padL(date.getHours())}${padL(date.getMinutes())}${padL(date.getSeconds())}`;
};
module.exports = {
format_timestamp
};
const jwt = require('jsonwebtoken');
const generate_jwt = (payload) => {
return new Promise((resolve, reject) => {
jwt.sign(payload, process.env.SECRET_KEY, { expiresIn: '1h' },
(err, token) => {
if (err) {
reject('No se generó el Token!');
} else {
resolve(token);
}
});
});
};
module.exports = {
generate_jwt
};
\ No newline at end of file
const { download_file } = require('../helpers/download_file');
const { generate_jwt } = require('./generate_jwt');
const { format_timestamp } = require('../helpers/format_timestamp');
module.exports = {
download_file,
generate_jwt,
format_timestamp
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment