Commit 4fe32bc3 by cyx

Commit 20230823 Wed

parent fb3cd9dc
......@@ -40,11 +40,11 @@
<version>2.0.31</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.google.code.gson</groupId>-->
<!-- <artifactId>gson</artifactId>-->
<!-- <version>2.8.9</version>-->
<!-- </dependency>-->
<!-- https://mvnrepository.com/artifact/org.java-websocket/Java-WebSocket -->
<dependency>
<groupId>org.java-websocket</groupId>
......@@ -65,18 +65,40 @@
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.13</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
......
package qiwu.xfllmdemo.controller;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import qiwu.xfllmdemo.mapper.DBMapper;
import qiwu.xfllmdemo.pojo.*;
import qiwu.xfllmdemo.service.LLMService;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
@Controller
// @RestMapping
@RequestMapping("/pregen")
public class PreGenerateController {
// @PostMapping("/upload")
@Autowired
private DBMapper dbMapper;
@Autowired
private LLMService llmService = new LLMService();
String uploadDir = "/home/cyx/uploadedFile"; // TODO 存储文件的目录
String fileName = "uploadedUserWords.txt"; // file.getOriginalFilename(); // TODO 存储到服务器上的文件名称
File sourceFile; // 上传的文件存储路径,构造方法中构建
PreGenerateController() {
sourceFile = new File(uploadDir + File.separator + fileName);
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void uploadFile(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
@CrossOrigin // 允许跨域请求
@ResponseBody // 令返回值作为响应体内容
public String uploadFile(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
if (file.isEmpty()) {
// 处理文件为空的情况
// return "redirect:/fileEmpty";
// 处理文件为空的情况 // return "redirect:/fileEmpty";
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); // 400
System.out.println("uploadFile emptyFile");
}
try {
// 定义文件存储路径,可以根据需求更改
System.out.println("uploadFile try");
String uploadDir = "~/uploadedFile"; // 存储文件的目录
String fileName = "uploadedUserWords.txt"; // file.getOriginalFilename(); // 获取上传文件的原始文件名
// 创建存储目录(如果不存在)
File uploadPath = new File(uploadDir);
if (!uploadPath.exists()) {
uploadPath.mkdirs();
}
// 构建文件存储路径
String filePath = uploadDir + File.separator + fileName;
System.out.println("uploadFile() try");
// 检查文件存储路径是否存在
if (!sourceFile.exists()) {
if (!sourceFile.mkdirs()) {
throw new IOException("destFile.mkdirs() failed");
}
}
// 将文件保存到服务器本地
file.transferTo(new File(filePath));
// 文件上传成功,可以进行其他业务逻辑处理
// return "redirect:/uploadSuccess";
file.transferTo(sourceFile);
// 文件上传成功,可以进行其他业务逻辑处理 // return "redirect:/uploadSuccess";
response.setStatus(HttpServletResponse.SC_OK); // 200
System.out.println("uploadFile OK");
System.out.println("uploadFile() OK");
} catch (IOException e) {
// 处理文件上传异常
// return "redirect:/uploadFailure";
// 处理文件上传异常 // return "redirect:/uploadFailure";
e.printStackTrace();
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); // 500
}
return "uploadFile OK";
}
@PostMapping(value = "/generate")
@CrossOrigin
public void generate(@RequestBody String requirement, HttpServletResponse response) throws Exception {
try {
// Test
System.out.println("generate()");
// TODO 1. 读取文件,获得待生成List
List<String> toGenList = new LinkedList<>();
Scanner sc = new Scanner(sourceFile);
while (sc.hasNextLine()) {
StringBuilder u = new StringBuilder(sc.nextLine());
// TODO 1.1 处理csv的逗号
while (u.charAt(u.length() - 1) == ',') {
u.deleteCharAt(u.charAt(u.length() - 1));
}
// Test
System.out.println(u);
toGenList.add(u.toString());
}
// TODO 2. List逐条请求模型,获得回复
// TODO 2.1 取得DB中意图ID值
int nowIntentionID = dbMapper.getMaxIntentionID();
// Test
System.out.println("nowIntentionID: " + nowIntentionID);
if (nowIntentionID <= 0) {
nowIntentionID = 1;
}
// TODO 2.2 请求模型
List<IntentionDAO> iList = new LinkedList<>();
List<OptDAO> oList = new LinkedList<>();
UUID thisUUID = UUID.randomUUID(); // 每一次生成,与模型使用一个对话
// Test
System.out.println("thisUUID: " + thisUUID);
// TODO 2.2.1 告知模型生成要求
// Test
System.out.println("requirement: " + requirement);
llmService.query(new LLMServiceRequestVO(thisUUID, requirement));
// TODO 2.2.2 用户话语逐条请求
for (String thisSentence : toGenList) {
LLMServiceResponseVO llmResponse = llmService.query(new LLMServiceRequestVO(thisUUID, thisSentence));
// Test
System.out.println(new DialogueVO(thisSentence, nowIntentionID, llmResponse.answer));
iList.add(new IntentionDAO(thisSentence, nowIntentionID));
oList.add(new OptDAO(nowIntentionID, llmResponse.answer));
nowIntentionID++;
}
// TODO 3. 将回复插入DB
int iRlt = dbMapper.insertIntoIntention(iList);
int oRlt = dbMapper.insertIntoOpt(oList);
// Test
System.out.println("iRlt: " + iRlt + " oRlt: " + oRlt);
if (iRlt >= 0 && oRlt >= 0) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.setHeader("message", "DBInsertError");
}
} catch (Exception e) {
e.printStackTrace();
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
package qiwu.xfllmdemo.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import qiwu.xfllmdemo.pojo.DialogueVO;
import qiwu.xfllmdemo.pojo.IntentionDAO;
import qiwu.xfllmdemo.pojo.OptDAO;
import java.util.List;
@Component
@Mapper
public interface DBMapper {
int getMaxIntentionID();
int insertIntoIntention(List<IntentionDAO> intentionDAOList);
int insertIntoOpt(List<OptDAO> optDAOList);
List<DialogueVO> getReply(String user_words);
}
package qiwu.xfllmdemo.pojo;
public class DialogueVO {
String user_words;
int intention_id;
String reply;
public DialogueVO() {}
public DialogueVO(String user_words, int intention_id) {
this.user_words = user_words;
this.intention_id = intention_id;
}
public DialogueVO(String user_words, int intention_id, String reply) {
this.user_words = user_words;
this.intention_id = intention_id;
this.reply = reply;
}
}
package qiwu.xfllmdemo.pojo;
public class IntentionDAO {
int id;
String user_words;
int intention_id;
public IntentionDAO(String user_words, int intention_id) {
this.user_words = user_words;
this.intention_id = intention_id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUser_words() {
return user_words;
}
public void setUser_words(String user_words) {
this.user_words = user_words;
}
public int getIntention_id() {
return intention_id;
}
public void setIntention_id(int intention_id) {
this.intention_id = intention_id;
}
@Override
public String toString() {
return "intentionTableDAO{" +
"id=" + id +
", user_words='" + user_words + '\'' +
", intention_id=" + intention_id +
'}';
}
}
package qiwu.xfllmdemo.pojo;
public class OptDAO {
int id;
int intention_id;
String reply;
boolean audit_status = false;
public OptDAO(int intention_id, String reply) {
this.intention_id = intention_id;
this.reply = reply;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIntention_id() {
return intention_id;
}
public void setIntention_id(int intention_id) {
this.intention_id = intention_id;
}
public String getReply() {
return reply;
}
public void setReply(String reply) {
this.reply = reply;
}
public boolean isAudit_status() {
return audit_status;
}
public void setAudit_status(boolean audit_status) {
this.audit_status = audit_status;
}
@Override
public String toString() {
return "optTableDAO{" +
"id=" + id +
", intention_id=" + intention_id +
", reply='" + reply + '\'' +
", audit_status=" + audit_status +
'}';
}
}
......@@ -98,7 +98,7 @@ public class LLMService {
thisHistory.add(new Message.Text("user", inVO.question));
toReq.payload.message.text = thisHistory;
String toReqJSON = JSON.toJSONString(toReq);
// TODO Test
// Test
System.out.println("toReqJSON: \n" + toReqJSON + "\n------");
System.out.println("authURL: \n" + authURL + "\n------");
// TODO 3. 发起请求,获得回复,将回复添加到对话历史,返回
......@@ -192,7 +192,7 @@ class LLMSocket extends WebSocketListener {
@Override
public synchronized void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
// System.out.println(userId + "用来区分是哪个用户的结果" + text);
// TODO Test
// Test
System.out.println("onMessage() " + threadNum + ": ");
threadNum++;
System.out.println("LLMResponseJSON: " + text);
......@@ -205,12 +205,11 @@ class LLMSocket extends WebSocketListener {
webSocket.close(1000, "");
return;
}
// TODO Test
// Test
System.out.println("responseVO: " + responseVO);
// TODO 2. 提取其中的回答串
List<Choices.Text> textList = responseVO.payload.choices.text;
// TODO Test
// Test
System.out.println("textList.size(): " + textList.size());
// TODO 3. 拼接形成完整回答串 每个Response的test里面只有一个元素
for (Choices.Text temp : textList) {
......
......@@ -3,3 +3,44 @@ server:
tomcat:
uri-encoding: UTF-8
max-http-header-size: 8192
spring:
datasource:
url: jdbc:mysql://localhost:3306/chitchat?serverTimezone=Asia/Shanghai&characterEncoding=utf-8
username: root
password: 7890-=
driver-class-name: com.mysql.cj.jdbc.Driver
data:
redis:
database: 0
host: localhost
port: 6379
# password:
#配置jedis客户端,这里也可以jedis替换为lettuce客户端,下级配置都一样
jedis:
pool:
# 连接池中的最大空闲连接 默认8
max-idle: 8
# 连接池中的最小空闲连接 默认0
min-idle: 0
# 连接池最大连接数 默认8 ,负数表示没有限制
max-active: 8
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
max-wait: -1
timeout: 3000
cache:
type: redis # 指定使用的缓存类型
# redis: 当自定义CacheManager时,这里的配置不起作用
# use-key-prefix: true
# key-prefix: "demo:"
# time-to-live: 60000 #缓存超时时间 单位:ms
# cache-null-values: false #是否缓存空值
cache-names: user
# 公共配置,与profiles选择无关
mybatis:
type-aliases-package: qiwu.xfllmdemo.pojo
mapper-locations: classpath:mapper/*.xml
# 开启MyBatis的二级缓存
configuration:
cache-enabled: true
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="qiwu.xfllmdemo.mapper.DBMapper">
<!-- 返回值:结果的行数 -->
<select id="getMaxIntentionID" resultType="int">
SELECT max(intention_id) --, project_name as projectName
FROM intention
</select>
<!-- 返回值:成功插入的行数 -->
<insert id="insertIntoIntention" parameterType="List">
INSERT INTO intention (user_words, intention_id)
VALUES
<foreach collection="list" index="index" item="item" separator=",">
(#{user_words, jdbcType=VARCHAR}, #{intention_id, jdbcType=INTEGER})
</foreach>
</insert>
<insert id="insertIntoOpt" parameterType="List">
INSERT INTO opt (intention_id, reply, audit_status)
VALUES
<foreach collection="list" index="index" item="item" separator=",">
(#{intention_id, jdbcType=INTEGER}, #{reply, jdbcType=VARCHAR}, #{audit_status, jdbcType=TINYINT})
</foreach>
</insert>
<!-- &lt;!&ndash; &ndash;&gt;-->
<!-- <update id="updateProjectInfoByPrimaryKey" parameterType="ProjectEntity">-->
<!-- UPDATE project_info-->
<!-- SET project_name = #{projectName, jdbcType=VARCHAR},-->
<!-- project_content = #{projectContent, jdbcType=VARCHAR},-->
<!-- last_updated_by = #{lastUpdatedBy, jdbcType=VARCHAR},-->
<!-- last_update_date = #{lastUpdateDate, jdbcType=TIMESTAMP}-->
<!-- WHERE id = #{id, jdbcType=VARCHAR}-->
<!-- </update>-->
<!-- &lt;!&ndash; &ndash;&gt;-->
<!-- <delete id="deleteProjectById" parameterType="ProjectEntity">-->
<!-- DELETE FROM project_info-->
<!-- WHERE id = #{id, jdbcType=VARCHAR}-->
<!-- </delete>-->
</mapper>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<!-- 1.可以为实体类设置别名 -->
<typeAlias type="java.lang.String" alias="String"/>
<typeAlias type="java.util.List" alias="List"/>
<typeAlias type="java.util.Date" alias="Date"/>
<typeAlias type="qiwu.xfllmdemo.pojo.IntentionDAO" alias="IntentionDAO"/>
<typeAlias type="qiwu.xfllmdemo.pojo.OptDAO" alias="OptDAO"/>
<!-- 2.可以指定一个包名,MyBatis会在包名下搜索每一个 Java Bean -->
<!-- 在没有注解的情况下,会使用 Bean 的首字母小写的非限定类名来作为它的别名 -->
<!-- <package name="qiwu.xfllmdemo.pojo"/>-->
<!-- The content of element type "typeAliases" must match "(typeAlias*,package*)". -->
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost:3306/chitchat?serverTimezone=Asia/Shanghai&amp;characterEncoding=utf-8"/>
<property name="username" value="root"/>
<property name="password" value="7890-="/>
</dataSource>
</environment>
</environments>
<mappers>
<!-- 每一个Mapper.xml都应在mybatis-config.xml中注册 -->
<mapper resource="mapper/DBMapper.xml"/>
</mappers>
</configuration>
......@@ -5,16 +5,25 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>预生成回答</title>
<script src="./utils/axios-1.4.0.min.js"></script> <!-- import axios -->
<script src="./utils/jquery-3.7.0.min.js"></script> <!-- import jquery -->
</head>
<body>
<!-- <input type="file" id="videoUploader" accept="video/mp4, video/ogg">-->
<p id="uploadInfoP">在此处上传预设用户话语txt</p>
<p id="uploadInfo">在此处上传预设用户话语txt(接受txt和csv格式)</p>
<input type="file" id="fileUploadInput" accept="text/csv, text/plain">
<button id="uploadButton">上传</button>
<progress id="uploadProgressBar" value="0" max="100"></progress>
<progress id="uploadProgressBar" value="0" max="100"></progress> <br>
<p id="divider1">------------------------------</p> <br>
<textarea id="requirementArea" cols = 30 placeholder="在此输入生成要求,如人物设定等"></textarea>
<button id="genButton">生成</button> <br>
<p id="genInfo"></p> <br>
<p id="divider2">------------------------------</p> <br>
<button id="downloadButton">下载导出文件</button> <br>
<p id="downloadInfo"></p>
<script src="./pre-generate.js" type="module"></script>
</body>
<script src="./utils/axios@1.4.0.min.js"></script> <!-- import axios -->
<script src="./pre-generate.js" type="module"></script>
</html>
\ No newline at end of file
// config.js
// 导出一些常量,包括上传信息、允许上传的文件类型、块大小和上传接口的URL
// 这些常量将在前端和后端代码中使用
const BASE_URL = 'http://localhost:8080';
const BASE_URL = 'http://127.0.0.1:8080';
/**
* dic - key : value
......@@ -12,20 +11,21 @@ export const UPLOAD_INFO = {
'INVALID_TYPE': '不支持该类型文件上传',
'UPLOAD_FAILED': '上传失败',
'UPLOAD_SUCCESS': '上传成功'
} ;
};
export const ALLOWED_TYPE = {
// 'video/mp4': 'mp4',
// 'video/ogg': 'ogg'
'text/csv': 'csv',
'text/plain': 'txt'
} ;
};
export const CHUNK_SIZE = 64 * 1024;
export const API = {
UPLOAD_VIDEO: BASE_URL + '/uploadFile'
} ;
export const API_URLS = {
UPLOAD_FILE: BASE_URL + '/pregen/upload',
START_GEN: BASE_URL + '/pregen/generate'
};
// index.js
// 在闭包内部,定义一个立即执行的匿名函数,接受document作为参数
......@@ -33,8 +33,13 @@ export const API = {
// 获取页面上的一些元素
const uploadProgressBar = doc.querySelector('#uploadProgressBar'); // 上传进度条
const fileUploadInput = doc.querySelector('#fileUploadInput'); // 文件上传输入框
const uploadInfoP = doc.querySelector('#uploadInfoP'); // 用于显示上传信息
const uploadInfo = doc.querySelector('#uploadInfo'); // p,显示上传状态信息
const uploadButton = doc.querySelector('#uploadButton'); // 上传按钮
const requirementArea = doc.querySelector('#requirementArea')
const genButton = doc.querySelector('#genButton'); // 开始生成按钮
const genInfo = doc.querySelector('#genInfo'); // p,显示生成状态信息
const downloadButton = doc.querySelector('#downloadButton');
const downloadInfo = doc.querySelector('#downloadInfo');
let uploadedSize = 0; // 已上传的文件大小,用于控制分块上传
......@@ -42,17 +47,45 @@ export const API = {
* 初始化函数
*/
const init = () => {
bindEvent(); // 绑定事件
// 绑定事件函数 - 为元素添加事件监听器
uploadButton.addEventListener('click', uploadFile, false); // uploadButton -> uploadFile()
genButton.addEventListener('click', startGen, false); // genButton -> startGen()
downloadButton.addEventListener('click', onDownload, false);
}
/**
* 绑定事件函数 - 为元素添加事件监听器
* 创建FormData函数,将文件块和相关信息添加到FormData对象中
*/
function bindEvent() {
uploadButton.addEventListener('click', uploadFile, false); // 点击上传按钮触发上传函数
function createFormData({
name,
type,
size,
fileName,
uploadedSize,
file
}) {
const fd = new FormData();
fd.append('name', name);
fd.append('type', type);
fd.append('size', size);
fd.append('fileName', fileName);
fd.append('uploadedSize', uploadedSize);
fd.append('file', file);
return fd;
}
/**
* 创建视频元素函数,用于在页面上展示上传成功的视频
*/
// function createFile(src) {
// const uploadedVideo = document.createElement('file');
// uploadedVideo.controls = true;
// uploadedVideo.width = '500';
// uploadedVideo.src = src;
// document.body.appendChild(uploadedVideo);
// }
/**
* 异步上传函数
*/
async function uploadFile() {
......@@ -62,14 +95,14 @@ export const API = {
// 检查是否选择了文件,如果没有则显示提示信息
if (!file) {
console.log("No file chosen");
uploadInfoP.innerText = UPLOAD_INFO['NO_FILE'];
uploadInfo.innerText = UPLOAD_INFO['NO_FILE'];
return;
}
// 检查文件类型是否被允许,如果不允许则显示提示信息
console.log(file.type.toString());
if (!ALLOWED_TYPE[file.type]) {
console.log("Invalid file chosen");
uploadInfoP.innerText = UPLOAD_INFO['INVALID_TYPE'];
uploadInfo.innerText = UPLOAD_INFO['INVALID_TYPE'];
return;
}
// 获取文件的一些基本信息
......@@ -77,7 +110,7 @@ export const API = {
const fileName = new Date().getTime() + '_' + name;
let uploadedResult = null;
uploadProgressBar.max = size;
uploadInfoP.innerText = '';
uploadInfo.innerText = '';
while (uploadedSize < size) {
// 若文件大,使用slice方法将文件切割成小块,实现分块上传
......@@ -94,9 +127,9 @@ export const API = {
console.log("axios POST");
// 使用axios库发送POST请求,将文件块上传到后端
try {
uploadedResult = await axios.post(API.UPLOAD_VIDEO, formData);
uploadedResult = await axios.post(API_URLS.UPLOAD_FILE, formData);
} catch (e) {
uploadInfoP.innerText = `${UPLOAD_INFO['UPLOAD_FAILED']}(${e.message})`; // on Exception
uploadInfo.innerText = `${UPLOAD_INFO['UPLOAD_FAILED']}(${e.message})`; // on Exception
return;
}
// 更新已上传的文件大小和进度条
......@@ -105,43 +138,46 @@ export const API = {
}
// 上传成功后,显示上传成功的提示信息,并将文件输入框置空
uploadInfoP.innerText = UPLOAD_INFO['UPLOAD_SUCCESS'];
uploadInfo.innerText = UPLOAD_INFO['UPLOAD_SUCCESS'];
fileUploadInput.value = null;
// 根据后端返回的视频URL,创建一个视频元素并展示在页面上
// createFile(uploadedResult.data.video_url);
}
/**
* 创建FormData函数,将文件块和相关信息添加到FormData对象中
*/
function createFormData({
name,
type,
size,
fileName,
uploadedSize,
file
}) {
const fd = new FormData();
fd.append('name', name);
fd.append('type', type);
fd.append('size', size);
fd.append('fileName', fileName);
fd.append('uploadedSize', uploadedSize);
fd.append('file', file);
return fd;
async function startGen() {
console.log("startGen()");
let requirement = requirementArea.text();
$.ajax({
url: API_URLS["START_GEN"],
type: "POST",
data: requirement,
dataType: "text",
contentType: "text/plain",
beforeSend() {
genInfo.text("等待中...");
},
success(res) { // responding with String
genInfo.text("生成完成!");
console.log("startGen() success");
}
});
}
/**
* 创建视频元素函数,用于在页面上展示上传成功的视频
*/
// function createFile(src) {
// const uploadedVideo = document.createElement('file');
// uploadedVideo.controls = true;
// uploadedVideo.width = '500';
// uploadedVideo.src = src;
// document.body.appendChild(uploadedVideo);
// }
async function onDownload() {
// 替换为你的Spring Boot Controller 的下载接口地址
let downloadUrl = "/download?path=/path/to/your/file";
// 创建一个隐藏的<a>元素来触发下载
let link = document.createElement('a');
link.href = downloadUrl;
link.target = "_blank"; // 在新窗口中打开
link.download = "BotGen.txt"; // 下载后的文件名,可以自定义
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// ------------------------------------
......
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