forked from Yara724/api
Fixed company code error not found
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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")}`,
|
||||
|
||||
Reference in New Issue
Block a user