diff --git a/enjoy/src/api/client.ts b/enjoy/src/api/client.ts index 58664be2..86098387 100644 --- a/enjoy/src/api/client.ts +++ b/enjoy/src/api/client.ts @@ -260,7 +260,9 @@ export class Client { return this.api.post("/api/transcriptions", decamelizeKeys(transcription)); } - syncSegment(segment: Partial>) { + syncSegment( + segment: Partial> + ) { return this.api.post("/api/segments", decamelizeKeys(segment)); } diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 61a9d35a..caf67440 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -604,5 +604,8 @@ "referenceText": "Reference text", "inputReferenceTextOrLeaveItBlank": "Input the reference text or leave it blank", "assessing": "Assessing", - "assessedSuccessfully": "Assessed successfully" + "assessedSuccessfully": "Assessed successfully", + "optinal": "Optional", + "uploadTranscriptFile": "Upload transcript file(.txt/.srt/.vtt)", + "onlyTextFileIsSupported": "Only text file is supported" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 2357f331..28925646 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -604,5 +604,8 @@ "referenceText": "参考文本", "inputReferenceTextOrLeaveItBlank": "输入参考文本,或者留空", "assessing": "正在评估", - "assessedSuccessfully": "评估成功" + "assessedSuccessfully": "评估成功", + "optinal": "可选", + "uploadTranscriptFile": "上传字幕文件(.txt/.srt/.vtt)", + "onlyTextFileIsSupported": "仅支持文本文件" } diff --git a/enjoy/src/main/db/handlers/audios-handler.ts b/enjoy/src/main/db/handlers/audios-handler.ts index e5060c54..b771ca48 100644 --- a/enjoy/src/main/db/handlers/audios-handler.ts +++ b/enjoy/src/main/db/handlers/audios-handler.ts @@ -11,10 +11,10 @@ const logger = log.scope("db/handlers/audios-handler"); class AudiosHandler { private async findAll( - event: IpcMainEvent, + _event: IpcMainEvent, options: FindOptions> ) { - return Audio.findAll({ + const audios = await Audio.findAll({ order: [["updatedAt", "DESC"]], include: [ { @@ -25,46 +25,30 @@ class AudiosHandler { }, ], ...options, - }) - .then((audios) => { - if (!audios) { - return []; - } - return audios.map((audio) => audio.toJSON()); - }) - .catch((err) => { - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }); + }); + + if (!audios) { + return []; + } + return audios.map((audio) => audio.toJSON()); } private async findOne( - event: IpcMainEvent, + _event: IpcMainEvent, where: WhereOptions> ) { - return Audio.findOne({ + const audio = await Audio.findOne({ where: { ...where, }, - }) - .then((audio) => { - if (!audio) return; + }); + if (!audio) return; - if (!audio.isSynced) { - audio.sync().catch(() => {}); - } + if (!audio.isSynced) { + audio.sync().catch(() => {}); + } - return audio.toJSON(); - }) - .catch((err) => { - logger.error(err); - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }); + return audio.toJSON(); } private async create( @@ -79,22 +63,15 @@ class AudiosHandler { let file = uri; let source; if (uri.startsWith("http")) { - try { - if (youtubedr.validateYtURL(uri)) { - file = await youtubedr.autoDownload(uri); - } else { - file = await downloader.download(uri, { - webContents: event.sender, - }); - } - if (!file) throw new Error("Failed to download file"); - source = uri; - } catch (err) { - return event.sender.send("on-notification", { - type: "error", - message: t("models.audio.failedToDownloadFile", { file: uri }), + if (youtubedr.validateYtURL(uri)) { + file = await youtubedr.autoDownload(uri); + } else { + file = await downloader.download(uri, { + webContents: event.sender, }); } + if (!file) throw new Error("Failed to download file"); + source = uri; } try { @@ -119,73 +96,42 @@ class AudiosHandler { return audio.toJSON(); } catch (err) { - return event.sender.send("on-notification", { - type: "error", - message: t("models.audio.failedToAdd", { error: err.message }), - }); + logger.error(err); + throw err; } } private async update( - event: IpcMainEvent, + _event: IpcMainEvent, id: string, params: Attributes