configuration wiki editor link to bind with slug

This commit is contained in:
taDuc
2026-05-10 01:28:41 +07:00
parent 655454d83a
commit 78824ed07a
3 changed files with 360 additions and 14 deletions
+14 -1
View File
@@ -1,9 +1,10 @@
import { API_ENDPOINTS } from "@/uhm/api/config";
import { requestJson } from "@/uhm/api/http";
import { ApiError, requestJson } from "@/uhm/api/http";
export type Wiki = {
id: string;
title?: string;
slug?: string | null;
content?: string;
is_deleted?: boolean;
created_at?: string;
@@ -28,6 +29,18 @@ export async function fetchWikiById(id: string): Promise<Wiki> {
return requestJson<Wiki>(`${API_ENDPOINTS.wikis}/${encodeURIComponent(wikiId)}`);
}
export async function fetchWikiBySlug(slug: string): Promise<Wiki | null> {
const value = String(slug || "").trim();
if (!value.length) return null;
try {
return await requestJson<Wiki>(`${API_ENDPOINTS.wikis}/slug/${encodeURIComponent(value)}`);
} catch (err) {
// Treat "not found" as an empty result for search UX.
if (err instanceof ApiError && err.status === 404) return null;
throw err;
}
}
export async function checkWikiSlugExists(slug: string): Promise<boolean> {
const value = String(slug || "").trim();
if (!value.length) return false;