Commit 96409f99 authored by Jeff nan's avatar Jeff nan

feat: 添加权限验证

parent 524a1f81
...@@ -142,6 +142,23 @@ new Vue({ ...@@ -142,6 +142,23 @@ new Vue({
methods: { methods: {
async getAuthKey() {
const resp = await callServerMethod('getAuthKey');
if (resp.msg == 'success') {
return resp.data;
} else {
this.$message.error(resp.data);
return '';
}
},
// open API 鉴权 query:auth_key / user_sign
async appendApiAuthQuery(url) {
const authKey = await this.getAuthKey();
const sep = url.includes('?') ? '&' : '?';
return `${url}${sep}auth_key=${encodeURIComponent(authKey || '')}&user_sign=${encodeURIComponent('syllabus_cw_make')}`;
},
async tryAI() { async tryAI() {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const coursewareId = urlParams.get('course_id'); const coursewareId = urlParams.get('course_id');
...@@ -160,7 +177,7 @@ new Vue({ ...@@ -160,7 +177,7 @@ new Vue({
this.aiAnalysisStatus = '正在发送请求...'; this.aiAnalysisStatus = '正在发送请求...';
this.aiAnalysisProgress = 20; this.aiAnalysisProgress = 20;
const requestUrl = this.AI_SERVER_URL + '/open/api/ai/dpe/v1/pagerepair'; const requestUrl = await this.appendApiAuthQuery(this.AI_SERVER_URL + '/open/api/ai/dpe/v1/pagerepair');
const requestData = { courseware_id: coursewareId || 1783332, page_number: this.currentPageIndex }; const requestData = { courseware_id: coursewareId || 1783332, page_number: this.currentPageIndex };
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
......
//对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱 //对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱
var t_name = 'AI_BOOK_TOOL'; var t_name = 'AI_BOOK_TOOL';
const callServerMethod = (method, data) => {
return new Promise((resolve, reject) => {
window.courseware.onEvent(method, (result, next) => {
resolve(result);
next();
}, t_name);
window.courseware.sendEvent(method, data, t_name);
});
}
$(function () { $(function () {
window.courseware.getData(function (data) { window.courseware.getData(function (data) {
if (!data) { if (!data) {
...@@ -277,6 +287,23 @@ function initializeApp(data) { ...@@ -277,6 +287,23 @@ function initializeApp(data) {
}, },
methods: { methods: {
async getAuthKey() {
const resp = await callServerMethod('getAuthKey');
if (resp.msg == 'success') {
return resp.data;
} else {
this.$message.error(resp.data);
return '';
}
},
// open API 鉴权 query:auth_key / user_sign
async appendApiAuthQuery(url) {
const authKey = await this.getAuthKey();
const sep = url.includes('?') ? '&' : '?';
return `${url}${sep}auth_key=${encodeURIComponent(authKey || '')}&user_sign=${encodeURIComponent('syllabus_cw_make')}`;
},
// 初始化音频 // 初始化音频
initAudio() { initAudio() {
if (!this.audioUrl) { if (!this.audioUrl) {
...@@ -1185,7 +1212,7 @@ function initializeApp(data) { ...@@ -1185,7 +1212,7 @@ function initializeApp(data) {
// 滚动到底部 // 滚动到底部
this.scrollToBottom(); this.scrollToBottom();
const requestUrl = this.AI_SERVER_URL + '/open/api/ai/dpe/v1/super/translatetoc'; const requestUrl = await this.appendApiAuthQuery(this.AI_SERVER_URL + '/open/api/ai/dpe/v1/super/translatetoc');
const requestData = { const requestData = {
word: word, word: word,
sentence: sentence, sentence: sentence,
......
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