Filesharing / db.py
nikhilyadavtemp1's picture
feat: complete pro features - password protection, self-destruct, video player, and search
99e48df
Raw History Blame Contribute Delete
649 Bytes
import json
import os
from config import BASE_DIR
DB_PATH = os.path.join(BASE_DIR, "metadata.json")
def load_db():
if not os.path.exists(DB_PATH):
return {}
try:
with open(DB_PATH, "r") as f:
return json.load(f)
except:
return {}
def save_db(data):
with open(DB_PATH, "w") as f:
json.dump(data, f, indent=4)
def set_metadata(file_id, metadata):
db = load_db()
db[file_id] = metadata
save_db(db)
def get_metadata(file_id):
return load_db().get(file_id)
def delete_metadata(file_id):
db = load_db()
if file_id in db:
del db[file_id]
save_db(db)