1
0
forked from Yara724/api

Fixed company code error not found

This commit is contained in:
SepehrYahyaee
2026-05-30 15:01:53 +03:30
parent da298a3350
commit d6f1cb9eeb
5 changed files with 60 additions and 5 deletions

View File

@@ -8,9 +8,11 @@ import {
CaptchaChallenge,
CaptchaChallengeSchema,
} from "./entities/schema/captcha-challenge.schema";
import { ConfigModule } from "@nestjs/config";
@Module({
imports: [
ConfigModule,
HashModule,
MongooseModule.forFeature([
{ name: CaptchaChallenge.name, schema: CaptchaChallengeSchema },

View File

@@ -1,14 +1,17 @@
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import * as svgCaptcha from "svg-captcha";
export interface GeneratedCaptcha {
text: string;
text?: string;
image: string;
expiresAt: number;
}
@Injectable()
export class CaptchaService {
constructor(private readonly configService: ConfigService) {}
generate(): GeneratedCaptcha {
const captcha = svgCaptcha.create({
size: 5,
@@ -21,6 +24,13 @@ export class CaptchaService {
fontSize: 52,
});
if (this.configService.get<string>("NODE_ENV") === "production") {
return {
image: `data:image/svg+xml;base64,${Buffer.from(captcha.data, "utf8").toString("base64")}`,
expiresAt: this.buildExpireAt(),
};
}
return {
text: captcha.text,
image: `data:image/svg+xml;base64,${Buffer.from(captcha.data, "utf8").toString("base64")}`,