Refactoring

This commit is contained in:
2022-01-26 16:24:09 +01:00
parent 551ff95660
commit 9b0dc4d21b
12 changed files with 5268 additions and 84 deletions

View File

@@ -1,6 +1,7 @@
const https = require('https');
const fs = require('fs');
const path = require('path');
const { Socket } = require('socket.io');
// endpoint to github API
const options = {
@@ -13,7 +14,11 @@ const options = {
port: 443,
}
// build the binary url based on the release tag
/**
* Build the binary url based on the release tag
* @param {string} release yt-dlp GitHub release tag
* @returns {*} the fetch options with the correct tag and headers
*/
function buildDonwloadOptions(release) {
return {
hostname: 'github.com',
@@ -26,7 +31,9 @@ function buildDonwloadOptions(release) {
}
}
// main
/**
* gets the yt-dlp latest binary URL from GitHub API
*/
async function update() {
// ensure that the binary has been removed
try {
@@ -53,7 +60,10 @@ async function update() {
})
})
}
/**
* Utility that Pipes the latest binary to a file
* @param {string} url yt-dlp GitHub release url
*/
function downloadBinary(url) {
https.get(url, res => {
// if it is a redirect follow the url
@@ -70,7 +80,10 @@ function downloadBinary(url) {
})
})
}
/**
* Invoke the yt-dlp update procedure
* @param {Socket} socket the current connection socket
*/
function updateFromFrontend(socket) {
update().then(() => {
socket.emit('updated')