Skip to content

Commit

Permalink
support upload by paste copied file
Browse files Browse the repository at this point in the history
  • Loading branch information
sbx0 committed Jan 11, 2024
1 parent 5c99901 commit 1220369
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ public class ServerScheduled {
@Resource
private TaskService taskService;

@Scheduled(fixedRate = 1000)
// @Scheduled(fixedRate = 1000)
public void handleReminderTime() {
taskService.handleReminderTime();
}

@Scheduled(fixedRate = 1000)
// @Scheduled(fixedRate = 1000)
public void handleMessage() {
chatGPTService.handleMessage();
}

@Scheduled(fixedRate = 1000)
// @Scheduled(fixedRate = 1000)
public void sendMessage() {
chatGPTService.sendMessage();
}

// 30min @Scheduled(fixedRate = 1800000)
// 15min @Scheduled(fixedRate = 900000)
// 1min @Scheduled(fixedRate = 60000)
@Scheduled(fixedRate = 3600000)
// @Scheduled(fixedRate = 3600000)
public void getCarPlatePhoto() {
DefaultPagingRequest pagingRequest = new DefaultPagingRequest();
pagingRequest.setPage(1);
Expand Down
4 changes: 4 additions & 0 deletions todo-service/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ spring:
password: justfordev
repositories:
enabled: false
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
logging:
file:
name: ./logs/current.log
Expand Down
48 changes: 29 additions & 19 deletions todo-web/app/file/components/upload/upload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,10 @@ function DragAndDropUpload() {
event.dataTransfer.dropEffect = 'copy';
};

const handleDrop = (event) => {
event.preventDefault();
setDragging(false);

const uploadFiles = event.dataTransfer.files;
// 处理上传文件的逻辑,例如使用FormData发送到服务器

const handleUpload = (uploadFiles) => {
console.log('Dropped files:', uploadFiles);

// 创建 FormData 对象
const formData = new FormData();

// 将每个文件添加到 FormData
for (let i = 0; i < uploadFiles.length; i++) {
formData.append('file', uploadFiles[i]);
}
Expand All @@ -49,25 +40,43 @@ function DragAndDropUpload() {
}
}

// 使用 fetch 发送文件到服务器
fetch('/api/file/upload', {
method: 'POST',
body: formData,
headers: headers
})
.then(response => response.json())
.then(data => {
let newFiles = files.slice(0);
let file = data.data;
newFiles.push(file);
setFiles(newFiles);
.then(json => {
if (json.success) {
let newFiles = files.slice(0);
let file = json.data;
newFiles.push(file);
setFiles(newFiles);
} else {
console.error('Upload failed:', json.message);
}
})
.catch(error => {
// 处理上传失败的逻辑
console.error('Upload failed:', error);
});
}

const handleDrop = (event) => {
event.preventDefault();
setDragging(false);
const uploadFiles = event.dataTransfer.files;
handleUpload(uploadFiles);
};

const handlePaste = (event) => {
event.preventDefault();
const clipData = event.clipboardData || window.clipboardData;
const isFiles = !!clipData.files?.length;
if (isFiles) {
handleUpload(clipData.files);
}
}

return (
<div>
<div
Expand All @@ -76,11 +85,12 @@ function DragAndDropUpload() {
onDragLeave={handleDragLeave}
onDragOver={handleDragOver}
onDrop={handleDrop}
onPaste={handlePaste}
>
<div className="bg-white rounded-lg shadow-lg p-6">
<h1 className="text-3xl font-bold mb-4">拖拽上传</h1>
<h1 className="text-3xl font-bold mb-4">拖拽/粘贴上传</h1>
<p className="text-gray-700 mb-4">
拖拽文件到此区域进行上传
拖拽/粘贴文件到此区域进行上传
</p>
<div className="border-2 border-dashed border-gray-400 p-4">
{dragging ? '放开以上传文件' : '拖拽文件到此区域'}
Expand Down

0 comments on commit 1220369

Please sign in to comment.