Files
desa-darmasaba/prisma/seed_assets.ts
nico 358ff14efe Seeder Menu Lingkungan dan Pendidikan
Fix Jam Operasional Kantor Desa Darmasaba
2026-02-03 16:53:15 +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 { getAllDownloadUrls } from "./lib/get_images";
export default async function seedAssets() {
const images = await getAllDownloadUrls();
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.downloadUrl,
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));
// });
// }