feat: add reusable private and shared account icons

This commit is contained in:
陈煜 committed 2026-10-01 18:55:15 +08:00
1 parent d2b2681698
commit a4e9d56b8a
44 files changed
+1443 -20

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
require('dotenv/config');
const { PrismaClient } = require('@prisma/client');
const { readFile } = require('node:fs/promises');
const { join } = require('node:path');
const { createHash } = require('node:crypto');
const sharp = require('sharp');
const db = new PrismaClient();
async function main() {
const dir = join(__dirname, '../assets/icons');
const sources = JSON.parse(await readFile(join(dir, 'sources.json'), 'utf8'));
// Deterministic IDs make repeated runs safe, without overwriting existing records.
for (const item of sources) {
const data = await sharp(await readFile(join(dir, item.file)))
.resize(256, 256, { fit: 'inside', withoutEnlargement: true })
.png()
.toBuffer();
const hex = createHash('sha256')
.update('worthpath-builtin:' + item.name)
.digest('hex');
const id = `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
await db.icon.upsert({
where: { id },
create: {
id,
name: item.name,
shared: true,
data,
source: item.source,
hash: createHash('sha256').update(data).digest('hex'),
},
update: {},
});
}
console.log(`Shared icon catalog ready: ${sources.length} icons.`);
}
main()
.catch(() => {
console.error('Icon seeding failed; check local database configuration.');
process.exitCode = 1;
})
.finally(() => db.$disconnect());