ensure recording is synced before share (#492)
This commit is contained in:
@@ -67,6 +67,20 @@ class RecordingsHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private async sync(_event: IpcMainEvent, id: string) {
|
||||
const recording = await Recording.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!recording) {
|
||||
throw new Error(t("models.recording.notFound"));
|
||||
}
|
||||
|
||||
return await recording.sync();
|
||||
}
|
||||
|
||||
private async syncAll(event: IpcMainEvent) {
|
||||
const recordings = await Recording.findAll({
|
||||
where: { syncedAt: null },
|
||||
@@ -150,7 +164,7 @@ class RecordingsHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private async upload(event: IpcMainEvent, id: string) {
|
||||
private async upload(_event: IpcMainEvent, id: string) {
|
||||
const recording = await Recording.findOne({
|
||||
where: {
|
||||
id,
|
||||
@@ -158,23 +172,10 @@ class RecordingsHandler {
|
||||
});
|
||||
|
||||
if (!recording) {
|
||||
event.sender.send("on-notification", {
|
||||
type: "error",
|
||||
message: t("models.recording.notFound"),
|
||||
});
|
||||
throw new Error(t("models.recording.notFound"));
|
||||
}
|
||||
|
||||
recording
|
||||
.upload()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
event.sender.send("on-notification", {
|
||||
type: "error",
|
||||
message: err.message,
|
||||
});
|
||||
});
|
||||
return await recording.upload();
|
||||
}
|
||||
|
||||
private async assess(event: IpcMainEvent, id: string) {
|
||||
@@ -361,6 +362,7 @@ class RecordingsHandler {
|
||||
register() {
|
||||
ipcMain.handle("recordings-find-all", this.findAll);
|
||||
ipcMain.handle("recordings-find-one", this.findOne);
|
||||
ipcMain.handle("recordings-sync", this.sync);
|
||||
ipcMain.handle("recordings-sync-all", this.syncAll);
|
||||
ipcMain.handle("recordings-create", this.create);
|
||||
ipcMain.handle("recordings-destroy", this.destroy);
|
||||
|
||||
@@ -257,6 +257,9 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
|
||||
findOne: (params: any) => {
|
||||
return ipcRenderer.invoke("recordings-find-one", params);
|
||||
},
|
||||
sync: (id: string) => {
|
||||
return ipcRenderer.invoke("recordings-sync", id);
|
||||
},
|
||||
syncAll: () => {
|
||||
return ipcRenderer.invoke("recordings-sync-all");
|
||||
},
|
||||
|
||||
@@ -174,6 +174,14 @@ export const MediaCurrentRecording = () => {
|
||||
const handleShare = async () => {
|
||||
if (!currentRecording) return;
|
||||
|
||||
if (!currentRecording.isSynced) {
|
||||
try {
|
||||
await EnjoyApp.recordings.sync(currentRecording.id);
|
||||
} catch (error) {
|
||||
toast.error(t("shareFailed"), { description: error.message });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!currentRecording.uploadedAt) {
|
||||
try {
|
||||
await EnjoyApp.recordings.upload(currentRecording.id);
|
||||
@@ -320,7 +328,7 @@ export const MediaCurrentRecording = () => {
|
||||
}
|
||||
|
||||
const subscriptions = [
|
||||
regions.on("region-created", () => {}),
|
||||
regions.on("region-created", () => { }),
|
||||
|
||||
regions.on("region-clicked", (region, e) => {
|
||||
e.stopPropagation();
|
||||
@@ -543,17 +551,16 @@ export const MediaCurrentRecording = () => {
|
||||
>
|
||||
<GaugeCircleIcon
|
||||
className={`w-4 h-4 mr-4
|
||||
${
|
||||
currentRecording.pronunciationAssessment
|
||||
? currentRecording.pronunciationAssessment
|
||||
.pronunciationScore >= 80
|
||||
? "text-green-500"
|
||||
: currentRecording.pronunciationAssessment
|
||||
.pronunciationScore >= 60
|
||||
? "text-yellow-600"
|
||||
: "text-red-500"
|
||||
: ""
|
||||
}
|
||||
${currentRecording.pronunciationAssessment
|
||||
? currentRecording.pronunciationAssessment
|
||||
.pronunciationScore >= 80
|
||||
? "text-green-500"
|
||||
: currentRecording.pronunciationAssessment
|
||||
.pronunciationScore >= 60
|
||||
? "text-yellow-600"
|
||||
: "text-red-500"
|
||||
: ""
|
||||
}
|
||||
`}
|
||||
/>
|
||||
<span>{t("pronunciationAssessment")}</span>
|
||||
|
||||
1
enjoy/src/types/enjoy-app.d.ts
vendored
1
enjoy/src/types/enjoy-app.d.ts
vendored
@@ -140,6 +140,7 @@ type EnjoyAppType = {
|
||||
recordings: {
|
||||
findAll: (where: any) => Promise<RecordingType[]>;
|
||||
findOne: (where: any) => Promise<RecordingType>;
|
||||
sync: (id: string) => Promise<void>;
|
||||
syncAll: () => Promise<void>;
|
||||
create: (params: any) => Promise<RecordingType>;
|
||||
update: (id: string, params: any) => Promise<RecordingType | undefined>;
|
||||
|
||||
1
enjoy/src/types/recording.d.ts
vendored
1
enjoy/src/types/recording.d.ts
vendored
@@ -10,6 +10,7 @@ type RecordingType = {
|
||||
duration?: number;
|
||||
src?: string;
|
||||
md5: string;
|
||||
isSynced?: boolean;
|
||||
uploadedAt?: Date;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
Reference in New Issue
Block a user