Code refactoring and set up format selection
Set up format selection and archive download for next releases
This commit is contained in:
@@ -2,28 +2,53 @@ import { logger, splash } from './utils/logger';
|
||||
import { join } from 'path';
|
||||
import { Server } from 'socket.io';
|
||||
import { ytdlpUpdater } from './utils/updater';
|
||||
import { download, abortDownload, retrieveDownload, abortAllDownloads } from './core/downloader';
|
||||
import { download, abortDownload, retrieveDownload, abortAllDownloads, getFormatsAndInfo } from './core/downloader';
|
||||
import { getFreeDiskSpace } from './utils/procUtils';
|
||||
import Logger from './utils/BetterLogger';
|
||||
import Jean from './core/HTTPServer';
|
||||
import { listDownloaded } from './core/downloadArchive';
|
||||
import { createServer } from 'http';
|
||||
import * as Koa from 'koa';
|
||||
import * as Router from 'koa-router';
|
||||
import * as serve from 'koa-static';
|
||||
import * as cors from '@koa/cors';
|
||||
import { streamer } from './core/streamer';
|
||||
|
||||
const server = new Jean(join(__dirname, 'frontend')).createServer();
|
||||
const app = new Koa();
|
||||
const server = createServer(app.callback());
|
||||
const router = new Router();
|
||||
const log = new Logger();
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: "*",
|
||||
methods: ["GET", "POST"]
|
||||
}
|
||||
});
|
||||
|
||||
// Koa routing
|
||||
|
||||
router.get('/settings', (ctx, next) => {
|
||||
ctx.redirect('/')
|
||||
next()
|
||||
})
|
||||
router.get('/downloaded', (ctx, next) => {
|
||||
ctx.redirect('/')
|
||||
next()
|
||||
})
|
||||
router.get('/getAllDownloaded', (ctx, next) => {
|
||||
listDownloaded(ctx, next)
|
||||
})
|
||||
router.get('/stream/:filepath', (ctx, next) => {
|
||||
streamer(ctx, next)
|
||||
})
|
||||
|
||||
/*
|
||||
WebSocket listeners
|
||||
*/
|
||||
// WebSocket listeners
|
||||
|
||||
io.on('connection', socket => {
|
||||
logger('ws', `${socket.handshake.address} connected!`)
|
||||
|
||||
socket.on('send-url', (args) => {
|
||||
logger('ws', args?.url)
|
||||
//if (args.url) getFormatsAndInfo(socket, args?.url)
|
||||
download(socket, args)
|
||||
})
|
||||
socket.on('abort', (args) => {
|
||||
@@ -47,6 +72,10 @@ io.on('disconnect', (socket) => {
|
||||
logger('ws', `${socket.handshake.address} disconnected`)
|
||||
})
|
||||
|
||||
app.use(serve(join(__dirname, 'frontend')))
|
||||
app.use(router.routes())
|
||||
app.use(cors())
|
||||
|
||||
server.listen(process.env.PORT || 3022)
|
||||
|
||||
splash()
|
||||
@@ -63,7 +92,7 @@ const gracefullyStop = () => {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
/* Intercepts singnals and perform cleanups before shutting down. */
|
||||
// Intercepts singnals and perform cleanups before shutting down.
|
||||
process
|
||||
.on('SIGTERM', () => gracefullyStop())
|
||||
.on('SIGUSR1', () => gracefullyStop())
|
||||
|
||||
Reference in New Issue
Block a user