Commit e4661791 authored by Jeff nan's avatar Jeff nan

fix

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