Skip to content

Node.js based forum software built for the modern web

Merge branch 'develop' into activitypub

Barış Soner Uşaklı00c70ce7b054
diff --cc src/meta/index.js
index 04f1851d34,cb4f8bfdcd..73e77b55e0
--- a/src/meta/index.js
+++ b/src/meta/index.js
@@@ -24,23 -24,28 +24,31 @@@ Meta.templates = require('./templates')
Meta.blacklist = require('./blacklist');
Meta.languages = require('./languages');
+ const user = require('../user');
+ const groups = require('../groups');
++const categories = require('../categories');
+
-/* Assorted */
-Meta.userOrGroupExists = async function (slug) {
+Meta.slugTaken = async function (slug) {
- if (!slug) {
+ const isArray = Array.isArray(slug);
+ if ((isArray && slug.some(slug => !slug)) || (!isArray && !slug)) {
throw new Error('[[error:invalid-data]]');
}
- const [user, groups, categories] = [require('../user'), require('../groups'), require('../categories')];
- slug = slugify(slug);
+ slug = isArray ? slug.map(s => slugify(s, false)) : slugify(slug);
- const exists = await Promise.all([
- const [userExists, groupExists] = await Promise.all([
++ const [userExists, groupExists, categoryExists] = await Promise.all([
user.existsBySlug(slug),
groups.existsBySlug(slug),
+ categories.existsByHandle(slug),
]);
- return exists.some(Boolean);
+
+ return isArray ?
- slug.map((s, i) => userExists[i] || groupExists[i]) :
- (userExists || groupExists);
++ slug.map((s, i) => userExists[i] || groupExists[i] || categoryExists[i]) :
++ (userExists || groupExists || categoryExists);
};
+
+Meta.userOrGroupExists = Meta.slugTaken; // backwards compatiblity
+
if (nconf.get('isPrimary')) {
pubsub.on('meta:restart', (data) => {
if (data.hostname !== os.hostname()) {
diff --cc src/posts/parse.js
index b8ce1dd3db,4740b6d92d..25e14cc3fc
--- a/src/posts/parse.js
+++ b/src/posts/parse.js
@@@ -49,13 -49,10 +50,15 @@@ module.exports = function (Posts)
if (!postData) {
return postData;
}
- postData.content = String(postData.content || '');
++
+ if (!type || !allowedTypes.has(type)) {
+ type = 'default';
+ }
+ postData.content = String(postData.sourceContent || postData.content || '');
- const cache = require('./cache');
+ const cache = postCache.getOrCreate();
- 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;