From 9e20d4e1156d53bea47bdb102148f09a9c9b4c8d Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Sun, 18 Nov 2018 09:42:41 +0200 Subject: [PATCH] refined autoremove support --- README.md | 22 +++++++++++---------- code/Dockerfile | 1 + code/app.py | 2 +- code/start_app.py | 41 +++++++++++++++++++++++++++++++--------- code/utils/utils.py | 15 ++++++++------- data/config.json.example | 1 + 6 files changed, 55 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b38aec5..7dea32d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # FLEES -A very small file sharing website. +A small file sharing website. The name comes from mispronouncing "files" very badly. @@ -16,14 +16,15 @@ The name comes from mispronouncing "files" very badly. - generate and manage shares with `code/flees-manager.py` - configure service with data/config.json - - Change your app_secret_key !! - - Change your public_url - - uid = user id for new files - - workers = parallel processes (i.e. one upload reserves a process) - - timeout = timeout for processes, single upload might take a long time! - - max_zip_size = zipping a share with more data is not allowed + - Change your `app_secret_key` !! + - Change your `public_url` + - Change your `timezone` + - `uid` = user id for new files + - `workers` = parallel processes (i.e. one upload reserves a process) + - `timeout` = timeout for processes, single upload might take a long time! + - `max_zip_size` = zipping a share with more data is not allowed - configure bind host and port in .env -- proxy with nginx, match body size and timeout to your needs: +- proxy with nginx, match bind port, body size and timeout to your needs: ``` location /flees/ { proxy_pass http://localhost:8136/; @@ -36,7 +37,6 @@ location /flees/ { } ``` -- configure local port in `docker-compose.yaml` - change website colors in code/static/css/colors.css - Check `flees-manager.py rest` command to get direct links to various @@ -96,11 +96,13 @@ Operation is one of download, direct_download, zip_download, or upload - @app.route('/files//', methods=['GET']) Return plain text list of files in the share - @app.route('/list//', methods=['GET']) - Login to a share with a token + List share contents for the browser - @app.route('/list/', methods=['GET']) List share contents for the browser - @app.route('/logout/', methods=['GET']) Logout from share. Only for browser. +- @app.route('/ls//', methods=['GET']) + List share contents for the console client - @app.route('/direct///', methods=['GET']) Download a file using the filename token (if direct download enabled) - @app.route('/download///', methods=['GET']) diff --git a/code/Dockerfile b/code/Dockerfile index bbf802d..56097ff 100644 --- a/code/Dockerfile +++ b/code/Dockerfile @@ -1,5 +1,6 @@ FROM alpine:3.5 RUN apk add --update \ + tzdata \ python3 \ python3-dev \ py3-pip \ diff --git a/code/app.py b/code/app.py index 0f833f1..ea8ba7c 100644 --- a/code/app.py +++ b/code/app.py @@ -14,7 +14,7 @@ from utils.utils import * from utils.crypt import * -__FLEES_VERSION__ = "20181104.0" +__FLEES_VERSION__ = "20181118.0" app = Flask(__name__) app.config.from_object(__name__) config_values = read_config(app) diff --git a/code/start_app.py b/code/start_app.py index 5d66ee8..9e34ec3 100644 --- a/code/start_app.py +++ b/code/start_app.py @@ -1,11 +1,34 @@ -import subprocess,json +import json +import os +import subprocess -config = json.load(open('data/config.json','rt')) +config = json.load(open(os.environ['FLEES_CONFIG'],'rt')) -subprocess.call([ - 'gunicorn', - '-b','0.0.0.0:80', - '--timeout',str(config['timeout']), - '-w',str(config['workers']), - 'app:app' -]) +TZ = "Etc/UTC" +if 'timezone' in config: + TZ = config['timezone'] + assert os.path.exists('/usr/share/zoneinfo/' + TZ), "Invalid timezone '%s'. See /usr/share/zoneinfo/*"%( TZ, ) + + with open('/etc/timezone', 'wt') as fp: + fp.write(TZ) + fp.close() + if os.path.exists('/etc/localtime'): + os.remove('/etc/localtime') + os.symlink( + '/usr/share/zoneinfo/' + TZ, + '/etc/localtime' + ) + +env = os.environ.copy() +env['TZ'] = TZ + +subprocess.call( + [ + 'gunicorn', + '-b','0.0.0.0:80', + '--timeout',str(config['timeout']), + '-w',str(config['workers']), + 'app:app' + ], + env = env +) diff --git a/code/utils/utils.py b/code/utils/utils.py index 4fbc282..fb36cc8 100644 --- a/code/utils/utils.py +++ b/code/utils/utils.py @@ -1,6 +1,5 @@ import os from datetime import datetime -from dateutil.relativedelta import relativedelta from flask import current_app as app import requests import re @@ -122,12 +121,14 @@ def file_age(path): os.stat(path).st_mtime ) diff = now - then - rdiff = relativedelta(now, then) - return diff, "%dM %02dD %02d:%02dH" % ( - rdiff.years * 12 + rdiff.months, - rdiff.days, - rdiff.hours, - rdiff.minutes + return ( + diff, + "%03d d %s"%( + diff.days, + datetime.utcfromtimestamp( + diff.seconds + ).strftime('%H:%M:%S') + ) ) diff --git a/data/config.json.example b/data/config.json.example index 6e65c61..b9daed7 100644 --- a/data/config.json.example +++ b/data/config.json.example @@ -13,6 +13,7 @@ "timeout": 3600, "uid": 1000, "gid": -1, + "timezone": "Etc/UTC", "max_zip_size": 1000, "app_secret_key": "Cz2dw5NiRt3PSMFBSLTAJJi7kKrc4QU2CdQqEeOaU6", "notifier": "",