implemented cron thread for deleting files
This commit is contained in:
parent
88e462b0e0
commit
bd8e83426a
20
fileHost.py
20
fileHost.py
|
@ -53,9 +53,17 @@ class ReverseProxied(object):
|
|||
class CronThread(threading.Thread):
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
self.stop = threading.Event()
|
||||
|
||||
def run(self):
|
||||
db_execute("SELECT filename, delete_date FROM uploads WHERE delete_date")
|
||||
while not self.stop.is_set():
|
||||
records = db_execute(
|
||||
"SELECT filename, delete_date FROM uploads WHERE delete_date"
|
||||
).fetchall()
|
||||
for filename, delete_date in records:
|
||||
if time.time() >= delete_date:
|
||||
delete_file(filename)
|
||||
time.sleep(60)
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
@ -87,6 +95,7 @@ def init():
|
|||
"""
|
||||
os.makedirs(app.config.get("UPLOAD_DIR"), exist_ok=True)
|
||||
|
||||
# init secret key
|
||||
if os.path.exists("secret_key"):
|
||||
with open("secret_key", "rb") as file:
|
||||
secret_key = file.read()
|
||||
|
@ -96,6 +105,7 @@ def init():
|
|||
file.write(secret_key)
|
||||
app.secret_key = secret_key
|
||||
|
||||
# init db
|
||||
try:
|
||||
db_execute("SELECT * FROM users").fetchone()
|
||||
db_execute("SELECT * FROM uploads").fetchone()
|
||||
|
@ -111,7 +121,11 @@ def init():
|
|||
"uploaded_by TEXT,"
|
||||
"uploaded_date INTEGER DEFAULT (STRFTIME('%s', 'now')),"
|
||||
"delete_date INTEGER)")
|
||||
|
||||
|
||||
# init cron thread
|
||||
t = CronThread()
|
||||
t.start()
|
||||
app.config["CRON_THREAD"] = t
|
||||
|
||||
|
||||
def add_user(username, password, admin="FALSE"):
|
||||
|
|
Loading…
Reference in New Issue
Block a user