Skip to content

Commit

Permalink
feat: add OUTPUT_SRT_THEN_TRANSLATE to setting
Browse files Browse the repository at this point in the history
  • Loading branch information
hqwuzhaoyi committed Nov 11, 2023
1 parent 6b40cad commit 8490c87
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions apps/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/osrt/osrt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<IEvent>
@Inject("EVENT_SUBJECT") private readonly eventSubject: Subject<IEvent>,
private customConfigService: CustomConfigService
) {}

private logger: Logger = new Logger("OsrtService");
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default async function SettingsProfilePage() {
<ProfileForm
defaultValues={{
username: profile.username,
outputSrtThenTranslate:
config.outputSrtThenTranslate === "1" ? true : false,
OUTPUT_SRT_THEN_TRANSLATE:
config.OUTPUT_SRT_THEN_TRANSLATE === "1" ? true : false,
}}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/settings/profile-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof profileFormSchema>;
Expand Down Expand Up @@ -128,7 +128,7 @@ export function ProfileForm({
<div className="space-y-4">
<FormField
control={form.control}
name="outputSrtThenTranslate"
name="OUTPUT_SRT_THEN_TRANSLATE"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
Expand Down

0 comments on commit 8490c87

Please sign in to comment.