fix(build): resolve linter and tsconfig project service errors, guarantee dist/main existence in start-dev
Deploy Canina / deploy (push) Has been cancelled
Deploy Canina / deploy (push) Has been cancelled
This commit is contained in:
1 parent
a291fa0c4a
commit
6362750dea
50 files changed
+12128
-10959
No files matched your search
@@ -2,6 +2,7 @@ import { Injectable, Logger, BadRequestException } from '@nestjs/common';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import * as tls from 'tls';
|
||||
|
||||
export interface SslCertInfo {
|
||||
exists: boolean;
|
||||
@@ -21,14 +22,17 @@ export interface SslCertInfo {
|
||||
@Injectable()
|
||||
export class SslService {
|
||||
private readonly logger = new Logger(SslService.name);
|
||||
private readonly certsDir = process.env.SSL_CERTS_DIR || path.join(process.cwd(), 'ssl_certs');
|
||||
private readonly certsDir =
|
||||
process.env.SSL_CERTS_DIR || path.join(process.cwd(), 'ssl_certs');
|
||||
|
||||
constructor() {
|
||||
if (!fs.existsSync(this.certsDir)) {
|
||||
try {
|
||||
fs.mkdirSync(this.certsDir, { recursive: true });
|
||||
} catch (err) {
|
||||
this.logger.warn(`Could not create ssl_certs dir at ${this.certsDir}: ${err}`);
|
||||
this.logger.warn(
|
||||
`Could not create ssl_certs dir at ${this.certsDir}: ${err}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +73,10 @@ export class SslService {
|
||||
const validToDate = new Date(cert.validTo);
|
||||
const now = new Date();
|
||||
const diffMs = validToDate.getTime() - now.getTime();
|
||||
const daysRemaining = Math.max(0, Math.floor(diffMs / (1000 * 60 * 60 * 24)));
|
||||
const daysRemaining = Math.max(
|
||||
0,
|
||||
Math.floor(diffMs / (1000 * 60 * 60 * 24)),
|
||||
);
|
||||
const isExpired = diffMs <= 0;
|
||||
|
||||
// Extract SAN domains
|
||||
@@ -108,7 +115,9 @@ export class SslService {
|
||||
const cleanKey = keyContent.trim();
|
||||
|
||||
if (!cleanCert || !cleanKey) {
|
||||
throw new BadRequestException('محتوای گواهی (Certificate) و کلید خصوصی (Private Key) الزامی است.');
|
||||
throw new BadRequestException(
|
||||
'محتوای گواهی (Certificate) و کلید خصوصی (Private Key) الزامی است.',
|
||||
);
|
||||
}
|
||||
|
||||
// 1. Validate Certificate format
|
||||
@@ -117,7 +126,9 @@ export class SslService {
|
||||
cert = new crypto.X509Certificate(cleanCert);
|
||||
} catch (err: unknown) {
|
||||
const errObj = err as Error;
|
||||
throw new BadRequestException(`فرمت گواهی نامعتبر است: ${errObj.message}`);
|
||||
throw new BadRequestException(
|
||||
`فرمت گواهی نامعتبر است: ${errObj.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
// 2. Validate Private Key format
|
||||
@@ -125,7 +136,9 @@ export class SslService {
|
||||
crypto.createPrivateKey(cleanKey);
|
||||
} catch (err: unknown) {
|
||||
const errObj = err as Error;
|
||||
throw new BadRequestException(`فرمت کلید خصوصی نامعتبر است: ${errObj.message}`);
|
||||
throw new BadRequestException(
|
||||
`فرمت کلید خصوصی نامعتبر است: ${errObj.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Ensure certs directory exists
|
||||
@@ -150,7 +163,9 @@ export class SslService {
|
||||
fs.writeFileSync(certPath, cleanCert, 'utf8');
|
||||
fs.writeFileSync(keyPath, cleanKey, 'utf8');
|
||||
|
||||
this.logger.log(`SSL Certificates updated successfully. Subject: ${cert.subject}`);
|
||||
this.logger.log(
|
||||
`SSL Certificates updated successfully. Subject: ${cert.subject}`,
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -161,8 +176,10 @@ export class SslService {
|
||||
|
||||
public testOnlineDomainSsl(domain: string): Promise<Record<string, unknown>> {
|
||||
return new Promise((resolve) => {
|
||||
const cleanDomain = domain.replace(/^https?:\/\//, '').replace(/\/.*$/, '').trim();
|
||||
const tls = require('tls');
|
||||
const cleanDomain = domain
|
||||
.replace(/^https?:\/\//, '')
|
||||
.replace(/\/.*$/, '')
|
||||
.trim();
|
||||
const socket = tls.connect(
|
||||
{
|
||||
host: cleanDomain,
|
||||
@@ -192,7 +209,7 @@ export class SslService {
|
||||
issuer: peerCert.issuer?.O || peerCert.issuer?.CN,
|
||||
subject: peerCert.subject?.CN,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
socket.on('error', (err: Error) => {
|
||||
|
||||
Reference in new issue
Block a user