2026-11-05 18:01:08 +03:30
|
|
|
import { PrismaClient } from '@prisma/client';
|
2026-11-05 18:12:23 +03:30
|
|
|
import { existsSync, mkdirSync, copyFileSync } from 'fs';
|
|
|
|
|
import { join } from 'path';
|
2026-11-05 18:01:08 +03:30
|
|
|
import { PLUGIN_CATALOG_SEED } from '../src/plugins/plugin-catalog.seed';
|
|
|
|
|
|
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
|
|
|
|
|
|
async function main() {
|
2026-11-05 18:12:23 +03:30
|
|
|
console.log('Updating plugin store catalog descriptions and images in database...');
|
|
|
|
|
|
|
|
|
|
const sourceDir = join(__dirname, 'plugin-images');
|
|
|
|
|
const targetDir = join(process.cwd(), 'uploads', 'plugins');
|
|
|
|
|
|
|
|
|
|
if (!existsSync(targetDir)) {
|
|
|
|
|
mkdirSync(targetDir, { recursive: true });
|
|
|
|
|
console.log(`Created directory: ${targetDir}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 18:01:08 +03:30
|
|
|
let updatedCount = 0;
|
|
|
|
|
|
|
|
|
|
for (const seed of PLUGIN_CATALOG_SEED) {
|
2026-11-07 12:24:08 +03:30
|
|
|
// Check if there is a cache-busted _v2 version (e.g. enable_automation_v2.png)
|
|
|
|
|
const baseFilename = `${seed.settingKey}.png`;
|
|
|
|
|
const v2Filename = `${seed.settingKey}_v2.png`;
|
|
|
|
|
|
|
|
|
|
let activeFilename = baseFilename;
|
|
|
|
|
if (existsSync(join(sourceDir, v2Filename))) {
|
|
|
|
|
activeFilename = v2Filename;
|
|
|
|
|
copyFileSync(join(sourceDir, v2Filename), join(targetDir, v2Filename));
|
|
|
|
|
}
|
2026-11-05 18:12:23 +03:30
|
|
|
|
|
|
|
|
let hasImage = false;
|
2026-11-07 12:24:08 +03:30
|
|
|
const baseSrc = join(sourceDir, baseFilename);
|
|
|
|
|
if (existsSync(baseSrc)) {
|
|
|
|
|
copyFileSync(baseSrc, join(targetDir, baseFilename));
|
2026-11-05 18:12:23 +03:30
|
|
|
hasImage = true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-07 12:24:08 +03:30
|
|
|
if (activeFilename === v2Filename) {
|
|
|
|
|
hasImage = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const imageUrl = `/uploads/plugins/${activeFilename}`;
|
2026-11-05 18:12:23 +03:30
|
|
|
|
2026-11-05 18:01:08 +03:30
|
|
|
const res = await prisma.pluginCatalogItem.updateMany({
|
|
|
|
|
where: { settingKey: seed.settingKey },
|
|
|
|
|
data: {
|
|
|
|
|
description: seed.description,
|
|
|
|
|
titleFa: seed.titleFa,
|
2026-11-05 18:12:23 +03:30
|
|
|
...(hasImage ? { images: [imageUrl] } : {}),
|
2026-11-05 18:01:08 +03:30
|
|
|
},
|
|
|
|
|
});
|
2026-11-05 18:12:23 +03:30
|
|
|
|
2026-11-05 18:01:08 +03:30
|
|
|
if (res.count > 0) {
|
2026-11-07 12:24:08 +03:30
|
|
|
console.log(`✓ Updated [${seed.settingKey}] - ${seed.titleFa} -> ${imageUrl}`);
|
2026-11-05 18:01:08 +03:30
|
|
|
updatedCount += res.count;
|
|
|
|
|
} else {
|
2026-11-05 18:12:23 +03:30
|
|
|
console.log(`- Item [${seed.settingKey}] not found in DB`);
|
2026-11-05 18:01:08 +03:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 18:12:23 +03:30
|
|
|
console.log(`\nSuccessfully updated ${updatedCount} plugin store items with descriptions and images!`);
|
2026-11-05 18:01:08 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
.catch((e) => {
|
2026-11-05 18:12:23 +03:30
|
|
|
console.error('Error updating descriptions and images:', e);
|
2026-11-05 18:01:08 +03:30
|
|
|
process.exit(1);
|
|
|
|
|
})
|
|
|
|
|
.finally(async () => {
|
|
|
|
|
await prisma.$disconnect();
|
|
|
|
|
});
|