gpt4 book ai didi

node.js - Pencilblue - 用于获取所有呈现文章的列表的 Web 服务

转载 作者:太空宇宙 更新时间:2023-11-04 02:23:22 25 4
gpt4 key购买 nike

我想知道是否有一种方法可以获取所有已呈现的文章 HTML 的列表。我希望媒体图像文件呈现为 <img>而不是 ^media_display_55aabd2ac89b5e44211ccf86/position:none^.

我为此构建了一个 Controller :

module.exports = function BookApiControllerModule(pb) {

//PB dependencies
var util = pb.util;
var BaseApiController = pb.BaseApiController;
var PluginService = pb.PluginService;
var BaseObjectService = pb.BaseObjectService;
var BookService = PluginService.getService('BookService', 'articles-api');
var ArticleService = pb.ArticleService;
var TYPE = 'article';

//Creating an inline service.
function DndService(context) {
if (!util.isObject(context)) {
context = {};
}
context.type = TYPE;
DndService.super_.call(this, context);
}

util.inherits(DndService, BaseObjectService);

DndService.getName = function () {
return "DndService";
};

DndService.init = function (cb) {
pb.log.debug("DndService: Initialized");
cb(null, true);
};

DndService.beforeSave = function (context, cb) {
cb(null);
};

DndService.afterSave = function (context, cb) {
cb(null);
};

DndService.beforeDelete = function (context, cb) {
cb(null);
};

DndService.afterDelete = function (context, cb) {
cb(null);
};

DndService.validate = function (context, cb) {
cb(null);
};

DndService.merge = function (context, cb) {
cb(null);
};

DndService.format = function (context, cb) {
cb(null);
};

DndService.getAll = function (ctx, cb) {
ctx.data = [{message: "ASDF"}];
cb(null);
};

BaseObjectService.on(TYPE + '.' + BaseObjectService.GET_ALL, DndService.getAll);
//Done with the inline service

function BookApiController() {
this.service = new DndService();
};
util.inherits(BookApiController, pb.BaseApiController);

BookApiController.getRoutes = function (cb) {
var routes = [
{
method: 'get',
path: "/api/articles",
handler: "getAll",
content_type: 'application/json'
}
];
cb(null, routes);
};

//exports
return BookApiController;
};

它返回以下内容:

{
"data": [
{
"_id": "55c2a7650668d47274859fc8",
"author": "55aaa75a3bb0fbbd2056c76d",
"publish_date": "2015-08-05T22:45:00.000Z",
"meta_keywords": [
""
],
"article_media": [
"55aabd2ac89b5e44211ccf86",
"55c2a86d0668d47274859fd1"
],
"article_sections": [],
"article_topics": [],
"headline": "wefghj",
"subheading": "khgvhjvgjvgh",
"url": "blahhhhh",
"draft": 0,
"article_layout": "^media_display_55aabd2ac89b5e44211ccf86/position:none^^media_display_55c2a86d0668d47274859fd1/position:none^",
"object_type": "article",
"created": "2015-08-06T00:16:37.889Z",
"last_modified": "2015-08-06T00:22:46.825Z",
"id": "55c2a7650668d47274859fc8",
"template": "pencilblue|index"
}
],
"total": 1,
"count": 1,
"offset": 0,
"limit": 1000
}

最佳答案

您需要在返回媒体之前“渲染”媒体,否则您只能获得图像 ID。看看http://pencilblue.github.io/classes/MediaService.html#method_render (或 PB 0.6.0 的 http://pencilblue.github.io/classes/ImageMediaRenderer.html#method_render)。

关于node.js - Pencilblue - 用于获取所有呈现文章的列表的 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31844976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com