diff --git a/assets/images/hzone/2026-05-09-screen-shot-2025-11-10-at-18-02-10-fullpage.png b/assets/images/hzone/2026-05-09-screen-shot-2025-11-10-at-18-02-10-fullpage.png new file mode 100644 index 0000000..3aba68e Binary files /dev/null and b/assets/images/hzone/2026-05-09-screen-shot-2025-11-10-at-18-02-10-fullpage.png differ diff --git a/authoring_server.py b/authoring_server.py index ad93576..44b6a07 100755 --- a/authoring_server.py +++ b/authoring_server.py @@ -12,14 +12,15 @@ import subprocess import sys import threading import time -import cgi from dataclasses import dataclass, field from datetime import datetime +from email.parser import BytesParser +from email.policy import default as email_default_policy from email.utils import formatdate from http import HTTPStatus from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from pathlib import Path -from typing import Any +from typing import Any, Callable from urllib.parse import parse_qs, urlparse @@ -272,12 +273,16 @@ class BuildQueue: job.started_at = time.time() job.message = "Publishing site and search index." self._current = job - ok, message, log = run_build_commands() + def append_log(chunk: str) -> None: + with self._lock: + job.log = (job.log + chunk)[-200000:] + + ok, message, log = run_build_commands(append_log) with self._lock: job.finished_at = time.time() job.ok = ok job.message = message - job.log = log + job.log = log[-200000:] self._recent.append(job) self._recent = self._recent[-20:] self._current = None @@ -643,7 +648,7 @@ def save_upload(filename: str, payload: bytes, page_path: str = "") -> dict[str, absolute_url = f"https://zainezq.com/{rel}" relative_url = relative_asset_path(page_path, rel) is_markdown = page_path.endswith(".md") - insert_text = f"![{target.name}]({relative_url})" if is_markdown else f"[[{relative_url}]]" + insert_text = f"![{target.name}]({absolute_url})" if is_markdown else f"[[{relative_url}]]" return { "url": absolute_url, "relativeUrl": relative_url, @@ -654,7 +659,35 @@ def save_upload(filename: str, payload: bytes, page_path: str = "") -> dict[str, } -def run_build_commands() -> tuple[bool, str, str]: +def parse_upload_form(content_type: str, body: bytes) -> tuple[str, bytes, str]: + if not content_type.lower().startswith("multipart/form-data"): + raise ValueError("Uploads must use multipart/form-data.") + message = BytesParser(policy=email_default_policy).parsebytes( + f"Content-Type: {content_type}\r\nMIME-Version: 1.0\r\n\r\n".encode("utf-8") + body + ) + if not message.is_multipart(): + raise ValueError("Upload form is not multipart.") + + filename = "" + payload = b"" + page_path = "" + for part in message.iter_parts(): + name = part.get_param("name", header="content-disposition") + if name == "attachment": + filename = part.get_filename() or "" + payload = part.get_payload(decode=True) or b"" + elif name == "pagePath": + raw_value = part.get_payload(decode=True) or b"" + page_path = raw_value.decode(part.get_content_charset() or "utf-8", errors="replace") + + if not filename: + raise ValueError("No attachment was uploaded.") + if not payload: + raise ValueError("Attachment is empty.") + return filename, payload, page_path + + +def run_build_commands(log_callback: Callable[[str], None] | None = None) -> tuple[bool, str, str]: venv_python = ROOT / ".venv" / "bin" / "python" venv_pip = ROOT / ".venv" / "bin" / "pip" commands = [["emacs", "-Q", "--script", "build-site.el"]] @@ -667,20 +700,33 @@ def run_build_commands() -> tuple[bool, str, str]: ) commands.append([str(venv_python), "search-index-json.py"]) combined = [] + + def append_log(text: str) -> None: + combined.append(text) + if log_callback: + log_callback(text) + ok = True for command in commands: - combined.append(f"$ {' '.join(command)}\n") - proc = subprocess.run( + append_log(f"$ {' '.join(command)}\n") + env = os.environ.copy() + env["PYTHONUNBUFFERED"] = "1" + proc = subprocess.Popen( command, cwd=ROOT, + env=env, text=True, - stdout=subprocess.PIPE, + bufsize=1, stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, ) - combined.append(proc.stdout) - if proc.returncode != 0: + assert proc.stdout is not None + for line in proc.stdout: + append_log(line) + return_code = proc.wait() + if return_code != 0: ok = False - combined.append(f"\nCommand exited with {proc.returncode}.\n") + append_log(f"\nCommand exited with {return_code}.\n") break message = "Build complete. The site output and search index were regenerated." if ok else "Build failed. Check the log below." return ok, message, "".join(combined) @@ -1058,9 +1104,21 @@ APP_HTML = r""" return String(value).replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[char])); } + function previewImageUrl(src) { + const value = String(src || ""); + if (value.startsWith("https://author.zainezq.com/assets/")) { + return value.replace("https://author.zainezq.com/assets/", "https://zainezq.com/assets/"); + } + const relativeAsset = value.match(/^(?:\.\.\/)+assets\/(.+)$/); + if (relativeAsset) return `https://zainezq.com/assets/${relativeAsset[1]}`; + if (value.startsWith("/assets/")) return `https://zainezq.com${value}`; + if (value.startsWith("assets/")) return `https://zainezq.com/${value}`; + return value; + } + function renderInlineMarkdown(value) { let out = html(value); - out = out.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '$1'); + out = out.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_match, alt, src) => `${alt}`); out = out.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); out = out.replace(/\*\*([^*]+)\*\*/g, '$1'); out = out.replace(/\*([^*]+)\*/g, '$1'); @@ -1173,14 +1231,15 @@ APP_HTML = r""" } async function refreshBuild() { + const wasRunning = Boolean(state.build && state.build.running); try { state.build = await api("/api/build"); renderStatus(); + if (wasRunning && !state.build.running) await refreshPages(); } catch (err) { statusBox.className = "status fail"; statusBox.textContent = `Could not refresh build status: ${err.message}`; } - await refreshPages(); } editor.title.addEventListener("input", () => { @@ -1224,6 +1283,7 @@ APP_HTML = r""" const saved = await api("/api/page", { method: "POST", body: JSON.stringify(payload) }); setForm(saved); saveMessage.textContent = "Saved. Build queued."; + await refreshPages(); await refreshBuild(); } catch (err) { saveMessage.textContent = err.message; @@ -1509,24 +1569,12 @@ class Handler(BaseHTTPRequestHandler): def do_POST(self) -> None: if self.path == "/api/upload": try: - form = cgi.FieldStorage( - fp=self.rfile, - headers=self.headers, - environ={ - "REQUEST_METHOD": "POST", - "CONTENT_TYPE": self.headers.get("Content-Type", ""), - }, + length = int(self.headers.get("Content-Length", "0")) + filename, payload, page_path = parse_upload_form( + self.headers.get("Content-Type", ""), + self.rfile.read(length), ) - field = form["attachment"] if "attachment" in form else None - if field is None or not getattr(field, "filename", ""): - raise ValueError("No attachment was uploaded.") - payload = field.file.read() - if not payload: - raise ValueError("Attachment is empty.") - page_path = "" - if "pagePath" in form: - page_path = str(form["pagePath"].value or "") - self.send_json(save_upload(field.filename, payload, page_path)) + self.send_json(save_upload(filename, payload, page_path)) except Exception as exc: self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST) return diff --git a/lima/index.md b/lima/index.md old mode 100755 new mode 100644 index ad3430f..ad47b50 --- a/lima/index.md +++ b/lima/index.md @@ -9,3 +9,8 @@ I made quite a few changes. It all started when I realised that not everyone kno - I probably didn’t explain it as well, but you can create folders and files under the `lima-website` directory. The files must have a `.md` extension at the end (markdown). - One other thing, a more personal one: what do you think of all this? am i doing too much? am i doing too little? am i overengineering things? am i forcing you to do something you dont wanna do? these little trinkets work for me, but i’m not sure if it would work for someone else, so at any point if you have reservations, let me know okay? + + +![2026-05-09-screen-shot-2025-11-10-at-18-02-10-fullpage.png](../assets/images/hzone/2026-05-09-screen-shot-2025-11-10-at-18-02-10-fullpage.png) + +This is a test diff --git a/posts/posts-list.org b/posts/posts-list.org index 8759e3f..4dd7f3d 100644 --- a/posts/posts-list.org +++ b/posts/posts-list.org @@ -4,8 +4,7 @@ See the categories: @@html:Categories@@ * Posts: -- [[file:career/career-list.org][Career List]] @@html:09-05-2026 15:06@@ -- [[file:posts-list.sync-conflict-20260509-150632-VT6366A.org][Posts List]] @@html:09-05-2026 15:06@@ +- [[file:career/career-list.org][Career List]] @@html:09-05-2026 16:24@@ - [[file:career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:11-03-2026 17:18@@ @@html:learning@@ @@html:notes@@ - [[file:career/javascript.org][Understands the Javascript language]] @@html:11-03-2026 16:52@@ @@html:learning@@ @@html:notes@@ - [[file:career/restful-api.org][Restful API]] @@html:15-02-2026 23:00@@ @@html:learning@@ @@html:notes@@ diff --git a/posts/posts-list.sync-conflict-20260509-150632-VT6366A.org b/posts/posts-list.sync-conflict-20260509-150632-VT6366A.org deleted file mode 100644 index 0e4bca5..0000000 --- a/posts/posts-list.sync-conflict-20260509-150632-VT6366A.org +++ /dev/null @@ -1,26 +0,0 @@ -#+TITLE: Posts List -#+OPTIONS: toc:nil num:nil - -See the categories: @@html:Categories@@ - -* Posts: -- [[file:career/career-list.org][Career List]] @@html:09-05-2026 15:05@@ -- [[file:career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] @@html:11-03-2026 17:18@@ @@html:learning@@ @@html:notes@@ -- [[file:career/javascript.org][Understands the Javascript language]] @@html:11-03-2026 16:52@@ @@html:learning@@ @@html:notes@@ -- [[file:career/restful-api.org][Restful API]] @@html:15-02-2026 23:00@@ @@html:learning@@ @@html:notes@@ -- [[file:career/monitoring-and-logging.org][Monitoring and Logging]] @@html:18-01-2026 23:00@@ @@html:learning@@ @@html:notes@@ -- [[file:career/pipelines.org][Pipelines and how they work (as well as CI/CD)]] @@html:18-01-2026 23:00@@ @@html:learning@@ @@html:notes@@ -- [[file:career/database-permissions.org][Database Permissions, Roles, and Accounts]] @@html:18-01-2026 23:00@@ @@html:learning@@ @@html:notes@@ -- [[file:career/probation-objectives.org][Probation Objectives:]] @@html:08-12-2025 17:55@@ @@html:review@@ @@html:notes@@ -- [[file:career/airflow.org][Datamarts, Airflow and DAG's]] @@html:15-11-2025 18:37@@ @@html:learning@@ @@html:notes@@ -- [[file:career/normalisation.org][Benefits of Normalisation]] @@html:10-11-2025 18:04@@ @@html:learning@@ @@html:notes@@ -- [[file:career/wireframe-designs.org][Wireframe Designs]] @@html:06-11-2025 22:01@@ @@html:learning@@ @@html:notes@@ -- [[file:career/management-of-self.org][Management of self training]] @@html:06-11-2025 22:01@@ @@html:learning@@ @@html:notes@@ -- [[file:career/requirements-features.org][Requirements, features, user stories, tasks, walking skeletons]] @@html:06-11-2025 22:01@@ @@html:learning@@ @@html:notes@@ -- [[file:career/career-intro.org][Career Introduction]] @@html:06-11-2025 21:29@@ @@html:introduction@@ -- [[file:career/invest-principles.org][Invest Principles]] @@html:06-11-2025 21:08@@ @@html:learning@@ @@html:notes@@ -- [[file:career/lean.org][Lean]] @@html:05-11-2025 20:46@@ @@html:learning@@ @@html:notes@@ -- [[file:career/retrospectives.org][Retrospectives]] @@html:05-11-2025 20:46@@ @@html:learning@@ @@html:notes@@ -- [[file:career/owasp.org][OWASP Top Ten]] @@html:19-10-2025 13:21@@ @@html:learning@@ @@html:notes@@ -- [[file:career/solid-principles.org][SOLID Principles]] @@html:18-10-2025 19:14@@ @@html:learning@@ @@html:notes@@ -- [[file:posts-intro.org][Posts Introduction]] @@html:06-08-2025 00:00@@ @@html:introduction@@ \ No newline at end of file diff --git a/recently-updated.org b/recently-updated.org index b57c673..0c0f9f9 100644 --- a/recently-updated.org +++ b/recently-updated.org @@ -2,9 +2,6 @@ #+OPTIONS: toc:nil num:nil * Recently Updated (top 26 files) -- [[file:posts/posts-list.sync-conflict-20260509-150632-VT6366A.org][Posts List]] @@html:2026-05-09 15:06@@ -- [[file:sitemap.sync-conflict-20260509-150632-VT6366A.org][Sitemap]] @@html:2026-05-09 15:06@@ -- [[file:sitemap.sync-conflict-20260509-150611-VT6366A.org][Sitemap]] @@html:2026-05-09 15:06@@ - [[file:home/notes.org][Notes]] @@html:2026-05-09 15:05@@ - [[file:home/wird-tracker.org][Wird Tracker]] @@html:2026-05-09 01:18@@ - [[file:home/status.org][Competency Status Board]] @@html:2026-05-09 01:18@@ @@ -28,3 +25,6 @@ - [[file:blogs/2026/04-april/12-04-week-review.org][[12-04-2026] - Weekly Review]] @@html:2026-04-12 12:00@@ - [[file:blogs/2026/04-april/starting-new-rotation-08-04-26.org][Starting new rotation]] @@html:2026-04-08 16:15@@ - [[file:blogs/2026/04-april/action-plan-07-04-26.org][Action plan to change teams]] @@html:2026-04-07 10:04@@ +- [[file:blogs/2026/04-april/weekly-target-06-04-26.org][[06-04-2026] - Weekly target]] @@html:2026-04-06 22:53@@ +- [[file:blogs/2026/04-april/making-notes-through-org-noter-06-05.org][Making Notes through Org Noter]] @@html:2026-04-06 14:30@@ +- [[file:blogs/2026/04-april/05-04-week-review.org][[05-04-2026] - Weekly Review]] @@html:2026-04-05 12:00@@ diff --git a/requirements.txt b/requirements.txt index 6f83e94..b8ba271 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ beautifulsoup4 lxml +legacy-cgi diff --git a/sitemap.org b/sitemap.org index 4d00ad7..35e626d 100644 --- a/sitemap.org +++ b/sitemap.org @@ -1,8 +1,6 @@ #+TITLE: Sitemap - [[file:index.org][Home]] -- [[file:sitemap.sync-conflict-20260509-150611-VT6366A.org][Sitemap]] -- [[file:sitemap.sync-conflict-20260509-150632-VT6366A.org][Sitemap]] - [[file:wip.org][Work in progress]] - [[file:recently-updated.org][Recently Updated]] - tags @@ -44,7 +42,6 @@ - [[file:blogs/blogs-list.org][Blogs List]] - posts - [[file:posts/posts-intro.org][Posts Introduction]] - - [[file:posts/posts-list.sync-conflict-20260509-150632-VT6366A.org][Posts List]] - [[file:posts/posts-list.org][Posts List]] - career - [[file:posts/career/solid-principles.org][SOLID Principles]] diff --git a/sitemap.sync-conflict-20260509-150611-VT6366A.org b/sitemap.sync-conflict-20260509-150611-VT6366A.org deleted file mode 100644 index 4d5f753..0000000 --- a/sitemap.sync-conflict-20260509-150611-VT6366A.org +++ /dev/null @@ -1,65 +0,0 @@ -#+TITLE: Sitemap - -- [[file:index.org][Home]] -- [[file:wip.org][Work in progress]] -- [[file:recently-updated.org][Recently Updated]] -- home - - [[file:home/countdown.org][Countdown]] - - [[file:home/backlog.org][Backlog]] - - [[file:home/status.org][Competency Status Board]] - - [[file:home/services.org][Service]] - - [[file:home/wird-tracker.org][Wird Tracker]] - - [[file:home/contact.org][Contact]] - - [[file:home/notes.org][Notes]] - - [[file:home/categories.org][Categories]] - - guide - - [[file:home/guide/setup.org][Setup]] - - [[file:home/guide/wird-tracker-guide.org][Wird Tracker — Technical Guide]] -- books - - [[file:books/books-list.org][Books List]] - - clean-code - - [[file:books/clean-code/clean-code-notes.org][Clean Code Notes]] -- blogs - - [[file:blogs/blogs-intro.org][Blogs Introduction]] - - [[file:blogs/publish-pages.org][How to publish pages using Org Publish]] - - [[file:blogs/blogs-list.org][Blogs List]] -- lima - - [[file:lima/lima-list.org][Lima]] -- tags - - [[file:tags/life.sync-conflict-20260417-233423-VT6366A.org][Tag: life]] - - [[file:tags/review.sync-conflict-20260328-203248-VT6366A.org][Tag: review]] - - [[file:tags/introduction.org][Tag: introduction]] - - [[file:tags/learning.org][Tag: learning]] - - [[file:tags/notes.org][Tag: notes]] - - [[file:tags/review.org][Tag: review]] - - [[file:tags/website.org][Tag: website]] - - [[file:tags/life.org][Tag: life]] - - [[file:tags/update.org][Tag: update]] - - [[file:tags/insights.org][Tag: insights]] - - [[file:tags/emacs.org][Tag: emacs]] - - [[file:tags/education.org][Tag: education]] - - [[file:tags/reading.org][Tag: reading]] - - [[file:tags/maths.org][Tag: maths]] -- posts - - [[file:posts/posts-intro.org][Posts Introduction]] - - [[file:posts/posts-list.org][Posts List]] - - career - - [[file:posts/career/solid-principles.org][SOLID Principles]] - - [[file:posts/career/owasp.org][OWASP Top Ten]] - - [[file:posts/career/lean.org][Lean]] - - [[file:posts/career/retrospectives.org][Retrospectives]] - - [[file:posts/career/invest-principles.org][Invest Principles]] - - [[file:posts/career/career-intro.org][Career Introduction]] - - [[file:posts/career/wireframe-designs.org][Wireframe Designs]] - - [[file:posts/career/management-of-self.org][Management of self training]] - - [[file:posts/career/requirements-features.org][Requirements, features, user stories, tasks, walking skeletons]] - - [[file:posts/career/normalisation.org][Benefits of Normalisation]] - - [[file:posts/career/airflow.org][Datamarts, Airflow and DAG's]] - - [[file:posts/career/probation-objectives.org][Probation Objectives:]] - - [[file:posts/career/monitoring-and-logging.org][Monitoring and Logging]] - - [[file:posts/career/pipelines.org][Pipelines and how they work (as well as CI/CD)]] - - [[file:posts/career/database-permissions.org][Database Permissions, Roles, and Accounts]] - - [[file:posts/career/restful-api.org][Restful API]] - - [[file:posts/career/javascript.org][Understands the Javascript language]] - - [[file:posts/career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] - - [[file:posts/career/career-list.org][Career List]] \ No newline at end of file diff --git a/sitemap.sync-conflict-20260509-150632-VT6366A.org b/sitemap.sync-conflict-20260509-150632-VT6366A.org deleted file mode 100644 index 4d5dafa..0000000 --- a/sitemap.sync-conflict-20260509-150632-VT6366A.org +++ /dev/null @@ -1,66 +0,0 @@ -#+TITLE: Sitemap - -- [[file:index.org][Home]] -- [[file:sitemap.sync-conflict-20260509-150611-VT6366A.org][Sitemap]] -- [[file:wip.org][Work in progress]] -- [[file:recently-updated.org][Recently Updated]] -- home - - [[file:home/countdown.org][Countdown]] - - [[file:home/backlog.org][Backlog]] - - [[file:home/status.org][Competency Status Board]] - - [[file:home/services.org][Service]] - - [[file:home/wird-tracker.org][Wird Tracker]] - - [[file:home/contact.org][Contact]] - - [[file:home/notes.org][Notes]] - - [[file:home/categories.org][Categories]] - - guide - - [[file:home/guide/setup.org][Setup]] - - [[file:home/guide/wird-tracker-guide.org][Wird Tracker — Technical Guide]] -- books - - [[file:books/books-list.org][Books List]] - - clean-code - - [[file:books/clean-code/clean-code-notes.org][Clean Code Notes]] -- blogs - - [[file:blogs/blogs-intro.org][Blogs Introduction]] - - [[file:blogs/publish-pages.org][How to publish pages using Org Publish]] - - [[file:blogs/blogs-list.org][Blogs List]] -- lima - - [[file:lima/lima-list.org][Lima]] -- tags - - [[file:tags/life.sync-conflict-20260417-233423-VT6366A.org][Tag: life]] - - [[file:tags/review.sync-conflict-20260328-203248-VT6366A.org][Tag: review]] - - [[file:tags/learning.org][Tag: learning]] - - [[file:tags/introduction.org][Tag: introduction]] - - [[file:tags/notes.org][Tag: notes]] - - [[file:tags/website.org][Tag: website]] - - [[file:tags/review.org][Tag: review]] - - [[file:tags/life.org][Tag: life]] - - [[file:tags/emacs.org][Tag: emacs]] - - [[file:tags/education.org][Tag: education]] - - [[file:tags/update.org][Tag: update]] - - [[file:tags/reading.org][Tag: reading]] - - [[file:tags/insights.org][Tag: insights]] - - [[file:tags/maths.org][Tag: maths]] -- posts - - [[file:posts/posts-intro.org][Posts Introduction]] - - [[file:posts/posts-list.org][Posts List]] - - career - - [[file:posts/career/solid-principles.org][SOLID Principles]] - - [[file:posts/career/owasp.org][OWASP Top Ten]] - - [[file:posts/career/lean.org][Lean]] - - [[file:posts/career/retrospectives.org][Retrospectives]] - - [[file:posts/career/invest-principles.org][Invest Principles]] - - [[file:posts/career/career-intro.org][Career Introduction]] - - [[file:posts/career/wireframe-designs.org][Wireframe Designs]] - - [[file:posts/career/management-of-self.org][Management of self training]] - - [[file:posts/career/requirements-features.org][Requirements, features, user stories, tasks, walking skeletons]] - - [[file:posts/career/normalisation.org][Benefits of Normalisation]] - - [[file:posts/career/airflow.org][Datamarts, Airflow and DAG's]] - - [[file:posts/career/probation-objectives.org][Probation Objectives:]] - - [[file:posts/career/monitoring-and-logging.org][Monitoring and Logging]] - - [[file:posts/career/pipelines.org][Pipelines and how they work (as well as CI/CD)]] - - [[file:posts/career/database-permissions.org][Database Permissions, Roles, and Accounts]] - - [[file:posts/career/restful-api.org][Restful API]] - - [[file:posts/career/javascript.org][Understands the Javascript language]] - - [[file:posts/career/ha-dr.org][High Availability, Disaster Recovery and Business Continuity]] - - [[file:posts/career/career-list.org][Career List]] \ No newline at end of file diff --git a/tests/test_authoring_server.py b/tests/test_authoring_server.py index 9e314db..69aae75 100755 --- a/tests/test_authoring_server.py +++ b/tests/test_authoring_server.py @@ -103,6 +103,24 @@ class UtilityTests(AuthoringServerTestCase): self.assertEqual(server.image_dimensions(gif, ".gif"), (320, 200)) self.assertIsNone(server.image_dimensions(b"not an image", ".png")) + def test_parse_upload_form_reads_attachment_and_page_path(self): + boundary = "----authoring-test" + content_type = f"multipart/form-data; boundary={boundary}" + body = ( + f"--{boundary}\r\n" + 'Content-Disposition: form-data; name="pagePath"\r\n\r\n' + "lima/index.md\r\n" + f"--{boundary}\r\n" + 'Content-Disposition: form-data; name="attachment"; filename="photo.png"\r\n' + "Content-Type: image/png\r\n\r\n" + ).encode("utf-8") + b"image bytes\r\n" + f"--{boundary}--\r\n".encode("utf-8") + + filename, payload, page_path = server.parse_upload_form(content_type, body) + + self.assertEqual(filename, "photo.png") + self.assertEqual(payload, b"image bytes") + self.assertEqual(page_path, "lima/index.md") + class PageRenderingTests(AuthoringServerTestCase): def test_render_org_writes_metadata_and_body(self): @@ -244,6 +262,22 @@ class PageRenderingTests(AuthoringServerTestCase): self.assertEqual(saved["path"], "assets/images/blogs/2026-05-07-lunch.jpg") self.assertEqual(saved["insertText"], "[[../../../assets/images/blogs/2026-05-07-lunch.jpg]]") + def test_save_upload_inserts_absolute_public_url_for_markdown(self): + with mock.patch.object(server, "datetime") as datetime_mock: + datetime_mock.now.return_value = datetime(2026, 5, 9, 9, 30) + saved = server.save_upload( + "Screen Shot.png", + b"image bytes", + "lima/index.md", + ) + + self.assertEqual(saved["path"], "assets/images/hzone/2026-05-09-screen-shot.png") + self.assertEqual(saved["relativeUrl"], "../assets/images/hzone/2026-05-09-screen-shot.png") + self.assertEqual( + saved["insertText"], + "![2026-05-09-screen-shot.png](https://zainezq.com/assets/images/hzone/2026-05-09-screen-shot.png)", + ) + def test_save_upload_rejects_disallowed_extensions(self): with self.assertRaises(ValueError): server.save_upload("shell.php", b"