From 8490c87089ebc7c2dc29ff099322c60778343ef4 Mon Sep 17 00:00:00 2001 From: Prajna Date: Sat, 11 Nov 2023 23:46:55 +0800 Subject: [PATCH] feat: add OUTPUT_SRT_THEN_TRANSLATE to setting --- .env.template | 5 ++++- apps/server/src/auth/auth.service.ts | 6 +++--- apps/server/src/osrt/osrt.service.ts | 6 ++++-- apps/web/app/settings/page.tsx | 4 ++-- apps/web/app/settings/profile-form.tsx | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.env.template b/.env.template index 011d823d..42a5e08f 100644 --- a/.env.template +++ b/.env.template @@ -6,7 +6,6 @@ WEB_PORT=3000 # Front-end port SERVER_PORT=3001 # Backend port STATIC_PATH=/static # Static file path -OUTPUT_SRT_THEN_TRANSLATE=true # Whether to output the SRT file first and then translate it LANGUAGE=zh-CN # Output SRT file and then translate the language TRANSLATE_DELAY=1500 # Delay between calling translation interface TRANSLATE_GROUP=4 # Translate sentences for grouping translation, how many sentences can be translated at most at a time @@ -28,3 +27,7 @@ NEXT_PUBLIC_WEB_URL=http://localhost:3000 # Same as above. WEB address GITHUB_CLIENT_ID= # GitHub client ID GITHUB_CLIENT_SECRET= # GitHub client secret AUTH_SECRET = YOUR_KEY_HERE # JWT secret you can run `openssl rand -base64 32` to generate a secret + +# System Setting +# You can edit in Setting +OUTPUT_SRT_THEN_TRANSLATE=true # Whether to output the SRT file first and then translate it \ No newline at end of file diff --git a/apps/server/src/auth/auth.service.ts b/apps/server/src/auth/auth.service.ts index c0e0a711..dc80bedf 100644 --- a/apps/server/src/auth/auth.service.ts +++ b/apps/server/src/auth/auth.service.ts @@ -106,9 +106,9 @@ export class AuthService { }; } - async updateProfile(user, { username, password, outputSrtThenTranslate }) { - if (typeof outputSrtThenTranslate === "boolean") { - this.configService.set("outputSrtThenTranslate", outputSrtThenTranslate ? '1' : '0'); + async updateProfile(user, { username, password, OUTPUT_SRT_THEN_TRANSLATE }) { + if (typeof OUTPUT_SRT_THEN_TRANSLATE === "boolean") { + this.configService.set("OUTPUT_SRT_THEN_TRANSLATE", OUTPUT_SRT_THEN_TRANSLATE ? '1' : '0'); } return this.usersService.updateProfile(user.id, { diff --git a/apps/server/src/osrt/osrt.service.ts b/apps/server/src/osrt/osrt.service.ts index 92666e00..58459aa3 100644 --- a/apps/server/src/osrt/osrt.service.ts +++ b/apps/server/src/osrt/osrt.service.ts @@ -15,6 +15,7 @@ import { TranslateService } from "@/translate/translate.service"; import { IEvent } from "./event.subject"; import { Subject } from "rxjs"; import { PaginationDto } from "./dto/pagination.dto"; +import { CustomConfigService } from "@/config/custom-config.service"; const visibleFiles = (file: string) => !file.startsWith("."); const autoTranslateLanguages = "ja"; @@ -29,7 +30,8 @@ export class OsrtService { private readonly filesService: FilesService, private readonly translateService: TranslateService, @Inject("STATIC_DIR") private staticDir: string, - @Inject("EVENT_SUBJECT") private readonly eventSubject: Subject + @Inject("EVENT_SUBJECT") private readonly eventSubject: Subject, + private customConfigService: CustomConfigService ) {} private logger: Logger = new Logger("OsrtService"); @@ -284,7 +286,7 @@ export class OsrtService { async srtTranslate(videoDirPath, srtFile, targetSrtPath) { try { - if (process.env.OUTPUT_SRT_THEN_TRANSLATE === "true") { + if (this.customConfigService.get("OUTPUT_SRT_THEN_TRANSLATE")) { const relativePath = path.relative(this.staticDir, targetSrtPath); const translateSubtitle = await this.translateService.translateFile( srtFile, diff --git a/apps/web/app/settings/page.tsx b/apps/web/app/settings/page.tsx index 83064e90..be0d8819 100644 --- a/apps/web/app/settings/page.tsx +++ b/apps/web/app/settings/page.tsx @@ -18,8 +18,8 @@ export default async function SettingsProfilePage() { diff --git a/apps/web/app/settings/profile-form.tsx b/apps/web/app/settings/profile-form.tsx index b9b81fb2..d3205ed6 100644 --- a/apps/web/app/settings/profile-form.tsx +++ b/apps/web/app/settings/profile-form.tsx @@ -45,7 +45,7 @@ const profileFormSchema = z.object({ message: "Password must be at least 8 characters.", }) .optional(), - outputSrtThenTranslate: z.boolean().optional(), + OUTPUT_SRT_THEN_TRANSLATE: z.boolean().optional(), }); type ProfileFormValues = z.infer; @@ -128,7 +128,7 @@ export function ProfileForm({
(