diff --git a/app.js b/app.js index 805e6fd..71967fe 100644 --- a/app.js +++ b/app.js @@ -111,9 +111,10 @@ class Rectangle { } } class PDFDocument { - constructor(filename) { + constructor(filename, fileID) { this.pdf = new PDFView(filename); this.fname = filename; + this.fID = fileID; this.rects = []; this.cnv = document.querySelector("#drw_cnv"); this.ctx = this.cnv.getContext("2d"); @@ -264,7 +265,8 @@ function submitPdf(eve) { console.log(doc.paramRects); formdata.append("rects", JSON.stringify(doc.paramRects)); formdata.append("pagescales", JSON.stringify(doc.pagescales.slice(1))); - formdata.append("fname", doc.fname); + formdata.append("fileId", doc.fID); + formdata.append("filename", doc.filename); console.log(formdata); submitForm(formdata); } @@ -310,7 +312,7 @@ async function uploadFile(formData) { console.log(response); delete doc.pdf; delete doc; - doc = new PDFDocument(responseJSON.path); + doc = new PDFDocument(responseJSON.path, responseJSON.fid); } else { console.log("upload failed"); } @@ -338,7 +340,7 @@ function initListeners() { }); } const startPdf = () => { - doc = new PDFDocument("./VO_Mathematik_3.pdf"); + doc = new PDFDocument("./VO_Mathematik_3.pdf", 0); //pdf = new PDFView("./VO_Mathematik_3.pdf"); initDraw(); initUpload(); diff --git a/app/__pycache__/main.cpython-313.pyc b/app/__pycache__/main.cpython-313.pyc index 4fe65ec..721923a 100644 Binary files a/app/__pycache__/main.cpython-313.pyc and b/app/__pycache__/main.cpython-313.pyc differ diff --git a/app/main.py b/app/main.py index 4fdcb57..365d55e 100644 --- a/app/main.py +++ b/app/main.py @@ -1,16 +1,17 @@ from typing import Annotated from typing import List, Dict, Tuple -from datetime import date from fastapi import FastAPI, File, UploadFile, Request, Form from fastapi.staticfiles import StaticFiles import pymupdf -import pdf2image import json +import os app = FastAPI() app.mount("/static", StaticFiles(directory="./"), name="static") +locpaths = ["./VO_Mathematik_3.pdf"] # replace this with a database + @app.post("/files/") async def create_file(file: Annotated[bytes, File()]): @@ -21,10 +22,16 @@ async def create_file(file: Annotated[bytes, File()]): async def create_upload_file(file: UploadFile): content = await file.read() filename = file.filename if file.filename is not None else "None" - with open("./app/files/" + filename, "wb") as f: + locpath = "./app/files/" + filename + locpaths.append(locpath) + with open(locpath, "wb") as f: f.write(content) app.mount("/files", StaticFiles(directory="./app/files/"), name="files") - return {"filename": filename, "path": "/files/" + filename} + return { + "filename": filename, + "path": "/files/" + filename, + "fid": len(locpaths) - 1, + } @app.post("/submit/") @@ -32,6 +39,7 @@ async def get_submittion( lva: Annotated[str, Form()], # LVA Name and Number prof: Annotated[str, Form()], # Vortragender fname: Annotated[str, Form()], # Path to pdf File + fileId: Annotated[int, Form()], sem: Annotated[str, Form()], # Semester eg. 2024W stype: Annotated[str, Form()], # Type of File eg. Prüfung ex_date: Annotated[str, Form()], # Date of Exam only when type is exam @@ -45,7 +53,7 @@ async def get_submittion( print(lva, prof, fname, stype, sem, ex_date, rects, pagescales) rects_p = json.loads(rects) scales_p = json.loads(pagescales) - censor_pdf(fname, "./app/files/censored.pdf", rects_p, scales_p) + censor_pdf(locpaths[fileId], "./app/files/censored.pdf", rects_p, scales_p) return {"done": "ok"} diff --git a/index.html b/index.html index 85b9f16..ced4506 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - +