Spaces:
Paused
Paused
Download db.py from ttnikal/Filesharing: direct link, hf CLI and curl.
- Browser
- Download file 649 Bytes
-
https://huggingface.co/spaces/ttnikal/Filesharing/resolve/main/db.py
- Command line
-
hf download hf://spaces/ttnikal/Filesharing/db.py
-
curl -L -o db.py https://huggingface.co/spaces/ttnikal/Filesharing/resolve/main/db.py
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) | |