From bb474a24cb48acc972ff342c75962fe26bbb5eed Mon Sep 17 00:00:00 2001 From: Oha <forgejo@ohaa.xyz> Date: Sat, 22 Feb 2025 22:37:11 +0100 Subject: [PATCH] Those files are browseable!! --- app.py | 37 ++++++++++++++++++++++++++++++++----- static/cursor.png | Bin 0 -> 249 bytes static/style.css | 4 ++++ templates/filemanager.html | 27 +++++++++++++++++++++++++++ templates/player.html | 1 + 5 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 static/cursor.png create mode 100644 templates/filemanager.html diff --git a/app.py b/app.py index 0517d5e..805fa33 100644 --- a/app.py +++ b/app.py @@ -1,15 +1,22 @@ -import threading -from flask import Flask, render_template, request +from flask import Flask, render_template, request, send_file import os -playback = False +playback = False if not os.path.exists("music"): os.mkdir("music") app = Flask(__name__) def audio_player(): - os.system(f'mpv --input-ipc-server=/tmp/mpvsocket --shuffle music &') + os.system(f'mpv --input-ipc-server=/tmp/mpvsocket --shuffle music --no-video &') + +def sizeof_fmt(num, suffix="B"): + for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"): + if abs(num) < 1024.0: + return f"{num:3.1f}{unit}{suffix}" + num /= 1024.0 + return f"{num:.1f}Yi{suffix}" + @app.route('/', methods=["POST", "GET"]) def audiothing(): @@ -27,5 +34,25 @@ def audiothing(): playback = True return render_template("player.html", playing=playback) +@app.route("/files/<path:path>", methods=["GET"]) +@app.route("/files") +def filemgr(path=""): + full_path = os.path.join("music", path) + print(full_path) + if os.path.isfile(full_path): + return send_file(full_path) + files = os.listdir(full_path) + for i in range(len(files)): + if os.path.isfile(os.path.join(full_path, files[i])): + files[i] = [files[i], os.path.getsize(os.path.join(full_path, files[i]))] + else: + totalsize = 0 + for file in os.listdir(os.path.join(full_path, files[i])): + totalsize += os.path.getsize(os.path.join(full_path, files[i], file)) + files[i] = [files[i], totalsize] + for file in files: + file[1] = sizeof_fmt(file[1]) + return render_template("filemanager.html", files=files, path=path) + if __name__ == '__main__': - app.run() + app.run(host='0.0.0.0', port=1337) diff --git a/static/cursor.png b/static/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..1448a32abb5f744728af6530a33cfd45e7a26661 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgflE?EXn{$jlbNuW@rr;B5V#p$KN zj(i6cIJDcG|NoETQ+u<hZAPxvq=Lo(F4m1%ecZte3yeZ@t_EzHyH;w2$XOAyYesGs zZ>5r1r<bufsHR=*lRTraQc%gGie2`}FTPXJi?a8srq4dgSP|pb<9<J^(QD?+J+hZx neEB+cwauDY>*Idu|7ZB3k^1eyiLOSVBN#kg{an^LB{Ts5_pnrf literal 0 HcmV?d00001 diff --git a/static/style.css b/static/style.css index d84bb0d..76038dc 100644 --- a/static/style.css +++ b/static/style.css @@ -21,4 +21,8 @@ button { button:hover { background-color: #021b9f; cursor: pointer; +} + +* { + cursor: url("/static/cursor.png"), auto; } \ No newline at end of file diff --git a/templates/filemanager.html b/templates/filemanager.html new file mode 100644 index 0000000..1b522e4 --- /dev/null +++ b/templates/filemanager.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>LAAS - Filemanager</title> + <link rel="stylesheet" href="/static/style.css"> + <meta name="darkreader-lock"> +</head> +<body> +<h1>LAAS Filemanager!!</h1> + <table> + <thead> + <tr> + <th>Filename</th> + <th>Size</th> + </tr> + </thead> + {% for file in files %} + <tr> + <td><a href="/files/{{ path }}/{{ file[0] }}">{{ file[0] }}</a></td> + <td>{{ file[1] }}</td> + </tr> + {% endfor %} + </table> +</body> +</html> \ No newline at end of file diff --git a/templates/player.html b/templates/player.html index 3a5ec19..e0b032e 100644 --- a/templates/player.html +++ b/templates/player.html @@ -5,6 +5,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>LAAS</title> <link rel="stylesheet" href="/static/style.css"> + <meta name="darkreader-lock"> </head> <body> <h1>LAAS</h1>