feat: 开发中...
This commit is contained in:
@@ -48,15 +48,21 @@ public class AttachService implements IAttachService {
|
|||||||
if (checked != null) {
|
if (checked != null) {
|
||||||
return checked;
|
return checked;
|
||||||
}
|
}
|
||||||
log.info("prepare to save file: {}({} bytes)", file.getOriginalFilename(), file.getSize());
|
log.info("prepare to save file: {}({} kb)", file.getOriginalFilename(), file.getSize() / 1024.0);
|
||||||
|
long time1 = System.currentTimeMillis();
|
||||||
AttachEntity attachEntity = new AttachEntity();
|
AttachEntity attachEntity = new AttachEntity();
|
||||||
attachEntity.setFilename(file.getOriginalFilename());
|
attachEntity.setFilename(file.getOriginalFilename());
|
||||||
attachEntity.setContentType(file.getContentType());
|
attachEntity.setContentType(file.getContentType());
|
||||||
attachEntity.setData(file.getBytes());
|
attachEntity.setData(file.getBytes());
|
||||||
attachEntity = attachRepo.save(attachEntity);
|
attachEntity = attachRepo.save(attachEntity);
|
||||||
|
long time2 = System.currentTimeMillis();
|
||||||
|
log.info("file upload finished, took {} ms", time2 - time1);
|
||||||
|
|
||||||
File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachEntity.getId()));
|
File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachEntity.getId()));
|
||||||
Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
log.info("written attach data to local cache file: {}. took {} ms",
|
||||||
|
localCacheFile.getName(),
|
||||||
|
System.currentTimeMillis() - time2);
|
||||||
|
|
||||||
return ResponseVO.success(attachEntity.getId());
|
return ResponseVO.success(attachEntity.getId());
|
||||||
}
|
}
|
||||||
@@ -113,16 +119,23 @@ public class AttachService implements IAttachService {
|
|||||||
if (!attachRepo.existsById(attachID)) {
|
if (!attachRepo.existsById(attachID)) {
|
||||||
return ResponseVO.notFound();
|
return ResponseVO.notFound();
|
||||||
}
|
}
|
||||||
|
log.info("update attach {}, save file {} to database. ({} kb)", attachID,
|
||||||
|
file.getOriginalFilename(), file.getSize() / 1024.0);
|
||||||
|
long time1 = System.currentTimeMillis();
|
||||||
attachRepo.updateFilenameAndContentTypeAndDataById(
|
attachRepo.updateFilenameAndContentTypeAndDataById(
|
||||||
file.getOriginalFilename(),
|
file.getOriginalFilename(),
|
||||||
file.getContentType(),
|
file.getContentType(),
|
||||||
file.getBytes(),
|
file.getBytes(),
|
||||||
attachID
|
attachID
|
||||||
);
|
);
|
||||||
|
long time2 = System.currentTimeMillis();
|
||||||
|
log.info("file upload finished, took {} ms", time2 - time1);
|
||||||
|
|
||||||
File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachID));
|
File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachID));
|
||||||
Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
log.info("written attach data to local cache file: {}", localCacheFile.getName());
|
log.info("written attach data to local cache file: {}. took {} ms",
|
||||||
|
localCacheFile.getName(),
|
||||||
|
System.currentTimeMillis() - time2);
|
||||||
|
|
||||||
return ResponseVO.success();
|
return ResponseVO.success();
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import type { UploadRawFile, UploadRequestOptions } from "element-plus";
|
import type { UploadRequestOptions } from "element-plus";
|
||||||
|
|
||||||
import { api } from "@/api";
|
import { api } from "@/api";
|
||||||
import type { AttachInfoResponseVO } from "@/swagger";
|
import type { AttachInfoResponseVO } from "@/swagger";
|
||||||
@@ -32,7 +32,7 @@ function loadPage(newPage: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function uploadAttach(options: UploadRequestOptions) {
|
function uploadAttach(options: UploadRequestOptions) {
|
||||||
api.AttachController.createAttachForm(options.file).then((resp) => {
|
return api.AttachController.createAttachForm(options.file).then((resp) => {
|
||||||
const vo = resp.data;
|
const vo = resp.data;
|
||||||
if (vo.code === 200) {
|
if (vo.code === 200) {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
@@ -48,7 +48,6 @@ function uploadAttach(options: UploadRequestOptions) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateAttach(options: UploadRequestOptions) {
|
async function updateAttach(options: UploadRequestOptions) {
|
||||||
@@ -111,13 +110,13 @@ function deleteAttach(id: number) {
|
|||||||
</template>
|
</template>
|
||||||
<p>
|
<p>
|
||||||
由 {{ attach.creator.nickname }} 首次创建于
|
由 {{ attach.creator.nickname }} 首次创建于
|
||||||
{{ attach.createTime.toTimeString() }}
|
{{ attach.createTime.toLocaleString() }}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
由 {{ attach.creator.nickname }} 最后修改于
|
由 {{ attach.creator.nickname }} 最后修改于
|
||||||
{{ attach.updateTime.toTimeString() }}
|
{{ attach.updateTime.toLocaleString() }}
|
||||||
</p>
|
</p>
|
||||||
<div style="display: flex" class="attach-card-buttons">
|
<div class="attach-card-buttons">
|
||||||
<div style="flex-grow: 1"></div>
|
<div style="flex-grow: 1"></div>
|
||||||
<el-upload
|
<el-upload
|
||||||
:http-request="updateAttach"
|
:http-request="updateAttach"
|
||||||
@@ -131,7 +130,11 @@ function deleteAttach(id: number) {
|
|||||||
>
|
>
|
||||||
<el-button type="success">编辑</el-button>
|
<el-button type="success">编辑</el-button>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<el-button type="danger" @click="deleteAttach(attach.id)">
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
@click="deleteAttach(attach.id)"
|
||||||
|
style="margin-left: 15px"
|
||||||
|
>
|
||||||
删除
|
删除
|
||||||
</el-button>
|
</el-button>
|
||||||
<div style="flex-grow: 1"></div>
|
<div style="flex-grow: 1"></div>
|
||||||
@@ -167,19 +170,19 @@ function deleteAttach(id: number) {
|
|||||||
|
|
||||||
.attach-list {
|
.attach-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-around;
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.attach-card {
|
.attach-card {
|
||||||
margin-left: 12px;
|
margin-bottom: 15px;
|
||||||
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
attach-card-buttons {
|
.attach-card-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
margin-top: 15px;
|
||||||
|
|
||||||
.attach-card-buttons > * {
|
|
||||||
margin-left: 15px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@@ -52,5 +52,5 @@ export interface BlogUpdateRequireVO {
|
|||||||
* @type {Array<string>}
|
* @type {Array<string>}
|
||||||
* @memberof BlogUpdateRequireVO
|
* @memberof BlogUpdateRequireVO
|
||||||
*/
|
*/
|
||||||
tags?: Array<string>;
|
tags: Array<string>;
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,6 @@ onMounted(() => {
|
|||||||
editBlog.top = blog?.top;
|
editBlog.top = blog?.top;
|
||||||
editBlog.publish = blog?.publish;
|
editBlog.publish = blog?.publish;
|
||||||
editBlog.content = blog?.content ?? "";
|
editBlog.content = blog?.content ?? "";
|
||||||
tags.value = blog?.tags.toString();
|
|
||||||
} else {
|
} else {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
type: "error",
|
type: "error",
|
||||||
|
Reference in New Issue
Block a user