153 lines
4.2 KiB
TypeScript
153 lines
4.2 KiB
TypeScript
|
|
import argon2 from 'argon2';
|
||
|
|
import { PrismaClient, AccessMode, ToolStatus, ArtifactStatus, AdminUserStatus } from '@prisma/client';
|
||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
function todayDateString(): string {
|
||
|
|
return new Date().toISOString().slice(0, 10);
|
||
|
|
}
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
const nowDate = todayDateString();
|
||
|
|
|
||
|
|
await prisma.$transaction([
|
||
|
|
prisma.toolTag.deleteMany(),
|
||
|
|
prisma.toolFeature.deleteMany(),
|
||
|
|
prisma.downloadRecord.deleteMany(),
|
||
|
|
prisma.downloadTicket.deleteMany(),
|
||
|
|
prisma.openRecord.deleteMany(),
|
||
|
|
prisma.adminAuditLog.deleteMany(),
|
||
|
|
prisma.toolArtifact.deleteMany(),
|
||
|
|
prisma.tool.deleteMany(),
|
||
|
|
prisma.tag.deleteMany(),
|
||
|
|
prisma.category.deleteMany(),
|
||
|
|
prisma.hotKeyword.deleteMany(),
|
||
|
|
prisma.adminUser.deleteMany(),
|
||
|
|
]);
|
||
|
|
|
||
|
|
await prisma.category.createMany({
|
||
|
|
data: [
|
||
|
|
{ id: 'cat_ai', name: 'AI', sortOrder: 10 },
|
||
|
|
{ id: 'cat_dev', name: 'Developer', sortOrder: 20 },
|
||
|
|
{ id: 'cat_ops', name: 'Operations', sortOrder: 30 },
|
||
|
|
],
|
||
|
|
});
|
||
|
|
|
||
|
|
await prisma.tag.createMany({
|
||
|
|
data: [
|
||
|
|
{ id: 'tag_hot', name: 'Hot' },
|
||
|
|
{ id: 'tag_free', name: 'Free' },
|
||
|
|
{ id: 'tag_official', name: 'Official' },
|
||
|
|
],
|
||
|
|
});
|
||
|
|
|
||
|
|
const webToolId = 'tool_web_001';
|
||
|
|
const downloadToolId = 'tool_dl_001';
|
||
|
|
const artifactId = 'art_001';
|
||
|
|
|
||
|
|
await prisma.tool.create({
|
||
|
|
data: {
|
||
|
|
id: webToolId,
|
||
|
|
name: 'OpenAI Playground',
|
||
|
|
slug: 'openai-playground',
|
||
|
|
categoryId: 'cat_ai',
|
||
|
|
description: 'OpenAI web playground for prompt testing.',
|
||
|
|
rating: 4.8,
|
||
|
|
downloadCount: 0,
|
||
|
|
openCount: 128,
|
||
|
|
accessMode: AccessMode.web,
|
||
|
|
openUrl: 'https://platform.openai.com/playground',
|
||
|
|
openInNewTab: true,
|
||
|
|
status: ToolStatus.published,
|
||
|
|
updatedAt: nowDate,
|
||
|
|
features: {
|
||
|
|
createMany: {
|
||
|
|
data: [
|
||
|
|
{ id: 'feat_web_001', featureText: 'Prompt debugging', sortOrder: 10 },
|
||
|
|
{ id: 'feat_web_002', featureText: 'Model parameter tuning', sortOrder: 20 },
|
||
|
|
],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
tags: {
|
||
|
|
create: [{ tagId: 'tag_hot' }, { tagId: 'tag_official' }],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
await prisma.tool.create({
|
||
|
|
data: {
|
||
|
|
id: downloadToolId,
|
||
|
|
name: 'ToolsShow Desktop',
|
||
|
|
slug: 'toolsshow-desktop',
|
||
|
|
categoryId: 'cat_dev',
|
||
|
|
description: 'Desktop bundle for local workflows.',
|
||
|
|
rating: 4.6,
|
||
|
|
downloadCount: 52,
|
||
|
|
openCount: 0,
|
||
|
|
accessMode: AccessMode.download,
|
||
|
|
status: ToolStatus.published,
|
||
|
|
updatedAt: nowDate,
|
||
|
|
features: {
|
||
|
|
createMany: {
|
||
|
|
data: [
|
||
|
|
{ id: 'feat_dl_001', featureText: 'Offline usage', sortOrder: 10 },
|
||
|
|
{ id: 'feat_dl_002', featureText: 'Bundled plugins', sortOrder: 20 },
|
||
|
|
],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
tags: {
|
||
|
|
create: [{ tagId: 'tag_free' }],
|
||
|
|
},
|
||
|
|
artifacts: {
|
||
|
|
create: {
|
||
|
|
id: artifactId,
|
||
|
|
version: '1.0.0',
|
||
|
|
fileName: 'toolsshow-desktop-1.0.0.zip',
|
||
|
|
fileSizeBytes: 12_345_678,
|
||
|
|
sha256: 'sample-sha256-not-real',
|
||
|
|
mimeType: 'application/zip',
|
||
|
|
gitlabProjectId: 0,
|
||
|
|
gitlabPackageName: 'toolsshow/toolsshow-desktop',
|
||
|
|
gitlabPackageVersion: '1.0.0',
|
||
|
|
gitlabFilePath: 'storage/toolsshow-desktop-1.0.0.zip',
|
||
|
|
status: ArtifactStatus.active,
|
||
|
|
releaseNotes: 'Initial release',
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
await prisma.tool.update({
|
||
|
|
where: { id: downloadToolId },
|
||
|
|
data: { latestArtifactId: artifactId },
|
||
|
|
});
|
||
|
|
|
||
|
|
await prisma.hotKeyword.createMany({
|
||
|
|
data: [
|
||
|
|
{ id: 'kw_001', keyword: 'agent', sortOrder: 10, isActive: true },
|
||
|
|
{ id: 'kw_002', keyword: 'automation', sortOrder: 20, isActive: true },
|
||
|
|
{ id: 'kw_003', keyword: 'open-source', sortOrder: 30, isActive: true },
|
||
|
|
],
|
||
|
|
});
|
||
|
|
|
||
|
|
const passwordHash = await argon2.hash('admin123456', { type: argon2.argon2id });
|
||
|
|
await prisma.adminUser.create({
|
||
|
|
data: {
|
||
|
|
id: 'u_admin_001',
|
||
|
|
username: 'admin',
|
||
|
|
passwordHash,
|
||
|
|
displayName: 'System Admin',
|
||
|
|
status: AdminUserStatus.active,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|
||
|
|
.catch(async (error) => {
|
||
|
|
console.error(error);
|
||
|
|
process.exitCode = 1;
|
||
|
|
})
|
||
|
|
.finally(async () => {
|
||
|
|
await prisma.$disconnect();
|
||
|
|
});
|