first proposal download path selection
This commit is contained in:
62
server/src/utils/directoryUtils.ts
Normal file
62
server/src/utils/directoryUtils.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { readdirSync, statSync } from "fs";
|
||||
import { ISettings } from "../interfaces/ISettings";
|
||||
|
||||
let settings: ISettings;
|
||||
|
||||
class Node {
|
||||
public path: string
|
||||
public children: Node[]
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path
|
||||
this.children = []
|
||||
}
|
||||
}
|
||||
|
||||
function buildTreeDFS(rootPath: string, directoryOnly: boolean) {
|
||||
const root = new Node(rootPath)
|
||||
const stack: Node[] = []
|
||||
const flattened: string[] = []
|
||||
|
||||
stack.push(root)
|
||||
flattened.push(rootPath)
|
||||
|
||||
while (stack.length) {
|
||||
const current = stack.pop()
|
||||
if (current) {
|
||||
const children = readdirSync(current.path)
|
||||
for (const it of children) {
|
||||
const childPath = `${current.path}/${it}`
|
||||
const childNode = new Node(childPath)
|
||||
|
||||
if (directoryOnly) {
|
||||
if (statSync(childPath).isDirectory()) {
|
||||
current.children.push(childNode)
|
||||
stack.push(childNode)
|
||||
flattened.push(childNode.path)
|
||||
}
|
||||
} else {
|
||||
current.children.push(childNode)
|
||||
if (statSync(childPath).isDirectory()) {
|
||||
stack.push(childNode)
|
||||
flattened.push(childNode.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
tree: root,
|
||||
flat: flattened
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
settings = require('../../settings.json');
|
||||
} catch (e) { }
|
||||
|
||||
export function directoryTree() {
|
||||
const tree = buildTreeDFS(settings.download_path || 'downloads', true)
|
||||
return tree
|
||||
}
|
||||
@@ -17,8 +17,8 @@ export const splash = () => {
|
||||
const reset = "\u001b[0m"
|
||||
console.log(`${fg} __ ____ __ __ ______`)
|
||||
console.log(" __ __/ /________/ / /__ _ _____ / / / / / / _/")
|
||||
console.log(" / // / __/___/ _ / / _ \ | |/|/ / -_) _ \/ /_/ // / ")
|
||||
console.log(" \_, /\__/ \_,_/_/ .__/ |__,__/\__/_.__/\____/___/ ")
|
||||
console.log(" / // / __/___/ _ / / _ \\ | |/|/ / -_) _ \\/ /_/ // / ")
|
||||
console.log(" \\_, /\\__/ \\_,_/_/ .__/ |__,__/\\__/_.__/\\____/___/ ")
|
||||
console.log(`/___/ /_/ \n${reset}`)
|
||||
console.log(" yt-dlp-webUI - A web-ui for yt-dlp, simply enough")
|
||||
console.log("---------------------------------------------------\n")
|
||||
|
||||
Reference in New Issue
Block a user