mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-21 01:10:39 +08:00
新增”添加网盘链接“功能
This commit is contained in:
@@ -138,7 +138,7 @@ router.get('/dashboard/:group/:page/:subpage?', function (req, res) {
|
||||
},
|
||||
"object-detail": {
|
||||
title: "文件对象详情",
|
||||
baseTemplate: "blank",
|
||||
baseTemplate: "form",
|
||||
pageTemplate: "FileManage_ObjectManage_Detail",
|
||||
},
|
||||
"upload": {
|
||||
|
@@ -431,14 +431,14 @@
|
||||
}
|
||||
function getLinkDOM(fileObjectInfo) {
|
||||
// 获取文件下载链接DOM
|
||||
var iconSrc = "/assets/image/svg/direct_link.svg", title = fileObjectInfo.storageMedium, content = "", downloadLink = "";
|
||||
var iconSrc = "/assets/image/svg/direct_link.svg", title = fileObjectInfo.storageMediumForDisplay, content = "", downloadLink = "";
|
||||
if(fileObjectInfo.fileShareCode != "" && fileObjectInfo.fileShareCode != null) {
|
||||
content = `<span>提取码: <span class="click2copy" style="user-select: all; cursor: pointer;">${fileObjectInfo.fileShareCode}</span> </span>`; // 最后一个 是为了保证选中时不会选中后面的回车
|
||||
downloadLink = `<a class="baiduNetdiskLink" share-code="${fileObjectInfo.fileShareCode}" share-link="${fileObjectInfo.filePath}" style="cursor: pointer;" title="复制提取码并前往">前往</a>`;
|
||||
} else {
|
||||
downloadLink = `<a href="${fileObjectInfo.filePath}" target="_blank">前往</a>`;
|
||||
}
|
||||
switch (fileObjectInfo.storageMedium) {
|
||||
switch (fileObjectInfo.storageMediumForDisplay) {
|
||||
case "腾讯云对象存储":
|
||||
title = "直链下载";
|
||||
if (!localStorageUtils.getLoginStatus()) {
|
||||
@@ -455,7 +455,7 @@
|
||||
iconSrc = "/assets/image/svg/aliyun_drive.svg";
|
||||
break;
|
||||
default:
|
||||
title = fileObjectInfo.storageMedium;
|
||||
title = fileObjectInfo.storageMediumForDisplay;
|
||||
downloadLink = `<a href="${fileObjectInfo.filePath}" target="_blank">前往</a>`;
|
||||
break;
|
||||
}
|
||||
|
@@ -77,8 +77,9 @@
|
||||
${new Date(element.fileCreateAt).toLocaleString()}
|
||||
</span>`,
|
||||
管理: `<span style="margin: 0 auto;">
|
||||
<a href="<%= pageUrl %>detail?id=${element.id}">详情</a>
|
||||
<a href="javascript:deleteFile(${element.id});">删除(TODO)</a>
|
||||
<a href="<%= pageUrl %>detail?id=${element.id}">详情</a>
|
||||
<a href="<%= pageUrl %>object-detail?fileId=${element.id}">添加网盘链接</a><br>
|
||||
<a href="javascript:deleteFile(${element.id});">删除(TODO)</a>
|
||||
</span>`,
|
||||
})
|
||||
});
|
||||
|
@@ -83,7 +83,8 @@
|
||||
var item = data[i];
|
||||
items.push(`<tr>
|
||||
<td>${item.id}</td>
|
||||
<td>${item.storageMedium}</td>
|
||||
<td>${item.storageMediumForDisplay}</td>
|
||||
<td style="font-size: 12px;">${item.filePath}</td>
|
||||
<td>${item.filePwd}</td>
|
||||
<td>${item.fileShareCode}</td>
|
||||
<td>${(item.uploadStatus ? item.uploadStatus : "<span style='color: grey; font-weight: bold;'>未知</span>")
|
||||
@@ -93,10 +94,12 @@
|
||||
</tr>`);
|
||||
}
|
||||
document.getElementById("file-object-container").innerHTML =
|
||||
`<table border="1" style="margin: 0 auto;">
|
||||
`<a href="<%= pageUrl %>../object-detail?fileId=${fileId}">添加网盘链接</a><br>
|
||||
<table border="1" style="margin: 0 auto;">
|
||||
<tr>
|
||||
<th>文件对象Id</th>
|
||||
<th>存储介质</th>
|
||||
<th>链接</th>
|
||||
<th>文件密码</th>
|
||||
<th>提取码</th>
|
||||
<th>状态</th>
|
||||
|
@@ -1,3 +1,10 @@
|
||||
<style>
|
||||
/* 限制 来源 列的宽度 */
|
||||
tr>*:nth-child(3),
|
||||
td>*:nth-child(3) {
|
||||
max-width: 100px;
|
||||
}
|
||||
</style>
|
||||
<p>
|
||||
<a href="<%= pageUrl %>../">返回上一级</a>
|
||||
|
||||
@@ -26,12 +33,15 @@
|
||||
ID: ${element.fileId}
|
||||
<a href="<%= pageUrl %>../detail?id=${element.fileId}">查看</a>
|
||||
</span>`,
|
||||
链接: `<span class="overflow-omit" style="font-size: 12px; line-height: 1.2em; display: block;">
|
||||
${element.filePath}
|
||||
</span>`,
|
||||
密码: `<span class="overflow-omit" style="font-size: 12px; line-height: 1.2em; display: block;"><nobr>
|
||||
文件密码: ${element.filePwd}<br>
|
||||
提取码: ${element.fileShareCode}
|
||||
</nobr></span>`,
|
||||
存储介质: `<span class="overflow-omit" style="font-size: 12px; line-height: 1.2em; display: block;"><nobr>
|
||||
${element.storageMedium}
|
||||
${element.storageMediumForDisplay}
|
||||
</nobr></span>`,
|
||||
状态: `${(element.uploadStatus ? element.uploadStatus : "<span style='color: grey; font-weight: bold;'>未知</span>")
|
||||
.replace("SUCCESS", "<span style='color: green; font-weight: bold;'>成功</span>")
|
||||
|
@@ -0,0 +1,197 @@
|
||||
<script>
|
||||
// 如果传入了 id 那么就是修改文件对象,否则就是添加文件对象
|
||||
var params = getParams()
|
||||
var fileObjectId = params.id;
|
||||
var fileId = params.fileId;
|
||||
if (!fileId) {
|
||||
alert("未传入 fileId !");
|
||||
history.go(-1);
|
||||
}
|
||||
|
||||
var isModify = fileObjectId ? true : false;
|
||||
if (!isModify) {
|
||||
// 新增文件对象
|
||||
fileObjectId = 0;
|
||||
} else {
|
||||
// 修改文件对象
|
||||
}
|
||||
|
||||
// 点击提交按钮
|
||||
function btnSubmitClick() {
|
||||
formSubmit({
|
||||
type: 'POST',
|
||||
url: '/file/object/detail',
|
||||
data: { id: fileObjectId },
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
alert(isModify ? "修改成功!" : "添加成功!");
|
||||
history.go(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 如果是修改文件对象,则需要获取文件对象详情
|
||||
async function getFileObjectDetail(fileObjectId) {
|
||||
var responseData = await getRequest("/file/object/get", { id: fileObjectId });
|
||||
var axiosData = responseData.data;
|
||||
var status = axiosData.status;
|
||||
var data = axiosData.data;
|
||||
if (status === "success") {
|
||||
console.log(data)
|
||||
return data;
|
||||
} else {
|
||||
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
||||
// 回到上一页
|
||||
history.go(-1);
|
||||
}
|
||||
}
|
||||
|
||||
async function getControlsProfile(getValidateUtils) {
|
||||
|
||||
// 修改文件对象: 获取文件对象详情
|
||||
var fileObjectDetail = {};
|
||||
if (isModify) {
|
||||
fileObjectDetail = await getFileObjectDetail(fileObjectId);
|
||||
} else {
|
||||
console.log("新增文件对象无需获取文件对象详情");
|
||||
}
|
||||
|
||||
var filePathDisabledAttr = {};
|
||||
var modifyDisabledAttr = {};
|
||||
if (fileObjectDetail.storageMediumForDisplay == "腾讯云对象存储") {
|
||||
filePathDisabledAttr.disabled = "true";
|
||||
if (isModify) {
|
||||
modifyDisabledAttr.disabled = "true";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
// 必须设置 id, name
|
||||
// 只有设置了 id 才会使用 validate 校验取值
|
||||
{
|
||||
"tag": "select",
|
||||
"attr": {
|
||||
"id": "storageMedium",
|
||||
"name": "storageMedium",
|
||||
"value": fileObjectDetail.storageMedium || "",
|
||||
...modifyDisabledAttr
|
||||
},
|
||||
"label": {
|
||||
"value": "存储位置",
|
||||
},
|
||||
"required": true,
|
||||
"children": [
|
||||
{
|
||||
"tag": "option",
|
||||
"attr": { "value": "QCLOUD_COS" },
|
||||
"innerHTML": "腾讯云对象存储",
|
||||
},
|
||||
{
|
||||
"tag": "option",
|
||||
"attr": { "value": "BAIDU_NETDISK" },
|
||||
"innerHTML": "百度网盘",
|
||||
},
|
||||
{
|
||||
"tag": "option",
|
||||
"attr": { "value": "ALIYUN_DRIVE" },
|
||||
"innerHTML": "阿里云盘",
|
||||
},
|
||||
],
|
||||
"innerHTML": "",
|
||||
"validate": (val) => {
|
||||
if (val == "QCLOUD_COS") {
|
||||
return {
|
||||
result: false,
|
||||
msg: "腾讯云对象存储请使用上传文件功能上传"
|
||||
};
|
||||
} else {
|
||||
return { result: true };
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
"id": "filePath",
|
||||
"name": "filePath",
|
||||
"placeholder": "文件对象链接或路径",
|
||||
"value": fileObjectDetail.filePath || "",
|
||||
...filePathDisabledAttr // 如果是对象存储,那么就不允许编辑
|
||||
},
|
||||
"label": {
|
||||
"value": "文件链接",
|
||||
},
|
||||
"required": true,
|
||||
"innerHTML": "",
|
||||
"validate": (val) => getValidateUtils().setValue(val)
|
||||
.notString("传入的值为非字符串类型")
|
||||
.notEmptyAfterTrim("文件链接不能为空,请输入文件链接")
|
||||
.length(0, 150, "文件链接不能超过 150 个字符")
|
||||
.isValid()
|
||||
},
|
||||
{
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
"id": "fileId",
|
||||
"name": "fileId",
|
||||
"placeholder": "关联文件Id",
|
||||
"value": fileId || "",
|
||||
"disabled": true,
|
||||
},
|
||||
"label": {
|
||||
"value": "关联文件Id",
|
||||
},
|
||||
"required": true,
|
||||
"innerHTML": "",
|
||||
"validate": (val) => getValidateUtils().setValue(val)
|
||||
.notPositiveInteger("关联文件id需要为正整数")
|
||||
.isValid()
|
||||
},
|
||||
{
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
"id": "filePwd",
|
||||
"name": "filePwd",
|
||||
"placeholder": "文件密码",
|
||||
"value": fileObjectDetail.filePwd || "",
|
||||
},
|
||||
"label": {
|
||||
"value": "文件密码",
|
||||
},
|
||||
"required": false,
|
||||
"innerHTML": "",
|
||||
"validate": (val) => getValidateUtils().setValue(val)
|
||||
.notString("传入的值为非字符串类型")
|
||||
.isValid()
|
||||
},
|
||||
{
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
"id": "fileShareCode",
|
||||
"name": "fileShareCode",
|
||||
"placeholder": "提取码",
|
||||
"value": fileObjectDetail.fileShareCode || "",
|
||||
},
|
||||
"label": {
|
||||
"value": "提取码",
|
||||
},
|
||||
"required": false,
|
||||
"innerHTML": "",
|
||||
"validate": (val) => getValidateUtils().setValue(val)
|
||||
.notString("传入的值为非字符串类型")
|
||||
.isValid()
|
||||
},
|
||||
// {
|
||||
// "tag": "span",
|
||||
// "attr": {
|
||||
// },
|
||||
// "innerHTML": fileObjectDetail.uploadStatus || "",
|
||||
// "label": {
|
||||
// "value": "上传状态",
|
||||
// },
|
||||
// "required": false,
|
||||
// },
|
||||
];
|
||||
}
|
||||
</script>
|
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 50726
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 23/04/2022 10:24:36
|
||||
Date: 23/04/2022 22:43:31
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@@ -152,7 +152,6 @@ CREATE TABLE `file_info` (
|
||||
`advertising` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1为已删除项',
|
||||
`source` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
|
||||
`file_create_at` datetime NOT NULL,
|
||||
`file_modified_at` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -171,7 +171,7 @@ public class BookController extends BaseController {
|
||||
Integer affectRows = 0;
|
||||
if (bookId == null || bookId == 0) {
|
||||
// 新增图书
|
||||
isDelete = false;
|
||||
// isDelete = false;
|
||||
affectRows = bookService.addBook(bookModel);
|
||||
} else {
|
||||
//修改图书
|
||||
|
@@ -18,11 +18,10 @@ import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Common.FileManager.QCloudCosUtils;
|
||||
import plus.bookshelf.Common.Response.CommonReturnType;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Controller.VO.BookVO;
|
||||
import plus.bookshelf.Controller.VO.FileObjectVO;
|
||||
import plus.bookshelf.Service.Impl.*;
|
||||
import plus.bookshelf.Service.Model.FailureFeedbackModel;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Model.*;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -55,6 +54,45 @@ public class FileObjectController extends BaseController {
|
||||
VisitorFingerprintLogServiceImpl visitorFingerprintLogService;
|
||||
|
||||
|
||||
@ApiOperation(value = "【管理员】添加/修改文件对象", notes = "管理员在后台添加/修改文件对象(fileObjectId 传 0 或 null 或 不传 即为添加)")
|
||||
@RequestMapping(value = "detail", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType detail(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(required = false, value = "id") Integer fileObjectId,
|
||||
@RequestParam(required = false, value = "filePath") String filePath,
|
||||
@RequestParam(required = false, value = "fileId") Integer fileId,
|
||||
@RequestParam(required = false, value = "filePwd") String filePwd,
|
||||
@RequestParam(required = false, value = "fileShareCode") String fileShareCode,
|
||||
@RequestParam(required = false, value = "storageMedium") String storageMedium) throws BusinessException, InvocationTargetException, IllegalAccessException {
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
|
||||
FileObjectModel fileObjectModel = new FileObjectModel();
|
||||
|
||||
fileObjectModel.setFilePath(filePath);
|
||||
fileObjectModel.setFileId(fileId);
|
||||
fileObjectModel.setFilePwd(filePwd);
|
||||
fileObjectModel.setFileShareCode(fileShareCode);
|
||||
fileObjectModel.setStorageMedium(storageMedium);
|
||||
|
||||
Boolean isSuccess;
|
||||
if (fileObjectId == null || fileObjectId == 0) {
|
||||
// 新增文件对象
|
||||
fileObjectModel.setUploadStatus("SUCCESS");
|
||||
isSuccess = fileObjectService.addFileObject(fileObjectModel);
|
||||
} else {
|
||||
//修改文件对象
|
||||
fileObjectModel.setId(fileObjectId);
|
||||
isSuccess = fileObjectService.modifyFileObject(fileObjectModel);
|
||||
}
|
||||
|
||||
if (isSuccess) {
|
||||
return CommonReturnType.create("success");
|
||||
} else {
|
||||
return CommonReturnType.create("failed");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "链接失效反馈", notes = "查询文件列表")
|
||||
@RequestMapping(value = "FailureFeedback", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
@@ -125,6 +163,19 @@ public class FileObjectController extends BaseController {
|
||||
return CommonReturnType.create(fileObjectVOS);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取文件对象信息", notes = "获取文件对象信息")
|
||||
@RequestMapping(value = "get", method = {RequestMethod.GET})
|
||||
@ResponseBody
|
||||
public CommonReturnType get(@RequestParam(value = "id") Integer id) throws InvocationTargetException, IllegalAccessException {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileObjectModel fileObjectModel = fileObjectService.getFileObjectById(id);
|
||||
FileObjectVO fileObjectVO = convertFileObjectVOFromModel(fileObjectModel);
|
||||
return CommonReturnType.create(fileObjectVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】更新文件对象上传状态", notes = "重新从 COS 对象存储中获取文件对象上传状态")
|
||||
@RequestMapping(value = "refreshFileObjectStatus", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
@@ -378,7 +429,7 @@ public class FileObjectController extends BaseController {
|
||||
BeanUtils.copyProperties(fileObjectModel, fileObjectVO);
|
||||
try {
|
||||
// 尝试将 FileStorageMedium 转为中文,如果没有成功,那么就保留英文
|
||||
fileObjectVO.setStorageMedium(FileStorageMediumEnum.valueOf(fileObjectModel.getStorageMedium()).getStorageMediumDisplayName());
|
||||
fileObjectVO.setStorageMediumForDisplay(FileStorageMediumEnum.valueOf(fileObjectModel.getStorageMedium()).getStorageMediumDisplayName());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return fileObjectVO;
|
||||
|
@@ -15,6 +15,7 @@ public class FileObjectVO {
|
||||
String uploadStatus;
|
||||
|
||||
// 文件存储介质类型
|
||||
String storageMediumForDisplay;
|
||||
String storageMedium;
|
||||
|
||||
// 文件地址
|
||||
|
@@ -20,7 +20,6 @@ import plus.bookshelf.Service.Service.FileObjectService;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -107,6 +106,26 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件对象
|
||||
* 返回是否修改成功
|
||||
*
|
||||
* @param fileObjectModel
|
||||
* @return
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@Override
|
||||
public Boolean modifyFileObject(FileObjectModel fileObjectModel) {
|
||||
FileObjectDO fileObjectDO = convertFromFileObjectModel(fileObjectModel);
|
||||
Integer id = fileObjectDO.getId();
|
||||
if (id == 0) {
|
||||
return false;
|
||||
}
|
||||
int affectRows = fileObjectDOMapper.updateByPrimaryKeySelective(fileObjectDO);
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
private FileObjectDO convertFromFileObjectModel(FileObjectModel fileObjectModel) {
|
||||
if (fileObjectModel == null) {
|
||||
return null;
|
||||
|
@@ -38,6 +38,14 @@ public interface FileObjectService {
|
||||
*/
|
||||
Boolean addFileObject(FileObjectModel fileObjectModel) throws InvocationTargetException, IllegalAccessException;
|
||||
|
||||
/**
|
||||
* 修改文件对象
|
||||
*
|
||||
* @param fileObjectModel
|
||||
* @return
|
||||
*/
|
||||
Boolean modifyFileObject(FileObjectModel fileObjectModel);
|
||||
|
||||
/**
|
||||
* 向数据库中插入文件信息
|
||||
*
|
||||
|
Reference in New Issue
Block a user