(
prevState: ActionState | null,
formData: {
title: string;
description: string;
url: string;
slug: string;
overview: string;
favicon: string;
ogImage: string;
search_results: string;
categoryId: string;
isFavorite: string;
isArchived: string;
},
)
| 163 | |
| 164 | // Bookmark Actions |
| 165 | export async function createBookmark( |
| 166 | prevState: ActionState | null, |
| 167 | formData: { |
| 168 | title: string; |
| 169 | description: string; |
| 170 | url: string; |
| 171 | slug: string; |
| 172 | overview: string; |
| 173 | favicon: string; |
| 174 | ogImage: string; |
| 175 | search_results: string; |
| 176 | categoryId: string; |
| 177 | isFavorite: string; |
| 178 | isArchived: string; |
| 179 | }, |
| 180 | ): Promise<ActionState> { |
| 181 | try { |
| 182 | const title = formData.title; |
| 183 | const description = formData.description; |
| 184 | const url = formData.url; |
| 185 | let slug = formData.slug; |
| 186 | const overview = formData.overview; |
| 187 | const favicon = formData.favicon; |
| 188 | const ogImage = formData.ogImage; |
| 189 | const search_results = formData.search_results; |
| 190 | const categoryId = formData.categoryId; |
| 191 | const isFavorite = formData.isFavorite === "true"; |
| 192 | const isArchived = formData.isArchived === "true"; |
| 193 | |
| 194 | // Generate slug if not provided |
| 195 | if (!slug) { |
| 196 | slug = generateSlug(title); |
| 197 | } |
| 198 | |
| 199 | await db.insert(bookmarks).values({ |
| 200 | title, |
| 201 | slug, |
| 202 | url, |
| 203 | description, |
| 204 | categoryId: categoryId === "none" ? null : categoryId, |
| 205 | search_results: search_results || null, |
| 206 | isFavorite, |
| 207 | isArchived, |
| 208 | overview, |
| 209 | favicon, |
| 210 | ogImage, |
| 211 | }); |
| 212 | |
| 213 | revalidatePath("/admin"); |
| 214 | revalidatePath("/"); |
| 215 | |
| 216 | return { success: true }; |
| 217 | } catch (err) { |
| 218 | console.error("Error creating bookmark:", err); |
| 219 | return { error: "Failed to create bookmark" }; |
| 220 | } |
| 221 | } |
| 222 |
no test coverage detected