* 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>
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { ipcMain, IpcMainEvent } from "electron";
|
|
import { Speech } from "@main/db/models";
|
|
import fs from "fs-extra";
|
|
import path from "path";
|
|
import settings from "@main/settings";
|
|
import { hashFile } from "@main/utils";
|
|
import { Attributes, WhereOptions } from "sequelize";
|
|
|
|
class SpeechesHandler {
|
|
private async findOne(
|
|
_event: IpcMainEvent,
|
|
where: WhereOptions<Attributes<Speech>>
|
|
) {
|
|
const speech = await Speech.findOne({ where });
|
|
if (!speech) {
|
|
return null;
|
|
}
|
|
|
|
return speech.toJSON();
|
|
}
|
|
|
|
private async create(
|
|
event: IpcMainEvent,
|
|
params: {
|
|
sourceId: string;
|
|
sourceType: string;
|
|
text: string;
|
|
configuration: {
|
|
engine: string;
|
|
model: string;
|
|
voice: string;
|
|
};
|
|
},
|
|
blob: {
|
|
type: string;
|
|
arrayBuffer: ArrayBuffer;
|
|
}
|
|
) {
|
|
const format = blob.type.split("/")[1];
|
|
const filename = `${Date.now()}.${format}`;
|
|
const file = path.join(settings.userDataPath(), "speeches", filename);
|
|
await fs.outputFile(file, Buffer.from(blob.arrayBuffer));
|
|
const md5 = await hashFile(file, { algo: "md5" });
|
|
fs.renameSync(file, path.join(path.dirname(file), `${md5}.${format}`));
|
|
|
|
return Speech.create({ ...params, extname: `.${format}`, md5 })
|
|
.then((speech) => {
|
|
return speech.toJSON();
|
|
})
|
|
.catch((err) => {
|
|
event.sender.send("on-notification", {
|
|
type: "error",
|
|
message: err.message,
|
|
});
|
|
});
|
|
}
|
|
|
|
register() {
|
|
ipcMain.handle("speeches-find-one", this.findOne);
|
|
ipcMain.handle("speeches-create", this.create);
|
|
}
|
|
|
|
unregister() {
|
|
ipcMain.removeHandler("speeches-find-one");
|
|
ipcMain.removeHandler("speeches-create");
|
|
}
|
|
}
|
|
|
|
export const speechesHandler = new SpeechesHandler();
|