Search in sources :

Example 1 with SheetDetailVO

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

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 2 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 3 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 4 with SheetDetailVO

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

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 5 with SheetDetailVO

use of run.halo.app.model.vo.SheetDetailVO in project halo-plugin-experimental by guqing.

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) {
    SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheetService.getBySlug(slug));
    if (formatDisabled) {
        // Clear the format content
        sheetDetailVO.setFormatContent(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) 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