Search in sources :

Example 6 with SheetDetailVO

use of run.halo.app.model.vo.SheetDetailVO in project halo by ruibaby.

the class SheetController method getBy.

@GetMapping("{sheetId:\\d+}")
@ApiOperation("Gets a sheet")
public SheetDetailVO getBy(@PathVariable("sheetId") Integer sheetId, @RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
    Sheet sheet = sheetService.getById(sheetId);
    SheetDetailVO sheetDetailVO = sheetRenderAssembler.convertToDetailVo(sheet);
    if (formatDisabled) {
        // Clear the format content
        sheetDetailVO.setContent(null);
    }
    if (sourceDisabled) {
        // Clear the original content
        sheetDetailVO.setOriginalContent(null);
    }
    sheetService.publishVisitEvent(sheetDetailVO.getId());
    return sheetDetailVO;
}
Also used : SheetDetailVO(run.halo.app.model.vo.SheetDetailVO) Sheet(run.halo.app.model.entity.Sheet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with SheetDetailVO

use of run.halo.app.model.vo.SheetDetailVO in project halo by ruibaby.

the class SheetController method getBy.

@GetMapping("/slug")
@ApiOperation("Gets a sheet by slug")
public SheetDetailVO getBy(@RequestParam("slug") String slug, @RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
    Sheet sheet = sheetService.getBySlug(slug);
    SheetDetailVO sheetDetailVO = sheetRenderAssembler.convertToDetailVo(sheet);
    if (formatDisabled) {
        // Clear the format content
        sheetDetailVO.setContent(null);
    }
    if (sourceDisabled) {
        // Clear the original content
        sheetDetailVO.setOriginalContent(null);
    }
    sheetService.publishVisitEvent(sheetDetailVO.getId());
    return sheetDetailVO;
}
Also used : SheetDetailVO(run.halo.app.model.vo.SheetDetailVO) Sheet(run.halo.app.model.entity.Sheet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with SheetDetailVO

use of run.halo.app.model.vo.SheetDetailVO in project halo by halo-dev.

the class SheetAssembler method convertTo.

@NonNull
public SheetDetailVO convertTo(@NonNull Sheet sheet, List<SheetMeta> metas) {
    Assert.notNull(sheet, "Sheet must not be null");
    // Convert to base detail vo
    SheetDetailVO sheetDetailVO = new SheetDetailVO().convertFrom(sheet);
    Set<Long> metaIds = ServiceUtils.fetchProperty(metas, SheetMeta::getId);
    // Get sheet meta ids
    sheetDetailVO.setMetaIds(metaIds);
    sheetDetailVO.setMetas(sheetMetaService.convertTo(metas));
    generateAndSetSummaryIfAbsent(sheet, sheetDetailVO);
    sheetDetailVO.setCommentCount(sheetCommentService.countByStatusAndPostId(CommentStatus.PUBLISHED, sheet.getId()));
    sheetDetailVO.setFullPath(buildFullPath(sheet));
    PatchedContent sheetContent = sheet.getContent();
    sheetDetailVO.setContent(sheetContent.getContent());
    sheetDetailVO.setOriginalContent(sheetContent.getOriginalContent());
    // Sheet currently drafting in process
    Boolean inProgress = contentService.draftingInProgress(sheet.getId());
    sheetDetailVO.setInProgress(inProgress);
    return sheetDetailVO;
}
Also used : SheetMeta(run.halo.app.model.entity.SheetMeta) SheetDetailVO(run.halo.app.model.vo.SheetDetailVO) PatchedContent(run.halo.app.model.entity.Content.PatchedContent) NonNull(org.springframework.lang.NonNull)

Example 9 with SheetDetailVO

use of run.halo.app.model.vo.SheetDetailVO in project halo by halo-dev.

the class SheetModel method content.

/**
 * Sheet content.
 *
 * @param sheet sheet
 * @param token token
 * @param model model
 * @return template name
 */
public String content(Sheet sheet, String token, Model model) {
    SheetDetailVO sheetDetailVo;
    if (StringUtils.isEmpty(token)) {
        sheet = sheetService.getBy(PostStatus.PUBLISHED, sheet.getSlug());
        sheetDetailVo = sheetRenderAssembler.convertToDetailVo(sheet);
    } else {
        // verify token
        String cachedToken = cacheStore.getAny(token, String.class).orElseThrow(() -> new ForbiddenException("您没有该页面的访问权限"));
        if (!cachedToken.equals(token)) {
            throw new ForbiddenException("您没有该页面的访问权限");
        }
        sheetDetailVo = sheetRenderAssembler.convertToPreviewDetailVo(sheet);
    }
    sheetService.publishVisitEvent(sheet.getId());
    List<SheetMeta> metas = sheetMetaService.listBy(sheet.getId());
    // Generate meta keywords.
    if (StringUtils.isNotEmpty(sheet.getMetaKeywords())) {
        model.addAttribute("meta_keywords", sheet.getMetaKeywords());
    } else {
        model.addAttribute("meta_keywords", optionService.getSeoKeywords());
    }
    // Generate meta description.
    if (StringUtils.isNotEmpty(sheet.getMetaDescription())) {
        model.addAttribute("meta_description", sheet.getMetaDescription());
    } else {
        model.addAttribute("meta_description", sheetService.generateDescription(sheet.getContent().getContent()));
    }
    // sheet and post all can use
    model.addAttribute("sheet", sheetDetailVo);
    model.addAttribute("post", sheetDetailVo);
    model.addAttribute("is_sheet", true);
    model.addAttribute("metas", sheetMetaService.convertToMap(metas));
    if (themeService.templateExists(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate() + HaloConst.SUFFIX_FTL)) {
        return themeService.render(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate());
    }
    return themeService.render("sheet");
}
Also used : ForbiddenException(run.halo.app.exception.ForbiddenException) SheetMeta(run.halo.app.model.entity.SheetMeta) SheetDetailVO(run.halo.app.model.vo.SheetDetailVO)

Example 10 with SheetDetailVO

use of run.halo.app.model.vo.SheetDetailVO in project halo by halo-dev.

the class SheetController method getBy.

@GetMapping("{sheetId:\\d+}")
@ApiOperation("Gets a sheet")
public SheetDetailVO getBy(@PathVariable("sheetId") Integer sheetId, @RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
    Sheet sheet = sheetService.getById(sheetId);
    SheetDetailVO sheetDetailVO = sheetRenderAssembler.convertToDetailVo(sheet);
    if (formatDisabled) {
        // Clear the format content
        sheetDetailVO.setContent(null);
    }
    if (sourceDisabled) {
        // Clear the original content
        sheetDetailVO.setOriginalContent(null);
    }
    sheetService.publishVisitEvent(sheetDetailVO.getId());
    return sheetDetailVO;
}
Also used : SheetDetailVO(run.halo.app.model.vo.SheetDetailVO) Sheet(run.halo.app.model.entity.Sheet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SheetDetailVO (run.halo.app.model.vo.SheetDetailVO)12 ApiOperation (io.swagger.annotations.ApiOperation)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 SheetMeta (run.halo.app.model.entity.SheetMeta)6 Sheet (run.halo.app.model.entity.Sheet)4 NonNull (org.springframework.lang.NonNull)3 ForbiddenException (run.halo.app.exception.ForbiddenException)3 PatchedContent (run.halo.app.model.entity.Content.PatchedContent)2