From: PhiTux Date: Tue, 17 Jun 2025 16:59:07 +0000 (+0200) Subject: added history-menu for text X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=658dd094a4128dc9f9d2a50d90bc2fc85adcd006;p=DailyTxT.git added history-menu for text --- diff --git a/backend/server/routers/logs.py b/backend/server/routers/logs.py index 1b522ce..8b7c0bc 100644 --- a/backend/server/routers/logs.py +++ b/backend/server/routers/logs.py @@ -31,10 +31,12 @@ async def saveLog(log: Log, cookie = Depends(users.isLoggedIn)): content:dict = fileHandling.getMonth(cookie["user_id"], year, month) + history_available = False # move old log to history if "days" in content.keys(): for dayLog in content["days"]: if dayLog["day"] == day and "text" in dayLog.keys(): + history_available = True historyVersion = 0 if "history" not in dayLog.keys(): dayLog["history"] = [] @@ -52,7 +54,7 @@ async def saveLog(log: Log, cookie = Depends(users.isLoggedIn)): ''' IMPORTANT: Escaping html characters here is NOT possible, since it would break the appearance of html-code in the EDITOR. Code inside a markdown code-quote (`...`) will be auto-escaped. - Not a perfect solution, but actually any user can only load its own logs... + Not a perfect solution, but actually any user can only load its own logs (and so XSS himself)... ''' encrypted_text = security.encrypt_text(log.text, enc_key) encrypted_date_written = security.encrypt_text(html.escape(log.date_written), enc_key) @@ -75,7 +77,7 @@ async def saveLog(log: Log, cookie = Depends(users.isLoggedIn)): logger.error(f"Failed to save log for {cookie['user_id']} on {year}-{month:02d}-{day:02d}") return {"success": False} - return {"success": True} + return {"success": True, "history_available": history_available} @router.get("/getLog") @@ -93,13 +95,16 @@ async def getLog(day: int, month: int, year: int, cookie = Depends(users.isLogge enc_key = security.get_enc_key(cookie["user_id"], cookie["derived_key"]) text = "" date_written = "" + history_available = False if "text" in dayLog.keys(): text = security.decrypt_text(dayLog["text"], enc_key) date_written = security.decrypt_text(dayLog["date_written"], enc_key) if "files" in dayLog.keys(): for file in dayLog["files"]: file["filename"] = security.decrypt_text(file["enc_filename"], enc_key) - return {"text": text, "date_written": date_written, "files": dayLog.get("files", []), "tags": dayLog.get("tags", [])} + if "history" in dayLog.keys() and len(dayLog["history"]) > 0: + history_available = True + return {"text": text, "date_written": date_written, "files": dayLog.get("files", []), "tags": dayLog.get("tags", []), "history_available": history_available} return dummy @@ -555,11 +560,6 @@ async def saveTemplates(templates: Templates, cookie = Depends(users.isLoggedIn) else: return {"success": True} -""" class OnThisDay(BaseModel): - day: int - month: int - year: int - years: list[int] """ @router.get("/getOnThisDay") async def getOnThisDay(day: int, month: int, year: int, last_years: str, cookie = Depends(users.isLoggedIn)): @@ -583,4 +583,26 @@ async def getOnThisDay(day: int, month: int, year: int, last_years: str, cookie except: continue - return results \ No newline at end of file + return results + + +@router.get("/getHistory") +async def getHistory(day: int, month: int, year: int, cookie = Depends(users.isLoggedIn)): + enc_key = security.get_enc_key(cookie["user_id"], cookie["derived_key"]) + + content:dict = fileHandling.getMonth(cookie["user_id"], year, month) + + if "days" not in content.keys(): + return [] + + for dayLog in content["days"]: + if dayLog["day"] == day and "history" in dayLog.keys(): + history = [] + for historyLog in dayLog["history"]: + history.append({ + "text": security.decrypt_text(historyLog["text"], enc_key), + "date_written": security.decrypt_text(historyLog["date_written"], enc_key) + }) + return history + + return [] \ No newline at end of file diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 7eb8a6c..9512689 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -113,6 +113,7 @@ let settingsModal; function openSettingsModal() { $tempSettings = JSON.parse(JSON.stringify($settings)); + onThisDayYears = $settings.onThisDayYears.toString(); settingsModal = new bootstrap.Modal(document.getElementById('settingsModal')); settingsModal.show(); diff --git a/frontend/src/routes/write/+page.svelte b/frontend/src/routes/write/+page.svelte index 67478bc..5ec77d2 100644 --- a/frontend/src/routes/write/+page.svelte +++ b/frontend/src/routes/write/+page.svelte @@ -15,7 +15,10 @@ faCloudArrowUp, faCloudArrowDown, faSquarePlus, - faQuestionCircle + faQuestionCircle, + faClockRotateLeft, + faArrowLeft, + faArrowRight } from '@fortawesome/free-solid-svg-icons'; import Fa from 'svelte-fa'; import { v4 as uuidv4 } from 'uuid'; @@ -30,6 +33,7 @@ import TemplateDropdown from '$lib/TemplateDropdown.svelte'; import { templates, insertTemplate } from '$lib/templateStore'; import OnThisDay from '$lib/OnThisDay.svelte'; + import { marked } from 'marked'; axios.interceptors.request.use((config) => { config.withCredentials = true; @@ -188,6 +192,7 @@ }); } + let historyAvailable = $state(false); async function getLog() { if (savedLog !== currentLog) { const success = await saveLog(); @@ -208,6 +213,7 @@ currentLog = response.data.text; filesOfDay = response.data.files; selectedTags = response.data.tags; + historyAvailable = response.data.history_available; savedLog = currentLog; @@ -354,6 +360,7 @@ if (response.data.success) { savedLog = currentLog; logDateWritten = date_written; + historyAvailable = response.data.history_available; // add to $cal.daysWithLogs if (!$cal.daysWithLogs.includes(lastSelectedDate.day)) { @@ -741,6 +748,52 @@ isSavingNewTag = false; }); } + + let history = $state([]); + let historySelected = $state(0); + function getHistory() { + axios + .get(API_URL + '/logs/getHistory', { + params: { + day: $selectedDate.day, + month: $selectedDate.month, + year: $selectedDate.year + } + }) + .then((response) => { + if (response.data.length === 0) { + // no history + return; + } + + history = response.data.map((log) => { + return { + text: log.text, + date_written: log.date_written + }; + }); + historySelected = history.length - 1; + + // show history in a modal or something + const modal = new bootstrap.Modal(document.getElementById('modalHistory')); + modal.show(); + }) + .catch((error) => { + console.error(error); + const toast = new bootstrap.Toast(document.getElementById('toastErrorLoadingLog')); + toast.show(); + }); + } + + function selectHistory() { + if (historySelected < 0 || historySelected >= history.length) return; + + currentLog = history[historySelected].text; + //logDateWritten = history[historySelected].date_written; + + tinyMDE.setContent(currentLog); + tinyMDE.setSelection({ row: 0, col: 0 }); + } @@ -790,7 +843,13 @@
Geschrieben am:
{logDateWritten} -
history
+ {#if historyAvailable} +
+ +
+ {/if}
delete
@@ -1065,6 +1124,72 @@
+ +