deploy
parent
f70df881de
commit
5429540f32
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask
|
from flask import Flask, send_from_directory, request
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
@ -6,7 +6,7 @@ from controller import register_routes
|
||||||
from model.database import init_db
|
from model.database import init_db
|
||||||
from controller.socketIO import socketio
|
from controller.socketIO import socketio
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__, static_folder='dist', static_url_path='/')
|
||||||
CORS(app)
|
CORS(app)
|
||||||
socketio.init_app(app)
|
socketio.init_app(app)
|
||||||
|
|
||||||
|
|
@ -25,6 +25,10 @@ register_routes(app)
|
||||||
def health_check():
|
def health_check():
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
|
@app.route('/', defaults={'path': 'index.html'})
|
||||||
|
@app.route('/<path:path>')
|
||||||
|
def catch_all(path):
|
||||||
|
return app.send_static_file('index.html')
|
||||||
|
|
||||||
# für Docker wichtig: host='0.0.0.0'
|
# für Docker wichtig: host='0.0.0.0'
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import Blueprint, request, jsonify, send_file, current_app
|
from flask import Blueprint, request, jsonify, send_file, current_app, make_response
|
||||||
from model.database import db
|
from model.database import db
|
||||||
from model.pitch_book_model import PitchBookModel
|
from model.pitch_book_model import PitchBookModel
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
@ -86,10 +86,25 @@ def get_file(id):
|
||||||
@pitch_book_controller.route("/<int:id>/download", methods=["GET"])
|
@pitch_book_controller.route("/<int:id>/download", methods=["GET"])
|
||||||
def download_file(id):
|
def download_file(id):
|
||||||
file = PitchBookModel.query.get_or_404(id)
|
file = PitchBookModel.query.get_or_404(id)
|
||||||
return send_file(
|
|
||||||
BytesIO(file.file), download_name=file.filename, as_attachment=True
|
response = make_response(
|
||||||
|
send_file(
|
||||||
|
BytesIO(file.file),
|
||||||
|
download_name=file.filename,
|
||||||
|
as_attachment=True
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set cache headers
|
||||||
|
response.headers['Cache-Control'] = 'public, max-age=31536000' # 1 year
|
||||||
|
response.headers['Pragma'] = 'cache'
|
||||||
|
response.headers['Expires'] = 'Thu, 31 Dec 2037 23:55:55 GMT' # Far future date
|
||||||
|
|
||||||
|
return response
|
||||||
|
# return send_file(
|
||||||
|
# BytesIO(file.file), download_name=file.filename, as_attachment=True
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
@pitch_book_controller.route("/<int:id>", methods=["PUT"])
|
@pitch_book_controller.route("/<int:id>", methods=["PUT"])
|
||||||
def update_file(id):
|
def update_file(id):
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,4 @@ helm-charts
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.idea
|
.idea
|
||||||
coverage*
|
coverage*
|
||||||
|
dist
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ import { useNavigate, useRouter } from "@tanstack/react-router";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import FileUpload from "react-material-file-upload";
|
import FileUpload from "react-material-file-upload";
|
||||||
import { socket } from "../socket";
|
import { socket } from "../socket";
|
||||||
import { API_HOST } from "../util/api";
|
import { uploadPitchBook } from "../util/api";
|
||||||
|
// import { API_HOST } from "../util/api";
|
||||||
import { CircularProgressWithLabel } from "./CircularProgressWithLabel";
|
import { CircularProgressWithLabel } from "./CircularProgressWithLabel";
|
||||||
|
|
||||||
export default function UploadPage() {
|
export default function UploadPage() {
|
||||||
|
|
@ -15,23 +16,23 @@ export default function UploadPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const uploadFile = useCallback(async () => {
|
// const uploadFile = useCallback(async () => {
|
||||||
const formData = new FormData();
|
// const formData = new FormData();
|
||||||
formData.append("file", files[0]);
|
// formData.append("file", files[0]);
|
||||||
const response = await fetch(`${API_HOST}/api/pitch_book`, {
|
// const response = await fetch(`${API_HOST}/api/pitch_book/`, {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
body: formData,
|
// body: formData,
|
||||||
});
|
// });
|
||||||
|
|
||||||
if (response.ok) {
|
// if (response.ok) {
|
||||||
console.log("File uploaded successfully");
|
// console.log("File uploaded successfully");
|
||||||
const data = await response.json();
|
// const data = await response.json();
|
||||||
setPageId(data.id.toString());
|
// setPageId(data.id.toString());
|
||||||
setLoadingState(5);
|
// setLoadingState(5);
|
||||||
} else {
|
// } else {
|
||||||
console.error("Failed to upload file");
|
// console.error("Failed to upload file");
|
||||||
}
|
// }
|
||||||
}, [files]);
|
// }, [files]);
|
||||||
|
|
||||||
const onConnection = useCallback(() => {
|
const onConnection = useCallback(() => {
|
||||||
console.log("connected");
|
console.log("connected");
|
||||||
|
|
@ -166,7 +167,13 @@ export default function UploadPage() {
|
||||||
backgroundColor: "#383838",
|
backgroundColor: "#383838",
|
||||||
}}
|
}}
|
||||||
disabled={files.length === 0}
|
disabled={files.length === 0}
|
||||||
onClick={uploadFile}
|
onClick={async () => {
|
||||||
|
setLoadingState(1);
|
||||||
|
setPageId("-1");
|
||||||
|
const id = await uploadPitchBook(files);
|
||||||
|
setPageId(id.toString());
|
||||||
|
setLoadingState(5);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Kennzahlen extrahieren
|
Kennzahlen extrahieren
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { Kennzahl } from "@/types/kpi";
|
import type { Kennzahl } from "@/types/kpi";
|
||||||
|
|
||||||
const API_HOST = import.meta.env.VITE_API_HOST || "http://localhost:5050";
|
// const API_HOST = import.meta.env.VITE_API_HOST || "http://localhost:5050";
|
||||||
|
const API_HOST = "";
|
||||||
|
|
||||||
export { API_HOST };
|
export { API_HOST };
|
||||||
|
|
||||||
|
|
@ -122,3 +123,21 @@ export async function fetchPitchBooksById(id: number) {
|
||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const uploadPitchBook = async (files: File[]): Promise<number> => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", files[0]);
|
||||||
|
const response = await fetch(`${API_HOST}/api/pitch_book/`, {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log("File uploaded successfully");
|
||||||
|
const data = await response.json();
|
||||||
|
return data.id.toString();
|
||||||
|
} else {
|
||||||
|
console.error("Failed to upload file");
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue