Node.js based forum software built for the modern web
feat: passing in types to parsePost for more specific handling by plugins
Julian Lam8cf9617630b0
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.jsindex 55619e596c..9feafc6b0c 100644--- a/src/activitypub/mocks.js+++ b/src/activitypub/mocks.js@@ -256,6 +256,12 @@ Mocks.note = async (post) => {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.imgRegex);diff --git a/src/posts/parse.js b/src/posts/parse.jsindex fa89b0fdd6..62cc76b9c8 100644--- a/src/posts/parse.js+++ b/src/posts/parse.js@@ -35,6 +35,7 @@ let sanitizeConfig = {...sanitize.defaults.allowedClasses,},};+const allowedTypes = new Set(['default', 'plaintext', 'activitypub.note', 'activitypub.article']);module.exports = function (Posts) {Posts.urlRegex = {@@ -47,28 +48,38 @@ module.exports = function (Posts) {length: 5,};- Posts.parsePost = async function (postData) {+ Posts.parsePost = async function (postData, type) {if (!postData) {return postData;}+ if (!type || !allowedTypes.has(type)) {+ type = 'default';+ }postData.content = String(postData.sourceContent || postData.content || '');const cache = require('./cache');- const pid = String(postData.pid);- const cachedContent = cache.get(pid);+ const cacheKey = `${String(postData.pid)}|${type}`;+ const cachedContent = cache.get(cacheKey);if (postData.pid && cachedContent !== undefined) {postData.content = cachedContent;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);if (postData.pid) {- cache.set(pid, postData.content);+ cache.set(cacheKey, postData.content);}return postData;};+ Posts.clearCachedPost = function (pid) {+ const cache = require('./cache');+ allowedTypes.forEach((type) => {+ cache.del(`${String(pid)}|${type}`);+ });+ };+Posts.parseSignature = async function (userData, uid) {userData.signature = sanitizeSignature(userData.signature || '');return await plugins.hooks.fire('filter:parse.signature', { userData: userData, uid: uid });