Strip null values for changelog and set size limit for large content blocks

This commit is contained in:
thiloho
2024-10-06 02:01:15 +02:00
parent b53f4c4859
commit 1b8f093f5b
5 changed files with 21 additions and 10 deletions

View File

@@ -73,7 +73,7 @@ CREATE TABLE internal.header (
CREATE TABLE internal.home (
website_id UUID PRIMARY KEY REFERENCES internal.website (id) ON DELETE CASCADE,
main_content TEXT NOT NULL CHECK (TRIM(main_content) != ''),
main_content VARCHAR(200000) NOT NULL CHECK (TRIM(main_content) != ''),
meta_description VARCHAR(250) CHECK (TRIM(meta_description) != ''),
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL
@@ -101,7 +101,7 @@ CREATE TABLE internal.article (
meta_author VARCHAR(100) CHECK (TRIM(meta_author) != ''),
cover_image UUID REFERENCES internal.media (id) ON DELETE SET NULL,
publication_date DATE,
main_content TEXT CHECK (TRIM(main_content) != ''),
main_content VARCHAR(200000) CHECK (TRIM(main_content) != ''),
category UUID REFERENCES internal.docs_category (id) ON DELETE SET NULL,
article_weight INTEGER CHECK (article_weight IS NULL OR article_weight >= 0),
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
@@ -119,7 +119,7 @@ CREATE TABLE internal.footer (
CREATE TABLE internal.legal_information (
website_id UUID PRIMARY KEY REFERENCES internal.website (id) ON DELETE CASCADE,
main_content TEXT NOT NULL CHECK (TRIM(main_content) != ''),
main_content VARCHAR(200000) NOT NULL CHECK (TRIM(main_content) != ''),
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL

View File

@@ -63,6 +63,7 @@
<textarea
{name}
rows="20"
maxlength="200000"
bind:value={previewContent.value}
bind:this={mainContentTextarea}
onscroll={updateScrollPercentage}

View File

@@ -147,7 +147,13 @@ const createMarkdownParser = (showToc = true) => {
export const md = (markdownContent: string, showToc = true) => {
const marked = createMarkdownParser(showToc);
const html = DOMPurify.sanitize(marked.parse(markdownContent) as string);
let html = "";
try {
html = DOMPurify.sanitize(marked.parse(markdownContent, { async: false }));
} catch (_) {
html = "Failed to parse markdown";
}
return html;
};

View File

@@ -29,7 +29,10 @@ export const load: PageServerLoad = async ({ parent, fetch, params, url }) => {
const constructedFetchUrl = `${baseFetchUrl}&${searchParams.toString()}&limit=20&offset=${resultOffset}`;
const changeLog: (ChangeLog & { user: { username: User["username"] } })[] = (
await apiRequest(fetch, constructedFetchUrl, "GET", { returnData: true })
await apiRequest(fetch, constructedFetchUrl, "GET", {
headers: { Accept: "application/vnd.pgrst.array+json;nulls=stripped" },
returnData: true
})
).data;
const resultChangeLogData = await apiRequest(fetch, constructedFetchUrl, "HEAD", {
@@ -92,7 +95,10 @@ export const actions: Actions = {
fetch,
`${API_BASE_PREFIX}/change_log?id=eq.${data.get("id")}&select=old_value,new_value`,
"GET",
{ headers: { Accept: "application/vnd.pgrst.object+json" }, returnData: true }
{
headers: { Accept: "application/vnd.pgrst.object+json;nulls=stripped" },
returnData: true
}
)
).data;

View File

@@ -155,14 +155,12 @@
{#if new_value && !old_value}
<h4>New value</h4>
<pre style="white-space: pre-wrap">{@html (DOMPurify.sanitize(newValue),
{ ALLOWED_TAGS: ["ins", "del"] })}</pre>
<pre style="white-space: pre-wrap">{DOMPurify.sanitize(newValue)}</pre>
{/if}
{#if old_value && !new_value}
<h4>Old value</h4>
<pre style="white-space: pre-wrap">{@html (DOMPurify.sanitize(oldValue),
{ ALLOWED_TAGS: ["ins", "del"] })}</pre>
<pre style="white-space: pre-wrap">{DOMPurify.sanitize(oldValue)}</pre>
{/if}
</Modal>
</td>