Files
desa-darmasaba/prisma/seed_assets.ts
nico df154806f7 Fix image di seafile sudah tidak pakai token tapi by folder di seafile
Kasih console di page profil ppid & visi misi di Profile Desa
2026-02-05 11:10:30 +08:00

50 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { getAllPublicCdnUrls } from "./lib/create_file_share_folder";
export default async function seedAssets() {
const images = await getAllPublicCdnUrls();
for (const img of images) {
try {
// Check if the image already exists by name
const existingImage = await prisma.fileStorage.findUnique({
where: { name: img.name },
});
if (!existingImage) {
// Only create if it doesn't exist
await prisma.fileStorage.create({
data: {
name: img.name,
category: "image",
mimeType: "image/webp",
link: img.cdnUrl,
path: "images",
realName: img.name,
isActive: true,
},
});
console.log(`✅ Created new image: ${img.name}`);
} else {
console.log(` Image already exists, skipping: ${img.name}`);
}
} catch (err) {
console.log(`❌ Failed to seed asset ${img.name}:`, JSON.stringify(err));
}
}
console.log("🎉 Image seeding completed");
}
if (import.meta.main) {
seedAssets()
.then(() => {
console.log("seed assets success");
})
.catch((err) => {
console.log("gagal seed assets", JSON.stringify(err));
});
}