[파일 업로드] tusHook 작업
- 진행중
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.alist.api.common.modules.file;
|
package com.alist.api.common.modules.file;
|
||||||
|
|
||||||
import com.alist.api.common.modules.file.dto.UploadTokenDto;
|
import com.alist.api.common.modules.file.dto.UploadTokenDto;
|
||||||
|
import com.alist.api.common.modules.file.form.TusHookForm;
|
||||||
import com.alist.api.common.response.ApiResponse;
|
import com.alist.api.common.response.ApiResponse;
|
||||||
import com.alist.api.common.response.ApiResponseCode;
|
import com.alist.api.common.response.ApiResponseCode;
|
||||||
import com.alist.api.common.modules.file.dto.UploadStartDto;
|
import com.alist.api.common.modules.file.dto.UploadStartDto;
|
||||||
@@ -82,8 +83,8 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tusHook")
|
@PostMapping("/tusHook")
|
||||||
public ResponseEntity<ApiResponse<String>> tusHook(@RequestBody Map<String, Object> payload) {
|
public ResponseEntity<ApiResponse<String>> tusHook(@RequestBody TusHookForm tusHookForm) {
|
||||||
log.debug("[tusHook] payload={}", payload);
|
fileService.insertFileAndSave(tusHookForm.tusHookDto());
|
||||||
return ApiResponse.entity("", ApiResponseCode.CODE_200);
|
return ApiResponse.entity("", ApiResponseCode.CODE_200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.alist.api.common.modules.file.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class TusHookDto {
|
||||||
|
private TusHookEventDto tusHookEventDto;
|
||||||
|
private TusHookUploadDto tusHookUploadDto;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.alist.api.common.modules.file.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class TusHookEventDto {
|
||||||
|
private String Type;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.alist.api.common.modules.file.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class TusHookUploadDto {
|
||||||
|
private String id;
|
||||||
|
private Long size;
|
||||||
|
private Map<String, String> metaData;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.alist.api.common.modules.file.form;
|
||||||
|
|
||||||
|
import com.alist.api.common.modules.file.dto.TusHookDto;
|
||||||
|
import com.alist.api.common.modules.file.dto.TusHookEventDto;
|
||||||
|
import com.alist.api.common.modules.file.dto.TusHookUploadDto;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class TusHookForm {
|
||||||
|
private TusHookEventDto event;
|
||||||
|
private TusHookUploadDto upload;
|
||||||
|
|
||||||
|
public TusHookDto tusHookDto() {
|
||||||
|
TusHookDto tusHookDto = new TusHookDto();
|
||||||
|
tusHookDto.setTusHookEventDto(this.event);
|
||||||
|
tusHookDto.setTusHookUploadDto(this.upload);
|
||||||
|
|
||||||
|
return tusHookDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
package com.alist.api.common.modules.file.service;
|
package com.alist.api.common.modules.file.service;
|
||||||
|
|
||||||
|
import com.alist.api.common.modules.file.dto.TusHookDto;
|
||||||
|
import com.alist.api.common.modules.file.dto.TusHookUploadDto;
|
||||||
import com.alist.api.common.modules.file.dto.UploadStartDto;
|
import com.alist.api.common.modules.file.dto.UploadStartDto;
|
||||||
import com.alist.api.common.modules.file.dto.UploadTokenDto;
|
import com.alist.api.common.modules.file.dto.UploadTokenDto;
|
||||||
import com.alist.api.common.modules.file.mapper.FileMapper;
|
import com.alist.api.common.modules.file.mapper.FileMapper;
|
||||||
import com.alist.api.config.jwt.JwtTokenProvider;
|
import com.alist.api.config.jwt.JwtTokenProvider;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class FileService {
|
public class FileService {
|
||||||
@Value("${file.upload.tus-endpoint}")
|
@Value("${file.upload.tus-endpoint}")
|
||||||
@@ -67,4 +72,24 @@ public class FileService {
|
|||||||
|
|
||||||
return uploadTokenDto;
|
return uploadTokenDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertFileAndSave(TusHookDto tusHookDto) {
|
||||||
|
if (tusHookDto == null || tusHookDto.getTusHookEventDto() == null || tusHookDto.getTusHookUploadDto() == null) {
|
||||||
|
log.debug("[tusHook] invalid payload");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String eventType = tusHookDto.getTusHookEventDto().getType();
|
||||||
|
TusHookUploadDto upload = tusHookDto.getTusHookUploadDto();
|
||||||
|
Map<String, String> meta = upload.getMetaData();
|
||||||
|
|
||||||
|
String uploadId = upload.getId();
|
||||||
|
Long size = upload.getSize();
|
||||||
|
String fileMasterKey = meta == null ? null : meta.get("fileMasterKey");
|
||||||
|
String filename = meta == null ? null : meta.get("filename");
|
||||||
|
String filetype = meta == null ? null : meta.get("filetype");
|
||||||
|
|
||||||
|
log.debug("[tusHook] eventType={}, uploadId={}, size={}, fileMasterKey={}, filename={}, filetype={}",
|
||||||
|
eventType, uploadId, size, fileMasterKey, filename, filetype);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user