From 188a0868ecd60f0861c52d23e8dc9b0eed9f8f0b Mon Sep 17 00:00:00 2001 From: VZ Build Date: Sun, 19 Jul 2026 21:23:55 +0000 Subject: [PATCH] =?UTF-8?q?Add=20public=20file=20serving=20to=20adapter=20?= =?UTF-8?q?API=20=E2=80=94=20/public=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter_api.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/adapter_api.py b/adapter_api.py index 87f4ad8..1573eda 100644 --- a/adapter_api.py +++ b/adapter_api.py @@ -183,5 +183,54 @@ def retry_dead_letter(): return jsonify({'error': str(e)}), 500 + + +# ── Public file serving ─────────────────────────────────────── +# Serves deployment artifacts for KoreNet/Corné to pull directly +# No auth required — public read-only static files + +PUBLIC_DIR = os.path.join(os.path.dirname(__file__), 'public') +os.makedirs(PUBLIC_DIR, exist_ok=True) + +@app.route('/public/') +def serve_public(filename): + """Serve public deployment files.""" + import re + # Sanitise path — no directory traversal + if '..' in filename or filename.startswith('/'): + abort(400) + filepath = os.path.join(PUBLIC_DIR, filename) + if not os.path.exists(filepath): + abort(404) + with open(filepath, 'rb') as f: + data = f.read() + # Detect content type + if filename.endswith('.yaml') or filename.endswith('.yml'): + ct = 'text/yaml' + elif filename.endswith('.sh'): + ct = 'text/x-sh' + elif filename.endswith('.json'): + ct = 'application/json' + else: + ct = 'text/plain' + from flask import Response + return Response(data, mimetype=ct) + +@app.route('/public') +def list_public(): + """List available public files.""" + files = [] + if os.path.exists(PUBLIC_DIR): + for f in sorted(os.listdir(PUBLIC_DIR)): + fp = os.path.join(PUBLIC_DIR, f) + files.append({ + 'name': f, + 'size': os.path.getsize(fp), + 'url': f'http://63.245.138.38:8766/public/{f}', + 'modified': datetime.fromtimestamp( + os.path.getmtime(fp), tz=timezone.utc).isoformat() + }) + return jsonify({'files': files, 'count': len(files)}) + if __name__ == '__main__': app.run(host='0.0.0.0', port=8766, debug=False)