Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from __future__ import annotations

import io
from typing import Any

from flask import Flask, jsonify, request
from openpyxl import load_workbook

app = Flask(__name__)


def _extract_columns_from_xlsx(file_bytes: bytes, sheet_index: int) -> list[str]:
workbook = load_workbook(io.BytesIO(file_bytes), read_only=True, data_only=True)
sheets = workbook.worksheets
if not sheets:
return []
index = min(max(sheet_index, 0), len(sheets) - 1)
first_row = next(sheets[index].iter_rows(min_row=1, max_row=1, values_only=True), ())
return [str(cell).strip() for cell in first_row if isinstance(cell, str) and cell.strip()]


@app.post('/api/render-plot')
def render_plot() -> Any:
payload = request.get_json(silent=True) or {}
config = payload.get('config')
if not isinstance(config, dict):
return jsonify({'message': 'Missing config payload.'}), 400

svg = """<svg xmlns='http://www.w3.org/2000/svg' width='1200' height='675' viewBox='0 0 1200 675'>
<rect x='0' y='0' width='1200' height='675' fill='#f8fafc' />
<text x='40' y='64' font-size='32' font-family='Arial, sans-serif' fill='#111827'>Backend SVG placeholder</text>
<text x='40' y='104' font-size='18' font-family='Arial, sans-serif' fill='#334155'>Implement plotting logic inside backend/app.py render_plot().</text>
<text x='40' y='138' font-size='15' font-family='monospace' fill='#475569'>Received config keys: %s</text>
</svg>""" % ', '.join(sorted(config.keys()))

return jsonify({'svg': svg})


@app.post('/api/import-database')
def import_database() -> Any:
if request.is_json:
payload = request.get_json(silent=True) or {}
teable_url = payload.get('teable_url')
api_key = payload.get('API_Key')
if not teable_url or not api_key:
return jsonify({'success': False, 'message': 'Missing teable_url or API_Key.'}), 400
return jsonify({'success': True, 'columns': []})

upload = request.files.get('file')
if upload is None:
return jsonify({'success': False, 'message': 'Missing uploaded file.'}), 400

try:
sheet_index = int(request.form.get('import_sheet', '0'))
except ValueError:
sheet_index = 0

columns = _extract_columns_from_xlsx(upload.read(), sheet_index)
return jsonify({'success': True, 'columns': columns})


if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
2 changes: 2 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask==3.1.1
openpyxl==3.1.5
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"backend": "python3 backend/app.py"
},
"dependencies": {
"plotly.js-dist-min": "^3.5.0",
Expand Down
273 changes: 255 additions & 18 deletions src/App.tsx

Large diffs are not rendered by default.

Loading