mirror of https://github.com/halo-dev/halo
feat: support replace url method.
parent
c37f36f61e
commit
305d907531
|
@ -82,4 +82,13 @@ public interface AttachmentService extends CrudService<Attachment, Integer> {
|
||||||
* @return list of type.
|
* @return list of type.
|
||||||
*/
|
*/
|
||||||
List<AttachmentType> listAllType();
|
List<AttachmentType> listAllType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace attachment url in batch.
|
||||||
|
*
|
||||||
|
* @param oldUrl old blog url.
|
||||||
|
* @param newUrl new blog url.
|
||||||
|
* @return replaced attachments.
|
||||||
|
*/
|
||||||
|
List<Attachment> replaceUrl(@NonNull String oldUrl, @NonNull String newUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,6 +338,15 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
*/
|
*/
|
||||||
long getBirthday();
|
long getBirthday();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace option url in batch.
|
||||||
|
*
|
||||||
|
* @param oldUrl old blog url.
|
||||||
|
* @param newUrl new blog url.
|
||||||
|
* @return replaced options.
|
||||||
|
*/
|
||||||
|
List<OptionDTO> replaceUrl(@NonNull String oldUrl, @NonNull String newUrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts to option output dto.
|
* Converts to option output dto.
|
||||||
*
|
*
|
||||||
|
|
|
@ -80,4 +80,13 @@ public interface PhotoService extends CrudService<Photo, Integer> {
|
||||||
* @return list of teams
|
* @return list of teams
|
||||||
*/
|
*/
|
||||||
List<String> listAllTeams();
|
List<String> listAllTeams();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace photo url in batch.
|
||||||
|
*
|
||||||
|
* @param oldUrl old blog url.
|
||||||
|
* @param newUrl new blog url.
|
||||||
|
* @return replaced photos.
|
||||||
|
*/
|
||||||
|
List<PhotoDTO> replaceUrl(@NonNull String oldUrl, @NonNull String newUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,4 +55,13 @@ public interface ThemeSettingService {
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Map<String, Object> listAsMapBy(@NonNull String themeId);
|
Map<String, Object> listAsMapBy(@NonNull String themeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace theme setting url in batch.
|
||||||
|
*
|
||||||
|
* @param oldUrl old blog url.
|
||||||
|
* @param newUrl new blog url.
|
||||||
|
* @return replaced theme settings.
|
||||||
|
*/
|
||||||
|
List<ThemeSetting> replaceUrl(@NonNull String oldUrl, @NonNull String newUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,4 +285,13 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
||||||
*/
|
*/
|
||||||
<T extends BaseCommentDTO> Page<T> filterIpAddress(@NonNull Page<T> commentPage);
|
<T extends BaseCommentDTO> Page<T> filterIpAddress(@NonNull Page<T> commentPage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace comment url in batch.
|
||||||
|
*
|
||||||
|
* @param oldUrl old blog url.
|
||||||
|
* @param newUrl new blog url.
|
||||||
|
* @return replaced comments.
|
||||||
|
*/
|
||||||
|
List<BaseCommentDTO> replaceUrl(@NonNull String oldUrl, @NonNull String newUrl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,4 +245,14 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
List<POST> updateStatusByIds(@NonNull List<Integer> ids, @NonNull PostStatus status);
|
List<POST> updateStatusByIds(@NonNull List<Integer> ids, @NonNull PostStatus status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace post blog url in batch.
|
||||||
|
*
|
||||||
|
* @param oldUrl old blog url.
|
||||||
|
* @param newUrl new blog url.
|
||||||
|
* @return replaced posts.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
List<BasePostDetailDTO> replaceUrl(@NonNull String oldUrl, @NonNull String newUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,6 +183,18 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
||||||
return attachmentRepository.findAllType();
|
return attachmentRepository.findAllType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Attachment> replaceUrl(String oldUrl, String newUrl) {
|
||||||
|
List<Attachment> attachments = listAll();
|
||||||
|
List<Attachment> replaced = new ArrayList<>();
|
||||||
|
attachments.forEach(attachment -> {
|
||||||
|
attachment.setPath(attachment.getPath().replaceAll(oldUrl, newUrl));
|
||||||
|
attachment.setThumbPath(attachment.getThumbPath().replaceAll(oldUrl, newUrl));
|
||||||
|
replaced.add(attachment);
|
||||||
|
});
|
||||||
|
return updateInBatch(replaced);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Attachment create(Attachment attachment) {
|
public Attachment create(Attachment attachment) {
|
||||||
Assert.notNull(attachment, "Attachment must not be null");
|
Assert.notNull(attachment, "Attachment must not be null");
|
||||||
|
|
|
@ -584,6 +584,18 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
||||||
return commentPage;
|
return commentPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BaseCommentDTO> replaceUrl(String oldUrl, String newUrl) {
|
||||||
|
List<COMMENT> comments = listAll();
|
||||||
|
List<COMMENT> replaced = new ArrayList<>();
|
||||||
|
comments.forEach(comment -> {
|
||||||
|
comment.setAuthorUrl(comment.getAuthorUrl().replaceAll(oldUrl, newUrl));
|
||||||
|
replaced.add(comment);
|
||||||
|
});
|
||||||
|
List<COMMENT> updated = updateInBatch(replaced);
|
||||||
|
return convertTo(updated);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get children comments recursively.
|
* Get children comments recursively.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,10 +29,7 @@ import run.halo.app.utils.HaloUtils;
|
||||||
import run.halo.app.utils.MarkdownUtils;
|
import run.halo.app.utils.MarkdownUtils;
|
||||||
import run.halo.app.utils.ServiceUtils;
|
import run.halo.app.utils.ServiceUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -395,6 +392,20 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BasePostDetailDTO> replaceUrl(String oldUrl, String newUrl) {
|
||||||
|
List<POST> posts = listAll();
|
||||||
|
List<POST> replaced = new ArrayList<>();
|
||||||
|
posts.forEach(post -> {
|
||||||
|
post.setThumbnail(post.getThumbnail().replaceAll(oldUrl, newUrl));
|
||||||
|
post.setOriginalContent(post.getOriginalContent().replaceAll(oldUrl, newUrl));
|
||||||
|
post.setFormatContent(post.getFormatContent().replaceAll(oldUrl, newUrl));
|
||||||
|
replaced.add(post);
|
||||||
|
});
|
||||||
|
List<POST> updated = updateInBatch(replaced);
|
||||||
|
return updated.stream().map(this::convertToDetail).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public POST create(POST post) {
|
public POST create(POST post) {
|
||||||
// Check title
|
// Check title
|
||||||
|
|
|
@ -36,6 +36,7 @@ import run.halo.app.utils.ValidationUtils;
|
||||||
|
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OptionService implementation class
|
* OptionService implementation class
|
||||||
|
@ -460,6 +461,18 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OptionDTO> replaceUrl(String oldUrl, String newUrl) {
|
||||||
|
List<Option> options = listAll();
|
||||||
|
List<Option> replaced = new ArrayList<>();
|
||||||
|
options.forEach(option -> {
|
||||||
|
option.setValue(option.getValue().replaceAll(oldUrl, newUrl));
|
||||||
|
replaced.add(option);
|
||||||
|
});
|
||||||
|
List<Option> updated = updateInBatch(replaced);
|
||||||
|
return updated.stream().map(this::convertToDto).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OptionSimpleDTO convertToDto(Option option) {
|
public OptionSimpleDTO convertToDto(Option option) {
|
||||||
Assert.notNull(option, "Option must not be null");
|
Assert.notNull(option, "Option must not be null");
|
||||||
|
|
|
@ -19,10 +19,7 @@ import run.halo.app.service.base.AbstractCrudService;
|
||||||
import run.halo.app.utils.ServiceUtils;
|
import run.halo.app.utils.ServiceUtils;
|
||||||
|
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import java.util.LinkedList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,6 +111,19 @@ public class PhotoServiceImpl extends AbstractCrudService<Photo, Integer> implem
|
||||||
return photoRepository.findAllTeams();
|
return photoRepository.findAllTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PhotoDTO> replaceUrl(String oldUrl, String newUrl) {
|
||||||
|
List<Photo> photos = listAll();
|
||||||
|
List<Photo> replaced = new ArrayList<>();
|
||||||
|
photos.forEach(photo -> {
|
||||||
|
photo.setThumbnail(photo.getThumbnail().replace(oldUrl, newUrl));
|
||||||
|
photo.setUrl(photo.getUrl().replaceAll(oldUrl, newUrl));
|
||||||
|
replaced.add(photo);
|
||||||
|
});
|
||||||
|
List<Photo> updated = updateInBatch(replaced);
|
||||||
|
return updated.stream().map(photo -> (PhotoDTO) new PhotoDTO().convertFrom(photo)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Specification<Photo> buildSpecByQuery(@NonNull PhotoQuery photoQuery) {
|
private Specification<Photo> buildSpecByQuery(@NonNull PhotoQuery photoQuery) {
|
||||||
Assert.notNull(photoQuery, "Photo query must not be null");
|
Assert.notNull(photoQuery, "Photo query must not be null");
|
||||||
|
|
|
@ -160,6 +160,17 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ThemeSetting> replaceUrl(String oldUrl, String newUrl) {
|
||||||
|
List<ThemeSetting> themeSettings = listAll();
|
||||||
|
List<ThemeSetting> replaced = new ArrayList<>();
|
||||||
|
themeSettings.forEach(themeSetting -> {
|
||||||
|
themeSetting.setValue(themeSetting.getValue().replaceAll(oldUrl, newUrl));
|
||||||
|
replaced.add(themeSetting);
|
||||||
|
});
|
||||||
|
return updateInBatch(replaced);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets config item map. (key: item name, value: item)
|
* Gets config item map. (key: item name, value: item)
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue