Merge remote-tracking branch 'origin/dev' into dev

pull/157/head
ruibaby 2019-05-12 00:00:52 +08:00
commit 2c8d43785d
6 changed files with 35 additions and 11 deletions

View File

@ -15,7 +15,7 @@ jobs:
- stage: test
script: ./gradlew check
- stage: build
script: ./gradlew build -x test
script: ./gradlew clean build -x test
- stage: Build Docker Image for Release
script: ./scripts/docker-build-release.sh
- stage: Build Docker Image for Dev
@ -33,7 +33,8 @@ jobs:
stages:
- test
- build
- GitHub Release
- name: GitHub Release
if: tag =~ /^v\d+\.\d+(\.\d+)?(-\S*)?$/
- name: Build Docker Image for Release
if: tag =~ /^v\d+\.\d+(\.\d+)?(-release)?$/
- name: Build Docker Image for Dev

View File

@ -1,16 +1,16 @@
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.springframework.http.MediaType;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
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.
@ -80,6 +80,6 @@ public interface FileHandler {
static String normalizeDirectory(@NonNull String dir) {
Assert.hasText(dir, "Directory full name must not be blank");
return StringUtils.appendIfMissing(dir, File.separator);
return StringUtils.appendIfMissing(dir, FILE_SEPARATOR);
}
}

View File

@ -18,15 +18,15 @@ import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Calendar;
import java.util.Locale;
import java.util.Objects;
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
/**
* Local file handler.
*
@ -97,7 +97,7 @@ public class LocalFileHandler implements FileHandler {
int month = current.get(Calendar.MONTH) + 1;
// 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());

View File

@ -1,5 +1,7 @@
package run.halo.app.model.support;
import java.io.File;
/**
* <pre>
*
@ -25,6 +27,11 @@ public class HaloConst {
*/
public static final String HALO_VERSION;
/**
* Path separator.
*/
public static final String FILE_SEPARATOR = File.separator;
/**
* Suffix of freemarker template file
*/

View File

@ -21,6 +21,7 @@ import run.halo.app.repository.AttachmentRepository;
import run.halo.app.service.AttachmentService;
import run.halo.app.service.OptionService;
import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.utils.HaloUtils;
import javax.persistence.criteria.Predicate;
import java.util.LinkedList;
@ -108,7 +109,8 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
// Build attachment
Attachment attachment = new Attachment();
attachment.setName(uploadResult.getFilename());
attachment.setPath(uploadResult.getFilePath());
// Convert separator
attachment.setPath(HaloUtils.changeFileSeparatorToUrlSeparator(uploadResult.getFilePath()));
attachment.setFileKey(uploadResult.getKey());
attachment.setThumbPath(uploadResult.getThumbPath());
attachment.setMediaType(uploadResult.getMediaType().toString());

View File

@ -20,6 +20,8 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.Date;
import java.util.UUID;
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
/**
* <pre>
*
@ -31,6 +33,18 @@ import java.util.UUID;
@Slf4j
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.
*