55} from '@libs/contracts/constants' ;
66import { KeygenEntity } from '@modules/keygen/entities/keygen.entity' ;
77import { PrismaClient } from '@prisma/client' ;
8+ import consola from 'consola' ;
89
910export const XTLSDefaultConfig = {
1011 log : {
@@ -560,7 +561,7 @@ const prisma = new PrismaClient({
560561} ) ;
561562
562563async function seedSubscriptionTemplate ( ) {
563- console . log ( 'Seeding subscription templates...' ) ;
564+ consola . start ( 'Seeding subscription templates...' ) ;
564565 for ( const templateType of SUBSCRIPTION_TEMPLATE_TYPE_VALUES ) {
565566 const existingConfig = await prisma . subscriptionTemplate . findUnique ( {
566567 where : {
@@ -571,7 +572,7 @@ async function seedSubscriptionTemplate() {
571572 switch ( templateType ) {
572573 case SUBSCRIPTION_TEMPLATE_TYPE . STASH :
573574 if ( existingConfig ) {
574- console . log ( `Default ${ templateType } config already exists!` ) ;
575+ consola . info ( `Default ${ templateType } config already exists!` ) ;
575576 continue ;
576577 }
577578
@@ -582,7 +583,7 @@ async function seedSubscriptionTemplate() {
582583 break ;
583584 case SUBSCRIPTION_TEMPLATE_TYPE . MIHOMO :
584585 if ( existingConfig ) {
585- console . log ( `Default ${ templateType } config already exists!` ) ;
586+ consola . info ( `Default ${ templateType } config already exists!` ) ;
586587 continue ;
587588 }
588589
@@ -592,7 +593,7 @@ async function seedSubscriptionTemplate() {
592593 break ;
593594 case SUBSCRIPTION_TEMPLATE_TYPE . SINGBOX :
594595 if ( existingConfig ) {
595- console . log ( `Default ${ templateType } config already exists!` ) ;
596+ consola . info ( `Default ${ templateType } config already exists!` ) ;
596597 continue ;
597598 }
598599
@@ -602,7 +603,7 @@ async function seedSubscriptionTemplate() {
602603 break ;
603604 case SUBSCRIPTION_TEMPLATE_TYPE . SINGBOX_LEGACY :
604605 if ( existingConfig ) {
605- console . log ( `Default ${ templateType } config already exists!` ) ;
606+ consola . info ( `Default ${ templateType } config already exists!` ) ;
606607 continue ;
607608 }
608609
@@ -612,7 +613,7 @@ async function seedSubscriptionTemplate() {
612613 break ;
613614 case SUBSCRIPTION_TEMPLATE_TYPE . XRAY_JSON :
614615 if ( existingConfig ) {
615- console . log ( `Default ${ templateType } config already exists!` ) ;
616+ consola . info ( `Default ${ templateType } config already exists!` ) ;
616617 continue ;
617618 }
618619
@@ -623,7 +624,7 @@ async function seedSubscriptionTemplate() {
623624 break ;
624625 case SUBSCRIPTION_TEMPLATE_TYPE . CLASH :
625626 if ( existingConfig ) {
626- console . log ( `Default ${ templateType } config already exists!` ) ;
627+ consola . info ( `Default ${ templateType } config already exists!` ) ;
627628 continue ;
628629 }
629630
@@ -633,7 +634,8 @@ async function seedSubscriptionTemplate() {
633634
634635 break ;
635636 default :
636- throw new Error ( `Unknown template type: ${ templateType } ` ) ;
637+ consola . error ( `Unknown template type: ${ templateType } ` ) ;
638+ process . exit ( 1 ) ;
637639 }
638640 }
639641}
@@ -668,8 +670,10 @@ async function seedSubscriptionSettings() {
668670async function seedConfigVariables ( ) {
669671 const existingConfig = await prisma . xrayConfig . findFirst ( ) ;
670672
673+ consola . start ( '🔐 Seeding XTLS config...' ) ;
674+
671675 if ( existingConfig ) {
672- console . log ( ' Default XTLS config already seeded!') ;
676+ consola . success ( '🔐 Default XTLS config already seeded!') ;
673677 return ;
674678 }
675679
@@ -680,60 +684,80 @@ async function seedConfigVariables() {
680684 } ) ;
681685
682686 if ( ! config ) {
683- throw new Error ( 'Failed to create default config!' ) ;
687+ consola . error ( '🔐 Failed to create default config!' ) ;
688+ process . exit ( 1 ) ;
684689 }
685690
686- console . log ( ' Default XTLS config seeded!') ;
691+ consola . success ( '🔐 Default XTLS config seeded!') ;
687692}
688693
689694async function seedKeygen ( ) {
690- const existingConfig = await prisma . keygen . findFirst ( ) ;
691-
692- if ( ! existingConfig ) {
693- const { publicKey, privateKey } = await generateJwtKeypair ( ) ;
694- const { caCertPem, caKeyPem, clientCertPem, clientKeyPem } = await generateMasterCerts ( ) ;
695-
696- const keygenEntity = new KeygenEntity ( {
697- caCert : caCertPem ,
698- caKey : caKeyPem ,
699- clientCert : clientCertPem ,
700- clientKey : clientKeyPem ,
701- pubKey : publicKey ,
702- privKey : privateKey ,
703- } ) ;
704-
705- await prisma . keygen . create ( {
706- data : keygenEntity ,
707- } ) ;
708-
709- console . log ( '🔐 Keygen seeded!' ) ;
710-
711- return ;
712- }
713-
714- if (
715- existingConfig . pubKey &&
716- existingConfig . privKey &&
717- ( ! existingConfig . caCert ||
718- ! existingConfig . caKey ||
719- ! existingConfig . clientCert ||
720- ! existingConfig . clientKey )
721- ) {
722- const { caCertPem, caKeyPem, clientCertPem, clientKeyPem } = await generateMasterCerts ( ) ;
723-
724- await prisma . keygen . update ( {
725- where : { uuid : existingConfig . uuid } ,
726- data : {
727- caCert : caCertPem ,
728- caKey : caKeyPem ,
729- clientCert : clientCertPem ,
730- clientKey : clientKeyPem ,
731- } ,
732- } ) ;
733-
734- console . log ( '🔐 Keygen updated!' ) ;
735- return ;
736- }
695+ consola . start ( '🔐 Seeding keygen...' ) ;
696+
697+ // TODO: Remove after testing
698+ process . exit ( 1 ) ;
699+
700+ // const existingConfig = await prisma.keygen.findFirst();
701+
702+ // if (!existingConfig) {
703+ // try {
704+ // const { publicKey, privateKey } = await generateJwtKeypair();
705+ // const { caCertPem, caKeyPem, clientCertPem, clientKeyPem } =
706+ // await generateMasterCerts();
707+
708+ // const keygenEntity = new KeygenEntity({
709+ // caCert: caCertPem,
710+ // caKey: caKeyPem,
711+ // clientCert: clientCertPem,
712+ // clientKey: clientKeyPem,
713+ // pubKey: publicKey,
714+ // privKey: privateKey,
715+ // });
716+
717+ // await prisma.keygen.create({
718+ // data: keygenEntity,
719+ // });
720+
721+ // consola.success('🔐 Keygen seeded!');
722+
723+ // return;
724+ // } catch (error) {
725+ // consola.error('🔐 Failed to seed keygen:', error);
726+ // process.exit(1);
727+ // }
728+ // }
729+
730+ // if (
731+ // existingConfig.pubKey &&
732+ // existingConfig.privKey &&
733+ // (!existingConfig.caCert ||
734+ // !existingConfig.caKey ||
735+ // !existingConfig.clientCert ||
736+ // !existingConfig.clientKey)
737+ // ) {
738+ // try {
739+ // const { caCertPem, caKeyPem, clientCertPem, clientKeyPem } =
740+ // await generateMasterCerts();
741+
742+ // await prisma.keygen.update({
743+ // where: { uuid: existingConfig.uuid },
744+ // data: {
745+ // caCert: caCertPem,
746+ // caKey: caKeyPem,
747+ // clientCert: clientCertPem,
748+ // clientKey: clientKeyPem,
749+ // },
750+ // });
751+
752+ // consola.success('🔐 Keygen updated!');
753+ // return;
754+ // } catch (error) {
755+ // consola.error('🔐 Failed to update keygen:', error);
756+ // process.exit(1);
757+ // }
758+ // }
759+
760+ // consola.success('🔐 Keygen already seeded!');
737761}
738762
739763async function checkDatabaseConnection ( ) {
0 commit comments