diff --git a/enjoy/src/main/db/models/recording.ts b/enjoy/src/main/db/models/recording.ts index e9c58a55..f1e0f076 100644 --- a/enjoy/src/main/db/models/recording.ts +++ b/enjoy/src/main/db/models/recording.ts @@ -134,9 +134,7 @@ export class Recording extends Model { } async sync() { - if (!this.uploadedAt) { - await this.upload(); - } + this.upload().catch(() => {}); const webApi = new Client({ baseUrl: process.env.WEB_API_URL || WEB_API_URL, @@ -158,6 +156,7 @@ export class Recording extends Model { return assessment; } + await this.sync(); const webApi = new Client({ baseUrl: process.env.WEB_API_URL || WEB_API_URL, accessToken: settings.getSync("user.accessToken") as string, @@ -172,6 +171,14 @@ export class Recording extends Model { reference: this.referenceText, }); + const resultJson = camelcaseKeys( + JSON.parse(JSON.stringify(result.detailResult)), + { + deep: true, + } + ); + resultJson.duration = this.duration; + const _pronunciationAssessment = await PronunciationAssessment.create( { targetId: this.id, @@ -184,9 +191,7 @@ export class Recording extends Model { grammarScore: result.contentAssessmentResult?.grammarScore, vocabularyScore: result.contentAssessmentResult?.vocabularyScore, topicScore: result.contentAssessmentResult?.topicScore, - result: camelcaseKeys(JSON.parse(JSON.stringify(result.detailResult)), { - deep: true, - }), + result: resultJson, }, { include: Recording,