diff --git a/app/__pycache__/main.cpython-313.pyc b/app/__pycache__/main.cpython-313.pyc index bc800ae..ce6523c 100644 Binary files a/app/__pycache__/main.cpython-313.pyc and b/app/__pycache__/main.cpython-313.pyc differ diff --git a/app/graphics/empty.pdf b/app/graphics/empty.pdf new file mode 100644 index 0000000..00d9972 Binary files /dev/null and b/app/graphics/empty.pdf differ diff --git a/app/graphics/empty.svg b/app/graphics/empty.svg new file mode 100644 index 0000000..f4e3004 --- /dev/null +++ b/app/graphics/empty.svg @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + diff --git a/app/graphics/greeting.pdf b/app/graphics/greeting.pdf new file mode 100644 index 0000000..8142378 Binary files /dev/null and b/app/graphics/greeting.pdf differ diff --git a/app/graphics/greeting.svg b/app/graphics/greeting.svg new file mode 100644 index 0000000..b84abe7 --- /dev/null +++ b/app/graphics/greeting.svg @@ -0,0 +1,193 @@ + + + +Servus, + Sie sind auf der Uploadseite für Unterlagen der Fachschaft Elektrotechnik gelandet. Sie haben noch keine Unterlage ausgewählt, die Sie hochladen möchten. Um Unterlagen hochzuladen betätigen Sie bitte den Knopf "Browse" in der linken oberen Ecke des Bildschirms oder Ziehen Sie Unterlagen auf das Graue Feld, auf dem sich der besagte Knopf befindet, und lassen sie diese dort fallen. Ist dies erledigt, kann der Knopf "Upload" betätigt werden. Danach werden die Unterlagen, falls sie ein unterstütztes Format aufweisen statt dieser Seite angezeigt. Zensieren Sie alle Namen, indem Sie Rechtecke über diese Ziehen. Wählen Sie danach in der linken Bildschirmhälfte alle auf die Unterlagen zutreffenden Parameter aus und drücken Sie auf Senden. Danach wird die Fertige Unterlage in einem neuen Tab geöffnet. Tipp: Die Checkbox "Zensieren" ist standardmäßig ausgewählt. Wenn in dem Dokument nichts zu zensieren ist, können Sie diese abwählen, das erlaubt, das Dokument eventuell in besserer Qualität zu speichern. diff --git a/app/graphics/text2.pdf b/app/graphics/text2.pdf new file mode 100644 index 0000000..c89c950 Binary files /dev/null and b/app/graphics/text2.pdf differ diff --git a/app/graphics/unsupported.pdf b/app/graphics/unsupported.pdf new file mode 100644 index 0000000..11d66a1 Binary files /dev/null and b/app/graphics/unsupported.pdf differ diff --git a/app/graphics/unsupported.svg b/app/graphics/unsupported.svg new file mode 100644 index 0000000..0d59a87 --- /dev/null +++ b/app/graphics/unsupported.svg @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/main.py b/app/main.py index d6c9858..856eee7 100644 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,10 @@ from typing import List, Dict, Tuple from annotated_types import IsDigit from fastapi import FastAPI, File, HTTPException, UploadFile, Request, Form from fastapi.responses import FileResponse +# import multiprocessing +# import threading +# import concurrent.futures +# import asyncio # import fastapi from fastapi.staticfiles import StaticFiles @@ -48,6 +52,9 @@ EX_DATE_CATEGORIES = ["Prüfungen", "Klausuren"] EX_DATE_CATEGORIES_I = [0, 1] UNIZEUG_PATH = "./app/dest/" FILES_IN_PROGRESS = "./app/files/" +EMPTYFILE = "./app/graphics/empty.pdf" +UNSUPPORTEDFILE = "./app/graphics/unsupported.pdf" +GREETINGFILE = "./app/graphics/greeting.pdf" # cur = db.cursor() @@ -66,10 +73,12 @@ async def get_file(file_id: str): """returns the file that cooorosponds with the given ID""" if file_id == "unsupported": error("File is unsupported") - return FileResponse(FILES_IN_PROGRESS + "unsupported.pdf") + return FileResponse(UNSUPPORTEDFILE) if file_id == "empty": error("File Id empty") - return FileResponse(FILES_IN_PROGRESS + "empty.pdf") + return FileResponse(EMPTYFILE) + if file_id == "greeting": + return FileResponse(GREETINGFILE) cur = db.cursor() try: cur.execute("Select filename from FIP where id=?", (file_id,)) @@ -308,7 +317,7 @@ async def get_submission( pagescales: Annotated[ str, Form() ], # Scales of Pages # Annotated[List[Dict[str, float]], Form()], - censor: Annotated[str, Form()] | bool = False, + censor: Annotated[str, Form()], ): """handles submission""" print( @@ -333,13 +342,15 @@ async def get_submission( except ValueError as e: error(f"Error creating savepath: f{e}") raise HTTPException(status_code=400, detail=str(e)) - censor_pdf(filepath, dest, rects_p, scales_p, False if censor is False else True) + await censor_pdf( + filepath, dest, rects_p, scales_p, False if censor == "False" else True + ) # return {"done": "ok"} print(dest) return FileResponse(dest, content_disposition_type="inline") -def censor_pdf( +async def censor_pdf( path: str, destpath: str, rects: List[List[List[float]]], @@ -360,10 +371,13 @@ def censor_pdf( doc = pymupdf.open(path) output = pymupdf.open() page = doc[0] - width = page.rect.width - height = page.rect.height - print(width, height) - for i in range(doc.page_count): + # width = page.rect.width + # height = page.rect.height + # print(width, height) + npage = doc.page_count + # pages = [] + # tasks = [] + for i in range(npage): page = doc[i] if i < len(rects) and rects[i] != []: print(i) @@ -382,18 +396,53 @@ def censor_pdf( fill=(0, 0, 0), ) if secure: + # pages.append(page) bitmap = page.get_pixmap(dpi=400) pdf_bytes = bitmap.pdfocr_tobytes( language="deu", tessdata="/usr/share/tessdata/", # tesseract needs to be installed; this is the path to thetesseract files ) output.insert_pdf(pymupdf.Document(stream=pdf_bytes)) - print(f" Page {i}/{doc.page_count} CENSORING DONE") + # tasks.append(asyncio.create_task(censor_page(page))) + print(f"Page {i + 1}/{npage}: CENSORING DONE") else: output.insert_pdf(doc, i, i) + + # if secure: + # pages_bytes: List[bytes] = [] + # censor_page(pages[0]) + # with multiprocessing.Pool(npage) as p: + # pages_bytes = p.map(censor_page, pages) + # pages_bytes = p.map(test_function, [1, 2, 3, 4]) + # for pdf_bytes in pages_bytes: + # output.insert_pdf(pymupdf.Document(stream=pdf_bytes)) + # with concurrent.futures.ThreadPoolExecutor() as executor: + # futures = [] + # for page in pages: + # futures.append(executor.submit(censor_page, page)) + # for future in futures: + # output.insert_pdf(pymupdf.Document(stream=future.result())) + # + # for task in tasks: + # output.insert_pdf(pymupdf.Document(stream=await task)) + # print("CENSORING DONE") output.save(destpath) +def test_function(i: int) -> bytes: + return b"\x00\x66\x99" + + +async def censor_page(page: pymupdf.Page) -> bytes: + bitmap = page.get_pixmap(dpi=400) + pdf_bytes = bitmap.pdfocr_tobytes( + language="deu", + tessdata="/usr/share/tessdata/", # tesseract needs to be installed; this is the path to thetesseract files + ) + # print(pdf_bytes) + return pdf_bytes + + # def save_without_censoring(dest) diff --git a/static/app.js b/static/app.js index 9e75402..db14387 100644 --- a/static/app.js +++ b/static/app.js @@ -273,6 +273,9 @@ function submitPdf(eve) { formdata.append("fileId", doc.fID); //formdata.append("filename", doc.filename); formdata.append("ftype", doc.filetype); + if (!formdata.has("censor")) { + formdata.append("censor", "False"); + } console.log(formdata); submitForm(formdata); } @@ -361,12 +364,13 @@ function initListeners() { }); } const startPdf = () => { - doc = new PDFDocument( - "./files/b78c869f-e0bb-11ef-9b58-84144d05d665", - "b78c869f-e0bb-11ef-9b58-84144d05d665", - "pdf", - ); + // doc = new PDFDocument( + // "./files/b78c869f-e0bb-11ef-9b58-84144d05d665", + // "b78c869f-e0bb-11ef-9b58-84144d05d665", + // "pdf", + // ); //pdf = new PDFView("./VO_Mathematik_3.pdf"); + doc = new PDFDocument("./files/greeting", "greeting", "pdf"); initDraw(); initUpload(); initListeners(); diff --git a/static/autocomplete.js b/static/autocomplete.js index 74d6fbd..c1f0c4f 100644 --- a/static/autocomplete.js +++ b/static/autocomplete.js @@ -170,9 +170,21 @@ function autocomplete(inp, type) { closeAllLists(e.target); }); } +function enter_current_semeseter() { + var semField = document.getElementById("sem"); + var today = new Date(); + var year = today.getFullYear(); + var month = today.getMonth(); + if (month < 9 && month > 1) { + semField.value = String(year) + "S"; + } else { + semField.value = String(year) + "W"; + } +} function init() { autocomplete(document.getElementById("lva"), "lva"); autocomplete(document.getElementById("prof"), "prof"); autocomplete(document.getElementById("subcat"), "subcat"); + enter_current_semeseter(); } window.addEventListener("load", init); diff --git a/static/style.css b/static/style.css index 03f4764..1593cbb 100644 --- a/static/style.css +++ b/static/style.css @@ -39,6 +39,15 @@ span { justify-content: space-between; } +button { + background-color: #0872a9; + /* border-radius: 20px; */ + border-top-left-radius: 10px; + border-top-right-radius: 10px; + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; +} + .main { height: 100vh; width: 100vw;