some improvements regurading filepaths
This commit is contained in:
10
app.js
10
app.js
@@ -111,9 +111,10 @@ class Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class PDFDocument {
|
class PDFDocument {
|
||||||
constructor(filename) {
|
constructor(filename, fileID) {
|
||||||
this.pdf = new PDFView(filename);
|
this.pdf = new PDFView(filename);
|
||||||
this.fname = filename;
|
this.fname = filename;
|
||||||
|
this.fID = fileID;
|
||||||
this.rects = [];
|
this.rects = [];
|
||||||
this.cnv = document.querySelector("#drw_cnv");
|
this.cnv = document.querySelector("#drw_cnv");
|
||||||
this.ctx = this.cnv.getContext("2d");
|
this.ctx = this.cnv.getContext("2d");
|
||||||
@@ -264,7 +265,8 @@ function submitPdf(eve) {
|
|||||||
console.log(doc.paramRects);
|
console.log(doc.paramRects);
|
||||||
formdata.append("rects", JSON.stringify(doc.paramRects));
|
formdata.append("rects", JSON.stringify(doc.paramRects));
|
||||||
formdata.append("pagescales", JSON.stringify(doc.pagescales.slice(1)));
|
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);
|
console.log(formdata);
|
||||||
submitForm(formdata);
|
submitForm(formdata);
|
||||||
}
|
}
|
||||||
@@ -310,7 +312,7 @@ async function uploadFile(formData) {
|
|||||||
console.log(response);
|
console.log(response);
|
||||||
delete doc.pdf;
|
delete doc.pdf;
|
||||||
delete doc;
|
delete doc;
|
||||||
doc = new PDFDocument(responseJSON.path);
|
doc = new PDFDocument(responseJSON.path, responseJSON.fid);
|
||||||
} else {
|
} else {
|
||||||
console.log("upload failed");
|
console.log("upload failed");
|
||||||
}
|
}
|
||||||
@@ -338,7 +340,7 @@ function initListeners() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const startPdf = () => {
|
const startPdf = () => {
|
||||||
doc = new PDFDocument("./VO_Mathematik_3.pdf");
|
doc = new PDFDocument("./VO_Mathematik_3.pdf", 0);
|
||||||
//pdf = new PDFView("./VO_Mathematik_3.pdf");
|
//pdf = new PDFView("./VO_Mathematik_3.pdf");
|
||||||
initDraw();
|
initDraw();
|
||||||
initUpload();
|
initUpload();
|
||||||
|
|||||||
Binary file not shown.
18
app/main.py
18
app/main.py
@@ -1,16 +1,17 @@
|
|||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
from typing import List, Dict, Tuple
|
from typing import List, Dict, Tuple
|
||||||
from datetime import date
|
|
||||||
from fastapi import FastAPI, File, UploadFile, Request, Form
|
from fastapi import FastAPI, File, UploadFile, Request, Form
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
import pymupdf
|
import pymupdf
|
||||||
import pdf2image
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.mount("/static", StaticFiles(directory="./"), name="static")
|
app.mount("/static", StaticFiles(directory="./"), name="static")
|
||||||
|
|
||||||
|
locpaths = ["./VO_Mathematik_3.pdf"] # replace this with a database
|
||||||
|
|
||||||
|
|
||||||
@app.post("/files/")
|
@app.post("/files/")
|
||||||
async def create_file(file: Annotated[bytes, File()]):
|
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):
|
async def create_upload_file(file: UploadFile):
|
||||||
content = await file.read()
|
content = await file.read()
|
||||||
filename = file.filename if file.filename is not None else "None"
|
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)
|
f.write(content)
|
||||||
app.mount("/files", StaticFiles(directory="./app/files/"), name="files")
|
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/")
|
@app.post("/submit/")
|
||||||
@@ -32,6 +39,7 @@ async def get_submittion(
|
|||||||
lva: Annotated[str, Form()], # LVA Name and Number
|
lva: Annotated[str, Form()], # LVA Name and Number
|
||||||
prof: Annotated[str, Form()], # Vortragender
|
prof: Annotated[str, Form()], # Vortragender
|
||||||
fname: Annotated[str, Form()], # Path to pdf File
|
fname: Annotated[str, Form()], # Path to pdf File
|
||||||
|
fileId: Annotated[int, Form()],
|
||||||
sem: Annotated[str, Form()], # Semester eg. 2024W
|
sem: Annotated[str, Form()], # Semester eg. 2024W
|
||||||
stype: Annotated[str, Form()], # Type of File eg. Prüfung
|
stype: Annotated[str, Form()], # Type of File eg. Prüfung
|
||||||
ex_date: Annotated[str, Form()], # Date of Exam only when type is exam
|
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)
|
print(lva, prof, fname, stype, sem, ex_date, rects, pagescales)
|
||||||
rects_p = json.loads(rects)
|
rects_p = json.loads(rects)
|
||||||
scales_p = json.loads(pagescales)
|
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"}
|
return {"done": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html lang="de">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Unizeug uploader</title>
|
<title>Unizeug uploader</title>
|
||||||
|
|||||||
Reference in New Issue
Block a user