mirror of https://github.com/halo-dev/halo
Build FileHandler basic structure
parent
b85152f8a7
commit
88e0bc3099
|
@ -41,6 +41,12 @@ public class Attachment extends BaseEntity {
|
||||||
@Column(name = "path", columnDefinition = "varchar(1023) not null")
|
@Column(name = "path", columnDefinition = "varchar(1023) not null")
|
||||||
private String path;
|
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();
|
super.prePersist();
|
||||||
id = null;
|
id = null;
|
||||||
|
|
||||||
|
if (fileKey == null) {
|
||||||
|
fileKey = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (thumbPath == null) {
|
if (thumbPath == null) {
|
||||||
thumbPath = "";
|
thumbPath = "";
|
||||||
}
|
}
|
||||||
|
@ -107,7 +117,5 @@ public class Attachment extends BaseEntity {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = AttachmentType.SERVER;
|
type = AttachmentType.SERVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ public class UploadResult {
|
||||||
|
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
private String thumbPath;
|
private String thumbPath;
|
||||||
|
|
||||||
private String suffix;
|
private String suffix;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue