feat(plugins): add preview images and auto-copy to uploads on seed update
|
After Width: | Height: | Size: 297 KiB |
|
After Width: | Height: | Size: 304 KiB |
|
After Width: | Height: | Size: 304 KiB |
|
After Width: | Height: | Size: 301 KiB |
|
After Width: | Height: | Size: 302 KiB |
|
After Width: | Height: | Size: 310 KiB |
|
After Width: | Height: | Size: 304 KiB |
|
After Width: | Height: | Size: 313 KiB |
|
After Width: | Height: | Size: 299 KiB |
|
After Width: | Height: | Size: 295 KiB |
|
After Width: | Height: | Size: 300 KiB |
|
After Width: | Height: | Size: 296 KiB |
|
After Width: | Height: | Size: 325 KiB |
|
After Width: | Height: | Size: 300 KiB |
|
After Width: | Height: | Size: 301 KiB |
|
After Width: | Height: | Size: 299 KiB |
|
After Width: | Height: | Size: 301 KiB |
|
After Width: | Height: | Size: 301 KiB |
@@ -1,34 +1,59 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
import { existsSync, mkdirSync, copyFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
import { PLUGIN_CATALOG_SEED } from '../src/plugins/plugin-catalog.seed';
|
import { PLUGIN_CATALOG_SEED } from '../src/plugins/plugin-catalog.seed';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log('Updating plugin store catalog descriptions in database...');
|
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}`);
|
||||||
|
}
|
||||||
|
|
||||||
let updatedCount = 0;
|
let updatedCount = 0;
|
||||||
|
|
||||||
for (const seed of PLUGIN_CATALOG_SEED) {
|
for (const seed of PLUGIN_CATALOG_SEED) {
|
||||||
|
const filename = `${seed.settingKey}.png`;
|
||||||
|
const srcFile = join(sourceDir, filename);
|
||||||
|
const destFile = join(targetDir, filename);
|
||||||
|
|
||||||
|
let hasImage = false;
|
||||||
|
if (existsSync(srcFile)) {
|
||||||
|
copyFileSync(srcFile, destFile);
|
||||||
|
hasImage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const imageUrl = `/uploads/plugins/${filename}`;
|
||||||
|
|
||||||
const res = await prisma.pluginCatalogItem.updateMany({
|
const res = await prisma.pluginCatalogItem.updateMany({
|
||||||
where: { settingKey: seed.settingKey },
|
where: { settingKey: seed.settingKey },
|
||||||
data: {
|
data: {
|
||||||
description: seed.description,
|
description: seed.description,
|
||||||
titleFa: seed.titleFa,
|
titleFa: seed.titleFa,
|
||||||
|
...(hasImage ? { images: [imageUrl] } : {}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.count > 0) {
|
if (res.count > 0) {
|
||||||
console.log(`✓ Updated [${seed.settingKey}] - ${seed.titleFa}`);
|
console.log(`✓ Updated [${seed.settingKey}] - ${seed.titleFa} ${hasImage ? '(+ Image)' : ''}`);
|
||||||
updatedCount += res.count;
|
updatedCount += res.count;
|
||||||
} else {
|
} else {
|
||||||
console.log(`- Item [${seed.settingKey}] not yet in DB (will be seeded on next bootstrap)`);
|
console.log(`- Item [${seed.settingKey}] not found in DB`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\nSuccessfully updated ${updatedCount} plugin store items!`);
|
console.log(`\nSuccessfully updated ${updatedCount} plugin store items with descriptions and images!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error('Error updating descriptions:', e);
|
console.error('Error updating descriptions and images:', e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(async () => {
|
||||||
|
|||||||