Skip to content

Commit

Permalink
feat: support set attachment path type. (halo-dev#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Feb 2, 2020
1 parent 32ed3a9 commit bb8ee0f
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -157,13 +158,15 @@ public AttachmentDTO convertToDto(Attachment attachment) {
// 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);
Expand Down

0 comments on commit bb8ee0f

Please sign in to comment.