feat: support set attachment path type. (#539)

pull/550/head
Ryan Wang 2020-02-02 16:16:20 +08:00 committed by GitHub
parent 32ed3a9a11
commit bb8ee0f074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import run.halo.app.model.entity.Attachment;
import run.halo.app.model.enums.AttachmentType;
import run.halo.app.model.params.AttachmentQuery;
import run.halo.app.model.properties.AttachmentProperties;
import run.halo.app.model.properties.OtherProperties;
import run.halo.app.model.support.UploadResult;
import run.halo.app.repository.AttachmentRepository;
import run.halo.app.service.AttachmentService;
@ -157,13 +158,15 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
// Get blog base url
String blogBaseUrl = optionService.getBlogBaseUrl();
Boolean enabledAbsolutePath = optionService.getByPropertyOrDefault(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.class, true);
// Convert to output dto
AttachmentDTO attachmentDTO = new AttachmentDTO().convertFrom(attachment);
if (Objects.equals(attachmentDTO.getType(), AttachmentType.LOCAL)) {
// Append blog base url to path and thumbnail
String fullPath = StringUtils.join(blogBaseUrl, "/", attachmentDTO.getPath());
String fullThumbPath = StringUtils.join(blogBaseUrl, "/", attachmentDTO.getThumbPath());
String fullPath = StringUtils.join(enabledAbsolutePath ? blogBaseUrl : "", "/", attachmentDTO.getPath());
String fullThumbPath = StringUtils.join(enabledAbsolutePath ? blogBaseUrl : "", "/", attachmentDTO.getThumbPath());
// Set full path and full thumb path
attachmentDTO.setPath(fullPath);