diff --git a/framerail/src/lib/server/page/history.ts b/framerail/src/lib/server/page/history.ts new file mode 100644 index 0000000000..33c3debc74 --- /dev/null +++ b/framerail/src/lib/server/page/history.ts @@ -0,0 +1,28 @@ +import { wellfetch } from "$lib/server/deepwell/index.ts" +import type { Optional } from "$lib/types.ts" + +export async function pageHistory( + siteId: number, + pageId: Optional, + slug: string +): Promise { + const response = await wellfetch("/page/revision/range", { + method: "PUT", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + siteId, + pageId: pageId, + revisionNumber: -1, + revisionDirection: "before", + limit: 200 + }) + }) + + if (!response.ok) { + throw new Error("Unable to get data from server") + } + + return response.json() +} diff --git a/framerail/src/lib/server/page/index.ts b/framerail/src/lib/server/page/index.ts new file mode 100644 index 0000000000..0c69d605e6 --- /dev/null +++ b/framerail/src/lib/server/page/index.ts @@ -0,0 +1,11 @@ +import { pageDelete } from "$lib/server/page/delete" +import { pageEdit } from "$lib/server/page/edit" +import { pageMove } from "$lib/server/page/move" +import { pageHistory } from "$lib/server/page/history" + +export { + pageDelete, + pageEdit, + pageMove, + pageHistory +} diff --git a/framerail/src/routes/+error.svelte b/framerail/src/routes/+error.svelte index 30d1d2a048..925c8afdba 100644 --- a/framerail/src/routes/+error.svelte +++ b/framerail/src/routes/+error.svelte @@ -13,7 +13,7 @@ let fdata = new FormData(form) fdata.set("site-id", $page.error.site.siteId) fdata.set("slug", $page.params.slug) - await fetch(`/${$page.params.slug}`, { + await fetch(`/${$page.params.slug}/edit`, { method: "POST", body: fdata }) diff --git a/framerail/src/routes/[slug]/[...extra]/+server.ts b/framerail/src/routes/[slug]/[...extra]/+server.ts index 06535fee36..3822e3ec1e 100644 --- a/framerail/src/routes/[slug]/[...extra]/+server.ts +++ b/framerail/src/routes/[slug]/[...extra]/+server.ts @@ -1,35 +1,50 @@ -import { pageDelete } from "$lib/server/page/delete" -import { pageEdit } from "$lib/server/page/edit" -import { pageMove } from "$lib/server/page/move" +import * as page from "$lib/server/page" -/** - * Edit or create page. - */ export async function POST(event) { let data = await event.request.formData() let slug = event.params.slug + let extra = event.params.extra?.toLowerCase().split("/").filter((flag) => flag.length) + let pageIdVal = data.get("page-id")?.toString() let pageId = pageIdVal ? parseInt(pageIdVal) : null let siteId = parseInt(data.get("site-id")?.toString() ?? "1") - let comments = data.get("comments")?.toString() ?? "" - let wikitext = data.get("wikitext")?.toString() - let title = data.get("title")?.toString() - let altTitle = data.get("alt-title")?.toString() - let tagsStr = data.get("tags")?.toString().trim() - let tags: string[] = [] - if (tagsStr?.length) tags = tagsStr.split(" ").filter((tag) => tag.length) - let res = await pageEdit( - siteId, - pageId, - slug, - comments, - wikitext, - title, - altTitle, - tags - ) + let res: object = {}; + + if (extra.includes("edit")) { + /** + * Edit or create page. + */ + let comments = data.get("comments")?.toString() ?? "" + let wikitext = data.get("wikitext")?.toString() + let title = data.get("title")?.toString() + let altTitle = data.get("alt-title")?.toString() + let tagsStr = data.get("tags")?.toString().trim() + let tags: string[] = [] + if (tagsStr?.length) tags = tagsStr.split(" ").filter((tag) => tag.length) + + res = await page.pageEdit( + siteId, + pageId, + slug, + comments, + wikitext, + title, + altTitle, + tags + ) + + } else if (extra.includes("history")) { + /** + * Retrieve page revision list. + */ + res = await page.pageHistory( + siteId, + pageId, + slug + ) + } return new Response(JSON.stringify(res)) } @@ -46,7 +61,7 @@ export async function DELETE(event) { let siteId = parseInt(data.get("site-id")?.toString() ?? "1") let comments = data.get("comments")?.toString() ?? "" - let res = await pageDelete(siteId, pageId, slug, comments) + let res = await page.pageDelete(siteId, pageId, slug, comments) return new Response(JSON.stringify(res)) } @@ -63,7 +78,7 @@ export async function PUT(event) { let comments = data.get("comments")?.toString() ?? "" let newSlug = data.get("new-slug")?.toString() - let res = await pageMove(siteId, pageId, slug, newSlug, comments) + let res = await page.pageMove(siteId, pageId, slug, newSlug, comments) return new Response(JSON.stringify(res)) } diff --git a/framerail/src/routes/[slug]/[...extra]/page.svelte b/framerail/src/routes/[slug]/[...extra]/page.svelte index 1cf7792a65..121638fdaa 100644 --- a/framerail/src/routes/[slug]/[...extra]/page.svelte +++ b/framerail/src/routes/[slug]/[...extra]/page.svelte @@ -1,8 +1,10 @@

UNTRANSLATED:Loaded page

@@ -172,6 +185,15 @@ UT:Edit +
+ +
{/if} {#if showMoveAction} @@ -214,6 +236,41 @@ {/if} +{#if showHistory} +
+
+
+ Revision # +
+
+ Created +
+
+ User +
+
+ Comments +
+
+ {#each revisionList.reverse() as revision} +
+
+ {revision.revision_number} +
+
+ {revision.created_at} +
+
+ {revision.user_id} +
+
+ {revision.comments} +
+
+ {/each} +
+{/if} +