Add public file serving to adapter API — /public endpoint
This commit is contained in:
@@ -183,5 +183,54 @@ def retry_dead_letter():
|
|||||||
return jsonify({'error': str(e)}), 500
|
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/<path:filename>')
|
||||||
|
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__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=8766, debug=False)
|
app.run(host='0.0.0.0', port=8766, debug=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user