(
prevState: ActionState | null,
formData: {
urls: string;
},
)
| 340 | } |
| 341 | |
| 342 | export async function bulkUploadBookmarks( |
| 343 | prevState: ActionState | null, |
| 344 | formData: { |
| 345 | urls: string; |
| 346 | }, |
| 347 | ): Promise<ActionState> { |
| 348 | try { |
| 349 | const urls = formData.urls; |
| 350 | if (!urls) { |
| 351 | return { error: "No URLs provided" }; |
| 352 | } |
| 353 | |
| 354 | const urlList = urls.split("\n").filter((url) => url.trim()); |
| 355 | let successCount = 0; |
| 356 | let errorCount = 0; |
| 357 | |
| 358 | for (let i = 0; i < urlList.length; i++) { |
| 359 | const url = urlList[i].trim(); |
| 360 | if (!url) continue; |
| 361 | |
| 362 | try { |
| 363 | const content = await generateContent(url); |
| 364 | if (content.error) { |
| 365 | errorCount++; |
| 366 | continue; |
| 367 | } |
| 368 | |
| 369 | // Create bookmark data with proper types |
| 370 | const bookmarkData: BookmarkData = { |
| 371 | title: content.title, |
| 372 | description: content.description, |
| 373 | url: content.url, |
| 374 | overview: content.overview, |
| 375 | search_results: content.search_results, |
| 376 | favicon: content.favicon, |
| 377 | ogImage: content.ogImage, |
| 378 | slug: content.slug, |
| 379 | categoryId: null, |
| 380 | isFavorite: false, |
| 381 | isArchived: false, |
| 382 | createdAt: new Date(), |
| 383 | updatedAt: new Date(), |
| 384 | }; |
| 385 | |
| 386 | await db.insert(bookmarks).values(bookmarkData); |
| 387 | |
| 388 | successCount++; |
| 389 | revalidatePath("/admin"); |
| 390 | revalidatePath("/[slug]"); |
| 391 | |
| 392 | // Return progress update |
| 393 | return { |
| 394 | success: true, |
| 395 | progress: { |
| 396 | current: i + 1, |
| 397 | total: urlList.length, |
| 398 | lastAdded: content.title, |
| 399 | }, |
no test coverage detected