Commit e4661791 authored by Jeff nan's avatar Jeff nan

fix

parent 5891dc93
......@@ -227,13 +227,23 @@ function initVueApp(savedData) {
.map((k) => ({ key: k, value: data[k] }));
},
async getAuthKey() {
const resp = await callServerMethod('getAuthKey');
if (resp.msg == 'success') {
return resp.data;
} else {
this.$message.error(resp.data);
return '';
// courseware 同名事件不能并发监听:并行调用会互相覆盖,只保留最后一次
if (this._getAuthKeyInflight) {
return this._getAuthKeyInflight;
}
this._getAuthKeyInflight = (async () => {
try {
const resp = await callServerMethod('getAuthKey');
if (resp.msg == 'success') {
return resp.data;
}
this.$message.error(resp.data);
return '';
} finally {
this._getAuthKeyInflight = null;
}
})();
return this._getAuthKeyInflight;
},
// 结果 key -> 中文名称(去人声)
getVocalKeyZh(key) {
......@@ -284,11 +294,11 @@ function initVueApp(savedData) {
return isStaging ? 'https://stagingopensource.iteachabc.com' : 'https://opensource.iteachabc.com';
},
// open API 鉴权 query:auth_key / user_sign
async appendApiAuthQuery(url) {
const authKey = await this.getAuthKey();
// open API 鉴权 query:auth_key / user_sign(可传入已获取的 authKey,避免重复请求)
async appendApiAuthQuery(url, authKey) {
const key = authKey != null ? authKey : await this.getAuthKey();
const sep = url.includes('?') ? '&' : '?';
return `${url}${sep}auth_key=${encodeURIComponent(authKey || '')}&user_sign=${encodeURIComponent('syllabus_cw_make')}`;
return `${url}${sep}auth_key=${encodeURIComponent(key || '')}&user_sign=${encodeURIComponent('syllabus_cw_make')}`;
},
// 开始字幕任务轮询
......@@ -574,9 +584,10 @@ function initVueApp(savedData) {
this.videoUrl = res;
this.$message.success('视频上传成功!');
this.saveData();
// 自动并行触发两个任务
this.generateSubtitles();
this.removeVocals();
// 自动并行触发两个任务(共用一次 auth_key)
const authKey = await this.getAuthKey();
this.generateSubtitles(authKey);
this.removeVocals(authKey);
}
});
// 开始上传,显示进度条
......@@ -633,7 +644,7 @@ function initVueApp(savedData) {
},
// 生成字幕
async generateSubtitles() {
async generateSubtitles(authKey) {
const videoUrl = (this.videoUrl || '');
if (!videoUrl) {
this.$message.warning('请先上传或选择视频');
......@@ -666,7 +677,7 @@ function initVueApp(savedData) {
const base = this.getApiBase();
const loading = this.$loading({ lock: true, text: '正在提交字幕任务...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' });
try {
const url = await this.appendApiAuthQuery(`${base}/open/api/ai/dpe/v1/video/subtitles`);
const url = await this.appendApiAuthQuery(`${base}/open/api/ai/dpe/v1/video/subtitles`, authKey);
const resp = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
......@@ -689,7 +700,7 @@ function initVueApp(savedData) {
},
// 去人声
async removeVocals() {
async removeVocals(authKey) {
const videoUrl = (this.videoUrl || '');
if (!videoUrl) {
this.$message.warning('请先上传或选择视频');
......@@ -720,7 +731,7 @@ function initVueApp(savedData) {
const base = this.getApiBase();
const loading = this.$loading({ lock: true, text: '正在提交去人声任务...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' });
try {
const url = await this.appendApiAuthQuery(`${base}/open/api/ai/dpe/v1/video/vocalbgmute`);
const url = await this.appendApiAuthQuery(`${base}/open/api/ai/dpe/v1/video/vocalbgmute`, authKey);
const resp = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment