Commit 28fae881 authored by 周成波's avatar 周成波

参数加密

parent 9c33cb2b
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"@element-plus/icons-vue": "^2.1.0", "@element-plus/icons-vue": "^2.1.0",
"axios": "^1.6.1", "axios": "^1.6.1",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"crypto-js": "^4.2.0",
"element-plus": "^2.4.2", "element-plus": "^2.4.2",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"pinia": "^2.1.7", "pinia": "^2.1.7",
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
"devDependencies": { "devDependencies": {
"@rushstack/eslint-patch": "^1.3.3", "@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2", "@tsconfig/node18": "^18.2.2",
"@types/crypto-js": "^4.2.2",
"@types/file-saver": "^2.0.7", "@types/file-saver": "^2.0.7",
"@types/node": "^18.18.9", "@types/node": "^18.18.9",
"@vitejs/plugin-vue": "^4.4.0", "@vitejs/plugin-vue": "^4.4.0",
...@@ -376,6 +378,12 @@ ...@@ -376,6 +378,12 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/crypto-js": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz",
"integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==",
"dev": true
},
"node_modules/@types/estree": { "node_modules/@types/estree": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
...@@ -1282,6 +1290,11 @@ ...@@ -1282,6 +1290,11 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/crypto-js": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
},
"node_modules/cssesc": { "node_modules/cssesc": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"@element-plus/icons-vue": "^2.1.0", "@element-plus/icons-vue": "^2.1.0",
"axios": "^1.6.1", "axios": "^1.6.1",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"crypto-js": "^4.2.0",
"element-plus": "^2.4.2", "element-plus": "^2.4.2",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"pinia": "^2.1.7", "pinia": "^2.1.7",
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
"devDependencies": { "devDependencies": {
"@rushstack/eslint-patch": "^1.3.3", "@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2", "@tsconfig/node18": "^18.2.2",
"@types/crypto-js": "^4.2.2",
"@types/file-saver": "^2.0.7", "@types/file-saver": "^2.0.7",
"@types/node": "^18.18.9", "@types/node": "^18.18.9",
"@vitejs/plugin-vue": "^4.4.0", "@vitejs/plugin-vue": "^4.4.0",
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
* 相关接口 * 相关接口
*/ */
import request from '@/api/request' import request from '@/api/request'
import { enc } from 'crypto-js';
export default { export default {
submitLLM(prompt: string, llm: string = "gpt", history: Wm.PromptHistory[] = []): Promise<string> { submitLLM(prompt: string, llm: string = "gpt", history: Wm.PromptHistory[] = [], task_id: string = "-", encrypt: string = "false"): Promise<string> {
if (!prompt) { if (!prompt) {
return Promise.reject("输入不能为空"); return Promise.reject("输入不能为空");
} }
const post_data = { source_text: prompt, history: history, llm: llm } const post_data = { source_text: prompt, history: history, llm: llm, task_id: task_id, encrypt: encrypt }
return request.post('/text2video/text2llm', post_data) return request.post('/text2video/text2llm', post_data)
.then((res: any) => { .then((res: any) => {
// console.log(res); // console.log(res);
...@@ -36,6 +37,7 @@ export default { ...@@ -36,6 +37,7 @@ export default {
seed: string = "-1", seed: string = "-1",
steps: string = "25", steps: string = "25",
cfg_scale: string = "9", cfg_scale: string = "9",
encrypt: string = "false"
): Promise<{"domain_image_path": string, "local_image_path": string}> { ): Promise<{"domain_image_path": string, "local_image_path": string}> {
if (!prompt) { if (!prompt) {
return Promise.reject("SD提示词不能为空"); return Promise.reject("SD提示词不能为空");
...@@ -51,6 +53,7 @@ export default { ...@@ -51,6 +53,7 @@ export default {
width: width, width: width,
height: height, height: height,
cfg_scale: cfg_scale, cfg_scale: cfg_scale,
encrypt: encrypt,
} }
return request.post('/text2video/text2img', post_data) return request.post('/text2video/text2img', post_data)
.then((res: any) => { .then((res: any) => {
...@@ -110,11 +113,11 @@ export default { ...@@ -110,11 +113,11 @@ export default {
}); });
}, },
submitTranslateToEn(input_string: string): Promise<string> { submitTranslateToEn(input_string: string, task_id: string = "-", encrypt: string = "false"): Promise<string> {
if (!input_string) { if (!input_string) {
return Promise.reject("输入不能为空"); return Promise.reject("输入不能为空");
} }
const post_data = { input_string: input_string } const post_data = { input_string: input_string, task_id: task_id, encrypt: encrypt }
return request.post('/text2video/translate_to_en', post_data) return request.post('/text2video/translate_to_en', post_data)
.then((res: any) => { .then((res: any) => {
// console.log(res); // console.log(res);
...@@ -148,4 +151,22 @@ export default { ...@@ -148,4 +151,22 @@ export default {
return Promise.reject(`add_text_to_img接口通讯失败:${JSON.stringify(err.message)}`); return Promise.reject(`add_text_to_img接口通讯失败:${JSON.stringify(err.message)}`);
}); });
}, },
submitTest(prompt: string): Promise<string> {
const post_data = { source_text: prompt }
return request.post('/text2video/test', post_data)
.then((res: any) => {
// console.log(res);
if (res && res.code === 0) {
return res.data.result;
} else {
const errorMessage = res ? res.message : "未知错误";
return Promise.reject(errorMessage);
}
})
.catch((err: any) => {
console.log(`err = ${JSON.stringify(err)}`);
return Promise.reject(`与Test Api通讯失败:${JSON.stringify(err.message)}`);
});
},
} }
import _cryptoJs from 'crypto-js';
export default class utils { export default class utils {
// 格式化为json字符串 // 格式化为json字符串
static formatJson(jsonString: string) { static formatJson(jsonString: string) {
...@@ -69,4 +71,15 @@ export default class utils { ...@@ -69,4 +71,15 @@ export default class utils {
return /^[!-\/:-@\[-`{-~\p{P}\p{S}\s]*$/u.test(str); return /^[!-\/:-@\[-`{-~\p{P}\p{S}\s]*$/u.test(str);
} }
// 加密
static aesEncrypt(word: string) {
var key = _cryptoJs.enc.Utf8.parse('e6ef616dc57343248f6b3e98a07e1dde');
var srcs = _cryptoJs.enc.Utf8.parse(word);
var encrypted = _cryptoJs.AES.encrypt(srcs, key, {
mode: _cryptoJs.mode.ECB,
padding: _cryptoJs.pad.Pkcs7
});
return encrypted.toString();
}
} }
This diff is collapsed.
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