mirror of https://github.com/halo-dev/halo
Fix issue(#153)
parent
6169858b3d
commit
384ada38d1
|
@ -15,7 +15,7 @@ jobs:
|
||||||
- stage: test
|
- stage: test
|
||||||
script: ./gradlew check
|
script: ./gradlew check
|
||||||
- stage: build
|
- stage: build
|
||||||
script: ./gradlew build -x test
|
script: ./gradlew clean build -x test
|
||||||
- stage: Build Docker Image for Release
|
- stage: Build Docker Image for Release
|
||||||
script: ./scripts/docker-build-release.sh
|
script: ./scripts/docker-build-release.sh
|
||||||
- stage: Build Docker Image for Dev
|
- stage: Build Docker Image for Dev
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package run.halo.app.handler.file;
|
package run.halo.app.handler.file;
|
||||||
|
|
||||||
import run.halo.app.exception.FileOperationException;
|
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
|
||||||
import run.halo.app.model.support.UploadResult;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import run.halo.app.exception.FileOperationException;
|
||||||
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
|
import run.halo.app.model.support.UploadResult;
|
||||||
|
|
||||||
import java.io.File;
|
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File handler interface.
|
* File handler interface.
|
||||||
|
@ -80,6 +80,6 @@ public interface FileHandler {
|
||||||
static String normalizeDirectory(@NonNull String dir) {
|
static String normalizeDirectory(@NonNull String dir) {
|
||||||
Assert.hasText(dir, "Directory full name must not be blank");
|
Assert.hasText(dir, "Directory full name must not be blank");
|
||||||
|
|
||||||
return StringUtils.appendIfMissing(dir, File.separator);
|
return StringUtils.appendIfMissing(dir, FILE_SEPARATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,15 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local file handler.
|
* Local file handler.
|
||||||
*
|
*
|
||||||
|
@ -97,7 +97,7 @@ public class LocalFileHandler implements FileHandler {
|
||||||
int month = current.get(Calendar.MONTH) + 1;
|
int month = current.get(Calendar.MONTH) + 1;
|
||||||
|
|
||||||
// Build directory
|
// Build directory
|
||||||
String subDir = UPLOAD_SUB_DIR + year + File.separator + month + File.separator;
|
String subDir = UPLOAD_SUB_DIR + year + FILE_SEPARATOR + month + FILE_SEPARATOR;
|
||||||
|
|
||||||
String originalBasename = FilenameUtils.getBasename(file.getOriginalFilename());
|
String originalBasename = FilenameUtils.getBasename(file.getOriginalFilename());
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package run.halo.app.model.support;
|
package run.halo.app.model.support;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 公共常量
|
* 公共常量
|
||||||
|
@ -25,6 +27,11 @@ public class HaloConst {
|
||||||
*/
|
*/
|
||||||
public static final String HALO_VERSION;
|
public static final String HALO_VERSION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path separator.
|
||||||
|
*/
|
||||||
|
public static final String FILE_SEPARATOR = File.separator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suffix of freemarker template file
|
* Suffix of freemarker template file
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@ import run.halo.app.repository.AttachmentRepository;
|
||||||
import run.halo.app.service.AttachmentService;
|
import run.halo.app.service.AttachmentService;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.base.AbstractCrudService;
|
import run.halo.app.service.base.AbstractCrudService;
|
||||||
|
import run.halo.app.utils.HaloUtils;
|
||||||
|
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -108,7 +109,8 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
||||||
// Build attachment
|
// Build attachment
|
||||||
Attachment attachment = new Attachment();
|
Attachment attachment = new Attachment();
|
||||||
attachment.setName(uploadResult.getFilename());
|
attachment.setName(uploadResult.getFilename());
|
||||||
attachment.setPath(uploadResult.getFilePath());
|
// Convert separator
|
||||||
|
attachment.setPath(HaloUtils.changeFileSeparatorToUrlSeparator(uploadResult.getFilePath()));
|
||||||
attachment.setFileKey(uploadResult.getKey());
|
attachment.setFileKey(uploadResult.getKey());
|
||||||
attachment.setThumbPath(uploadResult.getThumbPath());
|
attachment.setThumbPath(uploadResult.getThumbPath());
|
||||||
attachment.setMediaType(uploadResult.getMediaType().toString());
|
attachment.setMediaType(uploadResult.getMediaType().toString());
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 常用工具
|
* 常用工具
|
||||||
|
@ -31,6 +33,18 @@ import java.util.UUID;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HaloUtils {
|
public class HaloUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes file separator to url separator.
|
||||||
|
*
|
||||||
|
* @param pathname full path name must not be blank.
|
||||||
|
* @return text with url separator
|
||||||
|
*/
|
||||||
|
public static String changeFileSeparatorToUrlSeparator(@NonNull String pathname) {
|
||||||
|
Assert.hasText(pathname, "Path name must not be blank");
|
||||||
|
|
||||||
|
return pathname.replace(FILE_SEPARATOR, "/");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Time format.
|
* Time format.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue