mirror of https://github.com/halo-dev/halo
Fix visit event ingore
parent
bc411484d6
commit
8dac1a176a
|
@ -13,7 +13,9 @@ import org.springframework.ui.Model;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import run.halo.app.cache.StringCacheStore;
|
||||
import run.halo.app.cache.lock.CacheLock;
|
||||
import run.halo.app.exception.BadRequestException;
|
||||
import run.halo.app.exception.ForbiddenException;
|
||||
import run.halo.app.exception.NotFoundException;
|
||||
import run.halo.app.model.entity.Category;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.entity.PostMeta;
|
||||
|
@ -128,7 +130,7 @@ public class ContentArchiveController {
|
|||
Model model) {
|
||||
Post post;
|
||||
if (preview) {
|
||||
post = postService.getBy(PostStatus.DRAFT, url);
|
||||
post = postService.getByUrl(url);
|
||||
} else if (intimate) {
|
||||
post = postService.getBy(PostStatus.INTIMATE, url);
|
||||
} else {
|
||||
|
@ -141,10 +143,10 @@ public class ContentArchiveController {
|
|||
post.setFormatContent(MarkdownUtils.renderHtml(post.getOriginalContent()));
|
||||
|
||||
// verify token
|
||||
String cachedToken = cacheStore.getAny("preview-post-token-" + post.getId(), String.class).orElseThrow(() -> new ForbiddenException("该文章的预览链接不存在或已过期"));
|
||||
String cachedToken = cacheStore.getAny("preview-post-token-" + post.getId(), String.class).orElseThrow(() -> new NotFoundException("该文章的预览链接不存在或已过期"));
|
||||
|
||||
if (!cachedToken.equals(token)) {
|
||||
throw new ForbiddenException("该文章的预览链接不存在或已过期");
|
||||
throw new BadRequestException("预览 Token 错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,10 +154,16 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
public Post getBy(PostStatus status, String url) {
|
||||
Post post = super.getBy(status, url);
|
||||
|
||||
if (PostStatus.PUBLISHED.equals(status)) {
|
||||
// Log it
|
||||
eventPublisher.publishEvent(new PostVisitEvent(this, post.getId()));
|
||||
}
|
||||
fireVisitEvent(post.getId());
|
||||
|
||||
return post;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Post getByUrl(String url) {
|
||||
Post post = super.getByUrl(url);
|
||||
|
||||
fireVisitEvent(post.getId());
|
||||
|
||||
return post;
|
||||
}
|
||||
|
@ -580,4 +586,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
// Convert to post detail vo
|
||||
return convertTo(post, tags, categories, postMetaList);
|
||||
}
|
||||
|
||||
private void fireVisitEvent(@NonNull Integer postId) {
|
||||
eventPublisher.publishEvent(new PostVisitEvent(this, postId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,17 +64,6 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
@Override
|
||||
public Sheet createBy(Sheet sheet, boolean autoSave) {
|
||||
Sheet createdSheet = createOrUpdateBy(sheet);
|
||||
if (!autoSave) {
|
||||
// Log the creation
|
||||
LogEvent logEvent = new LogEvent(this, createdSheet.getId().toString(), LogType.SHEET_PUBLISHED, createdSheet.getTitle());
|
||||
eventPublisher.publishEvent(logEvent);
|
||||
}
|
||||
return createdSheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet createBy(Sheet sheet, Set<SheetMeta> sheetMetas, boolean autoSave) {
|
||||
Sheet createdSheet = createOrUpdateBy(sheet);
|
||||
|
||||
// Create sheet meta data
|
||||
List<SheetMeta> sheetMetaList = sheetMetaService.createOrUpdateByPostId(sheet.getId(), sheetMetas);
|
||||
|
@ -91,18 +80,6 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
@Override
|
||||
public Sheet updateBy(Sheet sheet, boolean autoSave) {
|
||||
Sheet updatedSheet = createOrUpdateBy(sheet);
|
||||
if (!autoSave) {
|
||||
// Log the creation
|
||||
LogEvent logEvent = new LogEvent(this, updatedSheet.getId().toString(), LogType.SHEET_EDITED, updatedSheet.getTitle());
|
||||
eventPublisher.publishEvent(logEvent);
|
||||
}
|
||||
return updatedSheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet updateBy(Sheet sheet, Set<SheetMeta> sheetMetas, boolean autoSave) {
|
||||
|
||||
Sheet updatedSheet = createOrUpdateBy(sheet);
|
||||
|
||||
// Create sheet meta data
|
||||
List<SheetMeta> sheetMetaList = sheetMetaService.createOrUpdateByPostId(updatedSheet.getId(), sheetMetas);
|
||||
|
@ -127,7 +104,11 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
public Sheet getByUrl(String url) {
|
||||
Assert.hasText(url, "Url must not be blank");
|
||||
|
||||
return sheetRepository.getByUrl(url).orElseThrow(() -> new NotFoundException("查询不到该页面的信息").setErrorData(url));
|
||||
Sheet sheet = sheetRepository.getByUrl(url).orElseThrow(() -> new NotFoundException("查询不到该页面的信息").setErrorData(url));
|
||||
|
||||
fireVisitEvent(sheet.getId());
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,10 +120,7 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
|
||||
Sheet sheet = postOptional.orElseThrow(() -> new NotFoundException("查询不到该页面的信息").setErrorData(url));
|
||||
|
||||
if (PostStatus.PUBLISHED.equals(status)) {
|
||||
// Log it
|
||||
eventPublisher.publishEvent(new SheetVisitEvent(this, sheet.getId()));
|
||||
}
|
||||
fireVisitEvent(sheet.getId());
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
@ -249,6 +227,10 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
});
|
||||
}
|
||||
|
||||
private void fireVisitEvent(@NonNull Integer sheetId) {
|
||||
eventPublisher.publishEvent(new SheetVisitEvent(this, sheetId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SheetDetailVO convertToDetailVo(Sheet sheet) {
|
||||
// List sheetMetas
|
||||
|
|
Loading…
Reference in New Issue