30 lines
899 B
Python
Executable File
30 lines
899 B
Python
Executable File
from os import chdir, path, listdir, stat, remove, sep
|
|
from datetime import timedelta
|
|
from time import time
|
|
from binascii import unhexlify
|
|
|
|
from fhost import app, db, File
|
|
|
|
|
|
chdir(path.dirname(path.abspath(__file__)) + sep + app.config["FHOST_STORAGE_PATH"])
|
|
|
|
max_content_len = app.config["MAX_CONTENT_LENGTH"]
|
|
min_days = app.config['MIN_DAYS']
|
|
max_days = app.config['MAX_DAYS']
|
|
current_file = time()
|
|
|
|
for filename in listdir('.'):
|
|
file_stat = stat(filename)
|
|
|
|
age = timedelta(seconds=current_file - file_stat.st_mtime).days
|
|
|
|
maxage = min_days + (-max_days + min_days) * (file_stat.st_size / max_content_len - 1) ** 3
|
|
|
|
if True:
|
|
file_obj = File.query.filter_by(sha256=unhexlify(filename)).first()
|
|
file_obj.removed = True
|
|
db.session.add(file_obj)
|
|
remove(filename)
|
|
print('Deleting file: {}, age: {}'.format(filename, age))
|
|
db.session.commit()
|