From 731aef627255d90113798ba3fb56fa356dc7400c Mon Sep 17 00:00:00 2001 From: Lycoon Date: Tue, 21 Apr 2026 02:33:41 +0200 Subject: [PATCH] fixed compilation errors --- .../project/CollaboratorsSettings.tsx | 2 +- components/projects/CreateProjectPage.tsx | 8 +- src/lib/adapters/fountain/fountain_parser.ts | 82 ++++++++++--------- src/lib/import/import-project.ts | 4 +- src/lib/spellcheck/spellcheck.worker.ts | 3 +- src/lib/titlepage/nodes/text-node.ts | 3 +- src/lib/utils/requests.ts | 4 +- 7 files changed, 58 insertions(+), 48 deletions(-) diff --git a/components/dashboard/project/CollaboratorsSettings.tsx b/components/dashboard/project/CollaboratorsSettings.tsx index 29d1a4c..3e7cb69 100644 --- a/components/dashboard/project/CollaboratorsSettings.tsx +++ b/components/dashboard/project/CollaboratorsSettings.tsx @@ -150,7 +150,7 @@ const MemberSlot = ({ data, membership, mutateCollaborators, user }: MemberSlotP if (res.ok) { if (res.status !== 204) { // If user left the project by himself, redirect him to home - const json = (await res.json()) as ApiResponse; + const json = (await res.json()) as ApiResponse<{ redirectUrl: string }>; if (json.data && json.data.redirectUrl) { closeDashboard(); redirect(json.data.redirectUrl); diff --git a/components/projects/CreateProjectPage.tsx b/components/projects/CreateProjectPage.tsx index 35d6400..2e70ac4 100644 --- a/components/projects/CreateProjectPage.tsx +++ b/components/projects/CreateProjectPage.tsx @@ -59,8 +59,8 @@ const CreateProjectPage = ({ setIsCreating }: Props) => { body.poster = await cropImageBase64(selectedFile, 686, 1016); } const res = await createProject(user.id, body); - const json = (await res.json()) as ApiResponse; - if (res.ok) { + const json = (await res.json()) as ApiResponse<{ id: string }>; + if (res.ok && json.data) { projectId = json.data.id; } } catch { @@ -101,8 +101,8 @@ const CreateProjectPage = ({ setIsCreating }: Props) => { } const res = await createProject(user.id, body); - const json = (await res.json()) as ApiResponse; - if (!res.ok) { + const json = (await res.json()) as ApiResponse<{ id: string }>; + if (!res.ok || !json.data) { setFormInfo({ content: json.message!, isError: true }); return; } diff --git a/src/lib/adapters/fountain/fountain_parser.ts b/src/lib/adapters/fountain/fountain_parser.ts index 8c4ce14..8a33313 100644 --- a/src/lib/adapters/fountain/fountain_parser.ts +++ b/src/lib/adapters/fountain/fountain_parser.ts @@ -236,8 +236,16 @@ const tokenize = function (script: string) { return tokens; }; -const inline: Record string | undefined)> = { - //note: '$1', +interface InlineLexer { + (s: string): string | undefined; +} + +interface Inline { + [key: string]: string | InlineLexer | undefined; + lexer: InlineLexer; +} + +const inline: Inline = { line_break: "
", bold_italic_underline: '$2', @@ -247,45 +255,45 @@ const inline: Record string | undefined)> = { bold: '$2', italic: '$2', underline: '$2', -}; - -inline.lexer = function (s: string) { - if (!s) { - return; - } - - const styles = [ - "underline", - "italic", - "bold", - "bold_italic", - "italic_underline", - "bold_underline", - "bold_italic_underline", - ]; - let i = styles.length; - let style: string; - let match: RegExp; - - s = s - .replace(regex.note_inline, inline.note as string) - .replace(/\\\*/g, "[star]") - .replace(/\\_/g, "[underline]") - .replace(/\n/g, inline.line_break as string); - while (i--) { - style = styles[i]; - match = (regex as Record)[style]; + lexer: (s: string) => { + if (!s) { + return; + } - if (match.test(s)) { - s = s.replace(match, inline[style] as string); + const styles = [ + "underline", + "italic", + "bold", + "bold_italic", + "italic_underline", + "bold_underline", + "bold_italic_underline", + ]; + let i = styles.length; + let style: string; + let match: RegExp; + + s = s + .replace(regex.note_inline, (inline.note as string) || "") + .replace(/\\\*/g, "[star]") + .replace(/\\_/g, "[underline]") + .replace(/\n/g, (inline.line_break as string) || ""); + + while (i--) { + style = styles[i]; + match = (regex as Record)[style]; + + if (match.test(s)) { + s = s.replace(match, (inline[style] as string) || ""); + } } - } - return s - .replace(/\[star\]/g, "*") - .replace(/\[underline\]/g, "_") - .trim(); + return s + .replace(/\[star\]/g, "*") + .replace(/\[underline\]/g, "_") + .trim(); + }, }; const parse = function (script: string, toks?: boolean | FountainCallback, callback?: FountainCallback): FountainOutput { diff --git a/src/lib/import/import-project.ts b/src/lib/import/import-project.ts index 6d6609e..fc89bed 100644 --- a/src/lib/import/import-project.ts +++ b/src/lib/import/import-project.ts @@ -138,9 +138,9 @@ async function createRemoteProject(userId: string, title: string, description?: }; const res = await createProject(userId, body); - const json = (await res.json()) as ApiResponse; + const json = (await res.json()) as ApiResponse<{ id: string }>; - if (!res.ok) { + if (!res.ok || !json.data) { throw new Error(json.message || "Failed to create project"); } diff --git a/src/lib/spellcheck/spellcheck.worker.ts b/src/lib/spellcheck/spellcheck.worker.ts index 20e4d5c..414423c 100644 --- a/src/lib/spellcheck/spellcheck.worker.ts +++ b/src/lib/spellcheck/spellcheck.worker.ts @@ -33,7 +33,8 @@ self.onmessage = async (e: MessageEvent) => { post({ type: "ERROR", error: "Hunspell not initialized" }); break; } - const misspelled = msg.words.filter((w) => !hunspell.spell(w)); + const h = hunspell; + const misspelled = msg.words.filter((w) => !h.spell(w)); post({ type: "CHECK_RESULT", id: msg.id, misspelled }); break; } diff --git a/src/lib/titlepage/nodes/text-node.ts b/src/lib/titlepage/nodes/text-node.ts index 3f4473d..2088d57 100644 --- a/src/lib/titlepage/nodes/text-node.ts +++ b/src/lib/titlepage/nodes/text-node.ts @@ -30,7 +30,8 @@ export const TitlePageTextNode = Node.create({ return "left"; }, renderHTML: (attributes: Record) => { - const cls = ALIGN_CLASSES[attributes.textAlign] || ALIGN_CLASSES.left; + const alignment = (attributes.textAlign as string) || "left"; + const cls = ALIGN_CLASSES[alignment] || ALIGN_CLASSES.left; return { class: cls }; }, }, diff --git a/src/lib/utils/requests.ts b/src/lib/utils/requests.ts index ef0e5e8..165cdec 100644 --- a/src/lib/utils/requests.ts +++ b/src/lib/utils/requests.ts @@ -58,8 +58,8 @@ export function getCollabHttpUrl(path: string): string { export const getCloudToken = async (projectId: string): Promise<{ token: string | null; status: number }> => { const res = await request(`/api/projects/${projectId}/cloud-token`, "GET"); if (res.ok) { - const { data: token } = (await res.json()) as ApiResponse; - return { token, status: res.status }; + const { data: token } = (await res.json()) as ApiResponse; + return { token: token ?? null, status: res.status }; } return { token: null, status: res.status }; };