This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
TwitToMast/ref/functions/functions.js
Penelope Gomez / Pogmommy ed9d5c68fd 2.0.0
2023-02-14 14:35:57 -07:00

41 lines
986 B
JavaScript

const fs = require('fs');
const client = require('https');
var { tall } = require('tall')
function downloadImage(url, filepath) {
return new Promise((resolve, reject) => {
client.get(url, (res) => {
if (res.statusCode === 200) {
res.pipe(fs.createWriteStream(filepath))
.on('error', reject)
.once('close', () => resolve(filepath));
} else {
res.resume();
reject(new Error(`Request Failed With a Status Code: ${res.statusCode}`));
}
});
});
}
async function expandUrl(shortUrl) {
try {
const unshortenedUrl = await tall(shortUrl);
return unshortenedUrl;
} catch (err) {
console.error('Error unshortening url: ', err)
return "";
}
}
function rand(min, max) {
return Math.floor(
Math.random() * (max - min + 1) + min
)
}
module.exports = { downloadImage,expandUrl,rand };