fix: don't count internal links towards link count when restricting new users from posting links

This commit is contained in:
Julian Lam
2023-10-26 11:00:43 -04:00
parent 4693f8bf1e
commit 022fa0e75f

View File

@@ -96,9 +96,16 @@ module.exports = function (Posts) {
if (!isPrivileged && reputation < meta.config['min:rep:post-links']) { if (!isPrivileged && reputation < meta.config['min:rep:post-links']) {
const parsed = await plugins.hooks.fire('filter:parse.raw', String(content)); const parsed = await plugins.hooks.fire('filter:parse.raw', String(content));
if (parsed.match(/<a[^>]*>([^<]+)<\/a>/g)) { const matches = parsed.matchAll(/<a[^>]*href="([^"]+)"[^>]*>/g);
return false; let external = 0;
for (const [, href] of matches) {
const internal = utils.isInternalURI(new URL(href, nconf.get('url')), new URL(nconf.get('url')), nconf.get('relative_path'));
if (!internal) {
external += 1;
}
} }
return external === 0;
} }
return true; return true;
}; };