from flask import Flask, request, jsonify from flask_cors import CORS from datetime import datetime, timedelta import uuid import threading import time app = Flask(__name__) CORS(app) storage = {} @app.route('/api/store', methods=['POST']) def store(): req = request.get_json() data = req.get('data') ttl = int(req.get('ttl', 3600)) # default 1 hour view_once = bool(req.get('view_once', False)) secret_id = str(uuid.uuid4())[:8] expire_at = datetime.utcnow() + timedelta(seconds=ttl) storage[secret_id] = { 'data': data, 'expire_at': expire_at, 'view_once': view_once, } return jsonify({'id': secret_id}) @app.route('/api/fetch/', methods=['GET']) def fetch(secret_id): secret = storage.get(secret_id) if not secret: return jsonify({'error': 'Not found'}), 404 if datetime.utcnow() > secret['expire_at']: del storage[secret_id] return jsonify({'error': 'Expired'}), 410 data = secret['data'] if secret['view_once']: del storage[secret_id] return jsonify({'data': data}) def cleanup(): while True: now = datetime.utcnow() expired_keys = [k for k, v in storage.items() if now > v['expire_at']] for k in expired_keys: del storage[k] time.sleep(60) threading.Thread(target=cleanup, daemon=True).start() if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)