diff --git a/README.md b/README.md index aeb28cf..ba097fb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ medialib-manager =============== +## Установка и запуск +1. Клонируйте проект или создайте новую директорию. +2. Создайте виртуальное окружение: + ```python3 -m venv venv``` +3. Активируйте окружение: + ```source venv/bin/activate``` +4. Установите зависимости + ```pip install -r requirements.txt``` +5. Запустите приложение: + ```python app.py``` + +Потом можно выйти из окружения выполнив ```deactivate``` diff --git a/app.py b/app.py new file mode 100644 index 0000000..ca979d4 --- /dev/null +++ b/app.py @@ -0,0 +1,53 @@ +from flask import Flask, render_template, request, jsonify +import os +import json + +app = Flask(__name__) + +# Load configuration +CONFIG_FILE = 'config.json' +def load_config(): + if os.path.exists(CONFIG_FILE): + with open(CONFIG_FILE, 'r') as f: + return json.load(f) + else: + return {"directories": []} + +def save_config(config): + with open(CONFIG_FILE, 'w') as f: + json.dump(config, f, indent=4) + +config = load_config() + +# Function to list media files +def list_media_files(directories): + media_files = [] + for directory in directories: + if os.path.exists(directory): + for root, _, files in os.walk(directory): + for file in files: + file_path = os.path.join(root, file) + file_info = { + "name": file, + "path": file_path, + "size": os.path.getsize(file_path) + } + media_files.append(file_info) + return media_files + +@app.route('/') +def index(): + media_files = list_media_files(config.get("directories", [])) + return render_template('index.html', media_files=media_files) + +@app.route('/configure', methods=['GET', 'POST']) +def configure(): + if request.method == 'POST': + directories = request.json.get('directories', []) + config['directories'] = directories + save_config(config) + return jsonify({"status": "success"}) + return jsonify(config) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/config.json b/config.json new file mode 100644 index 0000000..d246ffe --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "directories": [ + "/home/gbook/media-storage/secraid5-storage" + ] +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fe43de8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +blinker==1.9.0 +click==8.1.8 +Flask==3.1.0 +itsdangerous==2.2.0 +Jinja2==3.1.5 +MarkupSafe==3.0.2 +Werkzeug==3.1.3 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..b3143e0 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,34 @@ + + + + + + Media Library Manager + + + +
+

Media Library Manager

+ Configure Directories + + + + + + + + + + {% for file in media_files %} + + + + + + {% endfor %} + +
File NamePathSize (Bytes)
{{ file.name }}{{ file.path }}{{ file.size }}
+
+ + +