Spaces:
Runtime error
Runtime error
| import json | |
| import os | |
| from typing import Dict, Any | |
| DATA_DIR = 'data' | |
| REQUESTS_FILE = os.path.join(DATA_DIR, 'requests.json') | |
| os.makedirs(DATA_DIR, exist_ok=True) | |
| def _load_all(): | |
| if not os.path.exists(REQUESTS_FILE): | |
| return [] | |
| with open(REQUESTS_FILE, 'r') as f: | |
| return json.load(f) | |
| def _save_all(items): | |
| with open(REQUESTS_FILE, 'w') as f: | |
| json.dump(items, f, indent=2, ensure_ascii=False) | |
| def create_request(payload: Dict[str, Any]) -> Dict[str, Any]: | |
| items = _load_all() | |
| request_id = len(items) + 1 | |
| payload['id'] = request_id | |
| payload['status'] = 'pending' | |
| items.append(payload) | |
| _save_all(items) | |
| return payload | |
| def list_requests(): | |
| return _load_all() | |