* add user settings * fix user setting * migrate dict settings * migrate hotkeys * fix hotkey setting * update library settings * migrate gpt Engine * use user setting key enum * migrate openai * migrate more settings * migrate whisper config * migrate whisper * refactor * clean up * migrate profile * migrate recorder config * refactor * refactor * fix e2e * add api status * fix e2e * fix app init * fetch apiUrl before fetch user * update stt engine enums * update enums * update enums * refactor login flow * Fix warning * Login from remembered users * fix e2e * refactor * add unauthorized alert * feat: 🎸 dict import update (#1040) * rectified. according to Issues. * issue #1025 * feat: add Vietnamese language to support (#1043) * feat: add vietnamese language to support * fix: update Vietnamese language name to native form --------- Co-authored-by: Ryan <trongdv@coccoc.com> * upgrade deps * update locales --------- Co-authored-by: divisey <18656007202@163.com> Co-authored-by: xiaolai <lixiaolai@gmail.com> Co-authored-by: ryan <69750456+ryangwn@users.noreply.github.com> Co-authored-by: Ryan <trongdv@coccoc.com>
71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
import { ipcMain, IpcMainEvent } from "electron";
|
|
import { Transcription, Audio, Video } from "@main/db/models";
|
|
import { Attributes } from "sequelize";
|
|
import log from "@main/logger";
|
|
|
|
const logger = log.scope("db/handlers/transcriptions-handler");
|
|
class TranscriptionsHandler {
|
|
private async findOrCreate(_event: IpcMainEvent, where: Transcription) {
|
|
try {
|
|
const { targetType, targetId } = where;
|
|
let target: Video | Audio = null;
|
|
if (targetType === "Video") {
|
|
target = await Video.findByPk(targetId);
|
|
} else if (targetType === "Audio") {
|
|
target = await Audio.findByPk(targetId);
|
|
} else {
|
|
throw new Error("models.transcription.invalidTargetType");
|
|
}
|
|
|
|
const [transcription, _created] = await Transcription.findOrCreate({
|
|
where: {
|
|
targetId,
|
|
targetType,
|
|
},
|
|
defaults: {
|
|
targetId,
|
|
targetType,
|
|
targetMd5: target.md5,
|
|
},
|
|
});
|
|
|
|
return transcription.toJSON();
|
|
} catch (err) {
|
|
logger.error(err);
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
private async update(
|
|
event: IpcMainEvent,
|
|
id: string,
|
|
params: Attributes<Transcription>
|
|
) {
|
|
const { result, engine, model, state, language } = params;
|
|
|
|
const transcription = await Transcription.findByPk(id);
|
|
if (!transcription) {
|
|
throw new Error("models.transcription.notFound");
|
|
}
|
|
return await transcription.update({
|
|
result,
|
|
engine,
|
|
model,
|
|
state,
|
|
language,
|
|
});
|
|
}
|
|
|
|
register() {
|
|
ipcMain.handle("transcriptions-find-or-create", this.findOrCreate);
|
|
ipcMain.handle("transcriptions-update", this.update);
|
|
}
|
|
|
|
unregister() {
|
|
ipcMain.removeHandler("transcriptions-find-or-create");
|
|
ipcMain.removeHandler("transcriptions-update");
|
|
}
|
|
}
|
|
|
|
export const transcriptionsHandler = new TranscriptionsHandler();
|