Initial commit
This commit is contained in:
		
						commit
						c9483141d4
					
				| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
__pycache__
 | 
			
		||||
config.toml
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
from src import app
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    app.run(debug=True)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
name = "Folder share"
 | 
			
		||||
base_path = "/path/to/folder"
 | 
			
		||||
favicon = "/.favicon.png"
 | 
			
		||||
 | 
			
		||||
[qbittorrent]
 | 
			
		||||
base_url = "http://127.0.0.1:8080"
 | 
			
		||||
username = "admin"
 | 
			
		||||
password = "adminadmin"
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,63 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
import tomllib
 | 
			
		||||
from flask import Flask, render_template, send_file
 | 
			
		||||
 | 
			
		||||
with open("config.toml", "rb") as f:
 | 
			
		||||
    config = tomllib.load(f)
 | 
			
		||||
 | 
			
		||||
app = Flask(
 | 
			
		||||
    __name__,
 | 
			
		||||
    template_folder="../templates",
 | 
			
		||||
    static_folder="../static",
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
app.jinja_env.globals.update(
 | 
			
		||||
    config=config,
 | 
			
		||||
    path_join=os.path.join,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Catch all
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route('/', defaults={'path': ''})
 | 
			
		||||
@app.route('/<path:path>')
 | 
			
		||||
def index(path):
 | 
			
		||||
    internal_path = os.path.join(config['base_path'], path)
 | 
			
		||||
    path = '/' + path
 | 
			
		||||
 | 
			
		||||
    # Checks ###################################################
 | 
			
		||||
 | 
			
		||||
    if '..' in path:
 | 
			
		||||
        return 'Path cannot contain double dots, i.e. "..".'
 | 
			
		||||
 | 
			
		||||
    if not os.path.exists(internal_path):
 | 
			
		||||
        return (
 | 
			
		||||
            render_template(
 | 
			
		||||
                "error.html",
 | 
			
		||||
                code=404,
 | 
			
		||||
                msg=f'The path "{path}" does not exist.'
 | 
			
		||||
            ),
 | 
			
		||||
            404,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    # Actual serving ###########################################
 | 
			
		||||
 | 
			
		||||
    if os.path.isdir(internal_path):
 | 
			
		||||
        _, dirs, files = next(os.walk(internal_path))
 | 
			
		||||
        files = filter(lambda x: not x.startswith("."), files)
 | 
			
		||||
        dirs = filter(lambda x: not x.startswith("."), dirs)
 | 
			
		||||
 | 
			
		||||
        return (
 | 
			
		||||
            render_template(
 | 
			
		||||
                "directory.html",
 | 
			
		||||
                path=path,
 | 
			
		||||
                dirs=dirs,
 | 
			
		||||
                files=files,
 | 
			
		||||
            ),
 | 
			
		||||
            200,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    # Path exists, not a folder, must be a file, send
 | 
			
		||||
    return send_file(internal_path)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
body {
 | 
			
		||||
  background-color: #191919;
 | 
			
		||||
	color: white;
 | 
			
		||||
	font-family: monospace;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
a {
 | 
			
		||||
	text-decoration: none;
 | 
			
		||||
	color: lightgrey;
 | 
			
		||||
}
 | 
			
		||||
  a:visited {
 | 
			
		||||
	  color: grey;
 | 
			
		||||
  }
 | 
			
		||||
  a:hover {
 | 
			
		||||
	  color: #191919;
 | 
			
		||||
	  background-color: white;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
<!doctype html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
  <head>
 | 
			
		||||
    <meta charset="utf-8" />
 | 
			
		||||
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
 | 
			
		||||
    <meta name="description" content="" />
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
			
		||||
 | 
			
		||||
    <title>{% block title %}{% endblock %} - {{ config["name"] }}</title>
 | 
			
		||||
 | 
			
		||||
    <link
 | 
			
		||||
      rel="stylesheet"
 | 
			
		||||
      href="{{ url_for('static', filename='style/main.css') }}"
 | 
			
		||||
    />
 | 
			
		||||
    <link rel="icon" href="{{ config["favicon"] }}">
 | 
			
		||||
 | 
			
		||||
    {# <script src="{{ url_for('static', filename='lib/htmx.min.js') }}"></script> #}
 | 
			
		||||
  </head>
 | 
			
		||||
  <body>
 | 
			
		||||
    {% block body %}{% endblock %}
 | 
			
		||||
  </body>
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
{% extends 'base.html' %}
 | 
			
		||||
 | 
			
		||||
{% block title %}{{ path }}{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block body %}
 | 
			
		||||
<a href=".."><--</a>
 | 
			
		||||
<br /><br />
 | 
			
		||||
 | 
			
		||||
{% for dir in dirs %}
 | 
			
		||||
<a href="{{ path_join(path, dir) }}">{{ dir }}</a><br />
 | 
			
		||||
{% endfor %}
 | 
			
		||||
 | 
			
		||||
<br /><br />
 | 
			
		||||
 | 
			
		||||
<h3>Archivos</h3>
 | 
			
		||||
 | 
			
		||||
{% for file in files %}
 | 
			
		||||
<a href="{{ path_join(path, file) }}">{{ file }}</a><br />
 | 
			
		||||
{% endfor %}
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
{% extends 'base.html' %}
 | 
			
		||||
 | 
			
		||||
{% block title %}Error {{ code }}{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block body %}
 | 
			
		||||
<h1>Error {{ code }}</h1>
 | 
			
		||||
<p>{{ msg }}</p>
 | 
			
		||||
<a href="/">Return to Index</a>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
		Loading…
	
		Reference in New Issue