mirror of https://github.com/halo-dev/halo
feat: support set attachment path type. (#539)
parent
32ed3a9a11
commit
bb8ee0f074
|
@ -18,6 +18,7 @@ import run.halo.app.model.entity.Attachment;
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
import run.halo.app.model.params.AttachmentQuery;
|
import run.halo.app.model.params.AttachmentQuery;
|
||||||
import run.halo.app.model.properties.AttachmentProperties;
|
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.model.support.UploadResult;
|
||||||
import run.halo.app.repository.AttachmentRepository;
|
import run.halo.app.repository.AttachmentRepository;
|
||||||
import run.halo.app.service.AttachmentService;
|
import run.halo.app.service.AttachmentService;
|
||||||
|
@ -157,13 +158,15 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
||||||
// Get blog base url
|
// Get blog base url
|
||||||
String blogBaseUrl = optionService.getBlogBaseUrl();
|
String blogBaseUrl = optionService.getBlogBaseUrl();
|
||||||
|
|
||||||
|
Boolean enabledAbsolutePath = optionService.getByPropertyOrDefault(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.class, true);
|
||||||
|
|
||||||
// Convert to output dto
|
// Convert to output dto
|
||||||
AttachmentDTO attachmentDTO = new AttachmentDTO().convertFrom(attachment);
|
AttachmentDTO attachmentDTO = new AttachmentDTO().convertFrom(attachment);
|
||||||
|
|
||||||
if (Objects.equals(attachmentDTO.getType(), AttachmentType.LOCAL)) {
|
if (Objects.equals(attachmentDTO.getType(), AttachmentType.LOCAL)) {
|
||||||
// Append blog base url to path and thumbnail
|
// Append blog base url to path and thumbnail
|
||||||
String fullPath = StringUtils.join(blogBaseUrl, "/", attachmentDTO.getPath());
|
String fullPath = StringUtils.join(enabledAbsolutePath ? blogBaseUrl : "", "/", attachmentDTO.getPath());
|
||||||
String fullThumbPath = StringUtils.join(blogBaseUrl, "/", attachmentDTO.getThumbPath());
|
String fullThumbPath = StringUtils.join(enabledAbsolutePath ? blogBaseUrl : "", "/", attachmentDTO.getThumbPath());
|
||||||
|
|
||||||
// Set full path and full thumb path
|
// Set full path and full thumb path
|
||||||
attachmentDTO.setPath(fullPath);
|
attachmentDTO.setPath(fullPath);
|
||||||
|
|
Loading…
Reference in New Issue