Those files are browseable!!

This commit is contained in:
Oha 2025-02-22 22:37:11 +01:00
parent 174fa3a36f
commit bb474a24cb
5 changed files with 64 additions and 5 deletions

37
app.py
View file

@ -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)

BIN
static/cursor.png Normal file

Binary file not shown.

After

(image error) Size: 249 B

View file

@ -21,4 +21,8 @@ button {
button:hover {
background-color: #021b9f;
cursor: pointer;
}
* {
cursor: url("/static/cursor.png"), auto;
}

View file

@ -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>

View file

@ -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>