mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-28 01:21:13 +01:00
feat: passing in types to parsePost for more specific handling by plugins
This commit is contained in:
@@ -256,6 +256,12 @@ Mocks.note = async (post) => {
|
|||||||
cc.add(followersUrl);
|
cc.add(followersUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const content = await posts.getPostField(post.pid, 'content');
|
||||||
|
const { postData: parsed } = await plugins.hooks.fire('filter:parse.post', {
|
||||||
|
postData: { content },
|
||||||
|
type: 'activitypub.note',
|
||||||
|
});
|
||||||
|
post.content = parsed.content;
|
||||||
post.content = posts.relativeToAbsolute(post.content, posts.urlRegex);
|
post.content = posts.relativeToAbsolute(post.content, posts.urlRegex);
|
||||||
post.content = posts.relativeToAbsolute(post.content, posts.imgRegex);
|
post.content = posts.relativeToAbsolute(post.content, posts.imgRegex);
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ let sanitizeConfig = {
|
|||||||
...sanitize.defaults.allowedClasses,
|
...sanitize.defaults.allowedClasses,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const allowedTypes = new Set(['default', 'plaintext', 'activitypub.note', 'activitypub.article']);
|
||||||
|
|
||||||
module.exports = function (Posts) {
|
module.exports = function (Posts) {
|
||||||
Posts.urlRegex = {
|
Posts.urlRegex = {
|
||||||
@@ -47,28 +48,38 @@ module.exports = function (Posts) {
|
|||||||
length: 5,
|
length: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
Posts.parsePost = async function (postData) {
|
Posts.parsePost = async function (postData, type) {
|
||||||
if (!postData) {
|
if (!postData) {
|
||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
|
if (!type || !allowedTypes.has(type)) {
|
||||||
|
type = 'default';
|
||||||
|
}
|
||||||
postData.content = String(postData.sourceContent || postData.content || '');
|
postData.content = String(postData.sourceContent || postData.content || '');
|
||||||
const cache = require('./cache');
|
const cache = require('./cache');
|
||||||
const pid = String(postData.pid);
|
const cacheKey = `${String(postData.pid)}|${type}`;
|
||||||
const cachedContent = cache.get(pid);
|
const cachedContent = cache.get(cacheKey);
|
||||||
if (postData.pid && cachedContent !== undefined) {
|
if (postData.pid && cachedContent !== undefined) {
|
||||||
postData.content = cachedContent;
|
postData.content = cachedContent;
|
||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
|
|
||||||
({ postData } = await plugins.hooks.fire('filter:parse.post', { postData }));
|
({ postData } = await plugins.hooks.fire('filter:parse.post', { postData, type }));
|
||||||
postData.content = translator.escape(postData.content);
|
postData.content = translator.escape(postData.content);
|
||||||
if (postData.pid) {
|
if (postData.pid) {
|
||||||
cache.set(pid, postData.content);
|
cache.set(cacheKey, postData.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return postData;
|
return postData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Posts.clearCachedPost = function (pid) {
|
||||||
|
const cache = require('./cache');
|
||||||
|
allowedTypes.forEach((type) => {
|
||||||
|
cache.del(`${String(pid)}|${type}`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Posts.parseSignature = async function (userData, uid) {
|
Posts.parseSignature = async function (userData, uid) {
|
||||||
userData.signature = sanitizeSignature(userData.signature || '');
|
userData.signature = sanitizeSignature(userData.signature || '');
|
||||||
return await plugins.hooks.fire('filter:parse.signature', { userData: userData, uid: uid });
|
return await plugins.hooks.fire('filter:parse.signature', { userData: userData, uid: uid });
|
||||||
|
|||||||
Reference in New Issue
Block a user