Skip to content

Commit

Permalink
get upload file list
Browse files Browse the repository at this point in the history
  • Loading branch information
sbx0 committed Jan 11, 2024
1 parent 1220369 commit e4e0cab
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
Expand Down Expand Up @@ -74,6 +77,26 @@ public ResponseEntity<FileSystemResource> downloadFile(@PathVariable String file
.body(fileSystemResource);
}

@GetMapping("/list")
public Result<List<FileInfoEntity>> fileList() {
File folder = new File(UPLOAD_DIR);
File[] files = folder.listFiles();
List<FileInfoEntity> fileInfos = new ArrayList<>();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
continue;
}
String name = file.getName();
if (name.contains(JSON_TYPE)) {
continue;
}
fileInfos.add(new FileInfoEntity(name));
}
}
return Result.success(fileInfos);
}

private String calculateMD5(byte[] fileBytes) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(fileBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ public class FileInfoEntity {
private String fileName;
private String originalFileName;
private String md5;

public FileInfoEntity() {
}

public FileInfoEntity(String fileName) {
this.fileName = fileName;
}
}
4 changes: 2 additions & 2 deletions todo-service/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ spring:
enabled: false
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
max-file-size: 100MB
max-request-size: 100MB
logging:
file:
name: ./logs/current.log
Expand Down
1 change: 1 addition & 0 deletions todo-web/apis/apiPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const TaskStatistics = API + "/task/statistics";
export const AssetTypePaging = API + "/asset/type/paging";
export const RecentRecordTimeList = API + "/asset/record/getRecentRecordTimeList";
export const AssetRecords = API + "/asset/record/getRecords";
export const FileList = API + "/file/list";
24 changes: 24 additions & 0 deletions todo-web/app/file/components/image/image.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client"

import React, {useState} from 'react';

function ImageClickFull({src}) {
const [isFullScreen, setIsFullScreen] = useState(false);

const toggleFullScreen = () => {
setIsFullScreen(!isFullScreen);
};

return (
<div className={`${isFullScreen ? 'w-screen h-screen fixed top-0 left-0 bg-black' : ''}`}
onClick={toggleFullScreen}>
<img src={src}
className={`${isFullScreen ? 'w-full h-full object-contain mx-auto' : ''}`}
alt=""
loading="lazy"
/>
</div>
);
}

export default ImageClickFull;
20 changes: 18 additions & 2 deletions todo-web/app/file/components/upload/upload.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
"use client"

import React, {useState} from 'react';
import React, {useEffect, useState} from 'react';
import {getCookie} from "../../../../apis/cookies";
import {callApi} from "../../../../apis/request";
import {FileList, GET, POST} from "../../../../apis/apiPath";
import ImageClickFull from "../image/image";

function DragAndDropUpload() {
const [files, setFiles] = useState([])
const [dragging, setDragging] = useState(false);

useEffect(() => {
getFileList();
}, []);

const getFileList = () => {
callApi({
method: GET,
url: FileList,
}).then(r => {
setFiles(r.data)
})
}

const handleDragEnter = (event) => {
event.preventDefault();
setDragging(true);
Expand Down Expand Up @@ -101,7 +117,7 @@ function DragAndDropUpload() {
{
files.map((one => {
return <div key={one.fileName}>
<img src={'/api/file/download/' + one.fileName} alt="" loading="lazy"/>
<ImageClickFull src={'/api/file/download/' + one.fileName}/>
</div>;
}))
}
Expand Down

0 comments on commit e4e0cab

Please sign in to comment.