Build FileHandler basic structure

pull/137/head
johnniang 2019-03-27 11:09:46 +08:00
parent b85152f8a7
commit 88e0bc3099
6 changed files with 135 additions and 2 deletions

View File

@ -41,6 +41,12 @@ public class Attachment extends BaseEntity {
@Column(name = "path", columnDefinition = "varchar(1023) not null")
private String path;
/**
* File key: oss file key or local file key (Just for deleting)
*/
@Column(name = "file_key", columnDefinition = "varchar(2047) default ''")
private String fileKey;
/**
*
*/
@ -88,6 +94,10 @@ public class Attachment extends BaseEntity {
super.prePersist();
id = null;
if (fileKey == null) {
fileKey = "";
}
if (thumbPath == null) {
thumbPath = "";
}
@ -107,7 +117,5 @@ public class Attachment extends BaseEntity {
if (type == null) {
type = AttachmentType.SERVER;
}
}
}

View File

@ -16,6 +16,8 @@ public class UploadResult {
private String filePath;
private String key;
private String thumbPath;
private String suffix;

View File

@ -0,0 +1,33 @@
package cc.ryanc.halo.service.upload;
import cc.ryanc.halo.exception.FileUploadException;
import cc.ryanc.halo.model.support.UploadResult;
import org.springframework.lang.NonNull;
import org.springframework.web.multipart.MultipartFile;
/**
* File handler interface.
*
* @author johnniang
* @date 3/27/19
*/
public interface FileHandler {
/**
* Uploads file.
*
* @param file multipart file must not be null
* @return upload result
* @throws FileUploadException throws when fail to upload the file
*/
@NonNull
UploadResult upload(@NonNull MultipartFile file);
/**
* Deletes file.
*
* @param key file key must not be null
*/
boolean delete(@NonNull String key);
}

View File

@ -0,0 +1,30 @@
package cc.ryanc.halo.service.upload;
import cc.ryanc.halo.model.support.UploadResult;
import cc.ryanc.halo.service.OptionService;
import org.springframework.web.multipart.MultipartFile;
/**
* Local file handler.
*
* @author johnniang
* @date 3/27/19
*/
public class LocalFileHandler implements FileHandler {
private final OptionService optionService;
public LocalFileHandler(OptionService optionService) {
this.optionService = optionService;
}
@Override
public UploadResult upload(MultipartFile file) {
return null;
}
@Override
public boolean delete(String key) {
return false;
}
}

View File

@ -0,0 +1,30 @@
package cc.ryanc.halo.service.upload;
import cc.ryanc.halo.model.support.UploadResult;
import cc.ryanc.halo.service.OptionService;
import org.springframework.web.multipart.MultipartFile;
/**
* Qi niu yun file handler.
*
* @author johnniang
* @date 3/27/19
*/
public class QnYunFileHandler implements FileHandler {
private final OptionService optionService;
public QnYunFileHandler(OptionService optionService) {
this.optionService = optionService;
}
@Override
public UploadResult upload(MultipartFile file) {
return null;
}
@Override
public boolean delete(String key) {
return false;
}
}

View File

@ -0,0 +1,30 @@
package cc.ryanc.halo.service.upload;
import cc.ryanc.halo.model.support.UploadResult;
import cc.ryanc.halo.service.OptionService;
import org.springframework.web.multipart.MultipartFile;
/**
* Up Yun file handler.
*
* @author johnniang
* @date 3/27/19
*/
public class UpYunFileHandler implements FileHandler {
private final OptionService optionService;
public UpYunFileHandler(OptionService optionService) {
this.optionService = optionService;
}
@Override
public UploadResult upload(MultipartFile file) {
return null;
}
@Override
public boolean delete(String key) {
return false;
}
}