Spaces:
Paused
Paused
Gemini CLI commited on
Commit Β·
de711f2
1
Parent(s): 0fae7dc
feat: add 'Never Delete' option to settings and per-file expiration logic
Browse files
app.py
CHANGED
|
@@ -24,10 +24,16 @@ async def cleanup_old_files():
|
|
| 24 |
for filename in files:
|
| 25 |
file_path = os.path.join(root, filename)
|
| 26 |
try:
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
except: pass
|
| 32 |
if root != UPLOAD_DIR and not os.listdir(root):
|
| 33 |
try: os.rmdir(root)
|
|
|
|
| 24 |
for filename in files:
|
| 25 |
file_path = os.path.join(root, filename)
|
| 26 |
try:
|
| 27 |
+
# Check metadata for custom expiration
|
| 28 |
+
meta = get_metadata(filename)
|
| 29 |
+
expire_hours = meta.get("expire_hours", 24) if meta else 24
|
| 30 |
+
|
| 31 |
+
# If expire_hours is 0, it's 'Never Delete'
|
| 32 |
+
if expire_hours > 0:
|
| 33 |
+
if now - os.path.getmtime(file_path) > (expire_hours * 3600):
|
| 34 |
+
os.remove(file_path)
|
| 35 |
+
delete_metadata(filename)
|
| 36 |
+
print(f"ποΈ Cleaned up expired file: {filename} ({expire_hours}h)")
|
| 37 |
except: pass
|
| 38 |
if root != UPLOAD_DIR and not os.listdir(root):
|
| 39 |
try: os.rmdir(root)
|
bot.py
CHANGED
|
@@ -135,7 +135,7 @@ else:
|
|
| 135 |
s = user_settings.get(uid, {"auto_delete": 24, "password": None, "self_destruct": False})
|
| 136 |
user_settings[uid] = s
|
| 137 |
kb = InlineKeyboardMarkup([
|
| 138 |
-
[InlineKeyboardButton(f"β° Auto-Delete: {s['auto_delete']}h", callback_data="set_del_cycle")],
|
| 139 |
[InlineKeyboardButton(f"π₯ Self-Destruct: {'ON' if s['self_destruct'] else 'OFF'}", callback_data="set_sd_toggle")],
|
| 140 |
[InlineKeyboardButton(f"π Password: {'β
Set' if s['password'] else 'β None'}", callback_data="set_pass_init")],
|
| 141 |
[InlineKeyboardButton("ποΈ Clear My Storage", callback_data="confirm_clear")],
|
|
@@ -149,7 +149,7 @@ else:
|
|
| 149 |
s = user_settings.get(uid, {"auto_delete": 24, "password": None, "self_destruct": False})
|
| 150 |
|
| 151 |
if cb.data == "set_del_cycle":
|
| 152 |
-
opts = [1, 6, 12, 24, 48]
|
| 153 |
s["auto_delete"] = opts[(opts.index(s.get("auto_delete", 24)) + 1) % len(opts)]
|
| 154 |
elif cb.data == "set_sd_toggle":
|
| 155 |
s["self_destruct"] = not s.get("self_destruct", False)
|
|
@@ -159,7 +159,7 @@ else:
|
|
| 159 |
|
| 160 |
user_settings[uid] = s
|
| 161 |
kb = InlineKeyboardMarkup([
|
| 162 |
-
[InlineKeyboardButton(f"β° Auto-Delete: {s['auto_delete']}h", callback_data="set_del_cycle")],
|
| 163 |
[InlineKeyboardButton(f"π₯ Self-Destruct: {'ON' if s['self_destruct'] else 'OFF'}", callback_data="set_sd_toggle")],
|
| 164 |
[InlineKeyboardButton(f"π Password: {'β
Set' if s['password'] else 'β None'}", callback_data="set_pass_init")],
|
| 165 |
[InlineKeyboardButton("ποΈ Clear My Storage", callback_data="confirm_clear")],
|
|
@@ -325,8 +325,12 @@ else:
|
|
| 325 |
try: os.remove(fpath)
|
| 326 |
except: pass
|
| 327 |
sname = os.path.basename(opath)
|
| 328 |
-
settings = user_settings.get(uid, {"password":None, "self_destruct":False})
|
| 329 |
-
set_metadata(sname, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
durl = f"{BASE_URL}/download/user_{uid}/{sname}"
|
| 331 |
results_text += f"β
`{fname}`\nβ π Saved: `{saved:.1f}%` β’ [Link]({durl})\n\n"
|
| 332 |
else:
|
|
@@ -457,8 +461,12 @@ else:
|
|
| 457 |
except: pass
|
| 458 |
return
|
| 459 |
else:
|
| 460 |
-
settings = user_settings.get(uid, {"password":None, "self_destruct": False})
|
| 461 |
-
set_metadata(os.path.basename(fpath), {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
durl = f"{BASE_URL}/download/user_{uid}/{os.path.basename(fpath)}"
|
| 463 |
|
| 464 |
btns = [[InlineKeyboardButton("π₯ Download", url=durl)]]
|
|
|
|
| 135 |
s = user_settings.get(uid, {"auto_delete": 24, "password": None, "self_destruct": False})
|
| 136 |
user_settings[uid] = s
|
| 137 |
kb = InlineKeyboardMarkup([
|
| 138 |
+
[InlineKeyboardButton(f"β° Auto-Delete: {s['auto_delete'] if s['auto_delete'] > 0 else 'Never'}h", callback_data="set_del_cycle")],
|
| 139 |
[InlineKeyboardButton(f"π₯ Self-Destruct: {'ON' if s['self_destruct'] else 'OFF'}", callback_data="set_sd_toggle")],
|
| 140 |
[InlineKeyboardButton(f"π Password: {'β
Set' if s['password'] else 'β None'}", callback_data="set_pass_init")],
|
| 141 |
[InlineKeyboardButton("ποΈ Clear My Storage", callback_data="confirm_clear")],
|
|
|
|
| 149 |
s = user_settings.get(uid, {"auto_delete": 24, "password": None, "self_destruct": False})
|
| 150 |
|
| 151 |
if cb.data == "set_del_cycle":
|
| 152 |
+
opts = [1, 6, 12, 24, 48, 0] # 0 = Never
|
| 153 |
s["auto_delete"] = opts[(opts.index(s.get("auto_delete", 24)) + 1) % len(opts)]
|
| 154 |
elif cb.data == "set_sd_toggle":
|
| 155 |
s["self_destruct"] = not s.get("self_destruct", False)
|
|
|
|
| 159 |
|
| 160 |
user_settings[uid] = s
|
| 161 |
kb = InlineKeyboardMarkup([
|
| 162 |
+
[InlineKeyboardButton(f"β° Auto-Delete: {s['auto_delete'] if s['auto_delete'] > 0 else 'Never'}h", callback_data="set_del_cycle")],
|
| 163 |
[InlineKeyboardButton(f"π₯ Self-Destruct: {'ON' if s['self_destruct'] else 'OFF'}", callback_data="set_sd_toggle")],
|
| 164 |
[InlineKeyboardButton(f"π Password: {'β
Set' if s['password'] else 'β None'}", callback_data="set_pass_init")],
|
| 165 |
[InlineKeyboardButton("ποΈ Clear My Storage", callback_data="confirm_clear")],
|
|
|
|
| 325 |
try: os.remove(fpath)
|
| 326 |
except: pass
|
| 327 |
sname = os.path.basename(opath)
|
| 328 |
+
settings = user_settings.get(uid, {"password":None, "self_destruct":False, "auto_delete": 24})
|
| 329 |
+
set_metadata(sname, {
|
| 330 |
+
"password": settings.get("password"),
|
| 331 |
+
"self_destruct": settings.get("self_destruct", False),
|
| 332 |
+
"expire_hours": settings.get("auto_delete", 24)
|
| 333 |
+
})
|
| 334 |
durl = f"{BASE_URL}/download/user_{uid}/{sname}"
|
| 335 |
results_text += f"β
`{fname}`\nβ π Saved: `{saved:.1f}%` β’ [Link]({durl})\n\n"
|
| 336 |
else:
|
|
|
|
| 461 |
except: pass
|
| 462 |
return
|
| 463 |
else:
|
| 464 |
+
settings = user_settings.get(uid, {"password":None, "self_destruct": False, "auto_delete": 24})
|
| 465 |
+
set_metadata(os.path.basename(fpath), {
|
| 466 |
+
"password": settings.get("password"),
|
| 467 |
+
"self_destruct": settings.get("self_destruct", False),
|
| 468 |
+
"expire_hours": settings.get("auto_delete", 24)
|
| 469 |
+
})
|
| 470 |
durl = f"{BASE_URL}/download/user_{uid}/{os.path.basename(fpath)}"
|
| 471 |
|
| 472 |
btns = [[InlineKeyboardButton("π₯ Download", url=durl)]]
|