Ephemeral Deletion Engines
Ephemeral has a few deletion engines. Historically, there was only one, however I saw how 0x0.st does stuff, and liked that more than what I had at the time (now called engine mode 1)
Engine Mode 1 (Time Based)
Files are deleted purely depending on their last view.
This lets the least popular files be deleted after they expire, and the most popular files stay around longer.
However, this allows people to keep a file alive indefinitely by just simply making a web request every deletiontime - 1
days.
Engine Mode 2 (Sized Based)
Files are deleted purely depending on their filesize. TL;DR: Big files are deleted sooner, than small files.
This solves the disadvantage of engine mode 1, where files can be kept alive indefinitely by the user. This is an exact recreation of 0x0.st's algorithm, so I'll also steal their graph.
days
365 | \
| \
| \
| \
| \
| \
| ..
| \
197.5 | ----------..-------------------------------------------
| ..
| \
| ..
| ...
| ..
| ...
| ....
| ......
30 | ....................
0 512.0 1024.0
MiB
The numbers are a little different, depending on how your config looks, but it works the same.
stat = os.stat(os.path.join(config['UPLOAD_FOLDER'], f))
systime = time.time()
age = timedelta(seconds = systime - stat.st_mtime).days
maxage = mind + (-maxd + mind) * (stat.st_size / maxs - 1) ** 3
if age >= maxage:
delete_file(f)
Engine Mode 3 (Hybrid 'Popularity' Based)
Files are deleted on a aggregate score based on size and popularity (large, popular files are kept alive longer, vs unpopular files most likely just used once)
Engine Mode 4 (Lazy-Hybrid 'Popularity' Based)
Files are deleted on size AND last view, depending on what comes last (small files stay the same, long files have potential to stay alive longer)
Expiry Overrides
Overriding the expiry will work by having a (normally) null expiry_override column in the DB, when set, will override the expiry of the file.
This can be longer or shorter than the normal expiry. However there should be checks for if it's longer, as I'd like for that to be a 'premium' action, requiring a api key or some other method of limitation.