mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
feat: attachments support
This commit is contained in:
@@ -101,15 +101,15 @@ define('forum/topic/events', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onPostEdited(data) {
|
function onPostEdited(data) {
|
||||||
if (!data || !data.post || parseInt(data.post.tid, 10) !== parseInt(ajaxify.data.tid, 10)) {
|
if (!data || !data.post || String(data.post.tid) !== String(ajaxify.data.tid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const editedPostEl = components.get('post/content', data.post.pid).filter(function (index, el) {
|
const editedPostEl = components.get('post/content', data.post.pid).filter(function (index, el) {
|
||||||
return parseInt($(el).closest('[data-pid]').attr('data-pid'), 10) === parseInt(data.post.pid, 10);
|
return String($(el).closest('[data-pid]').attr('data-pid')) === String(data.post.pid);
|
||||||
});
|
});
|
||||||
const postContainer = $(`[data-pid="${data.post.pid}"]`);
|
const postContainer = $(`[data-pid="${data.post.pid}"]`);
|
||||||
const editorEl = postContainer.find('[component="post/editor"]').filter(function (index, el) {
|
const editorEl = postContainer.find('[component="post/editor"]').filter(function (index, el) {
|
||||||
return parseInt($(el).closest('[data-pid]').attr('data-pid'), 10) === parseInt(data.post.pid, 10);
|
return String($(el).closest('[data-pid]').attr('data-pid')) === String(data.post.pid);
|
||||||
});
|
});
|
||||||
const topicTitle = components.get('topic/title');
|
const topicTitle = components.get('topic/title');
|
||||||
const navbarTitle = components.get('navbar/title').find('span');
|
const navbarTitle = components.get('navbar/title').find('span');
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ Mocks.post = async (objects) => {
|
|||||||
inReplyTo: toPid,
|
inReplyTo: toPid,
|
||||||
to,
|
to,
|
||||||
cc,
|
cc,
|
||||||
|
attachment,
|
||||||
} = object;
|
} = object;
|
||||||
|
|
||||||
const timestamp = new Date(published).getTime();
|
const timestamp = new Date(published).getTime();
|
||||||
@@ -108,7 +109,7 @@ Mocks.post = async (objects) => {
|
|||||||
|
|
||||||
edited,
|
edited,
|
||||||
editor: edited ? uid : undefined,
|
editor: edited ? uid : undefined,
|
||||||
_activitypub: { to, cc },
|
_activitypub: { to, cc, attachment },
|
||||||
};
|
};
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
@@ -41,8 +42,9 @@ Notes.assert = async (uid, input, options = {}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse ActivityPub-specific data
|
// Parse ActivityPub-specific data
|
||||||
const { to, cc } = postData._activitypub;
|
const { to, cc, attachment } = postData._activitypub;
|
||||||
await Notes.updateLocalRecipients(id, { to, cc });
|
await Notes.updateLocalRecipients(id, { to, cc });
|
||||||
|
await Notes.saveAttachments(id, attachment);
|
||||||
|
|
||||||
const hash = { ...postData };
|
const hash = { ...postData };
|
||||||
delete hash._activitypub;
|
delete hash._activitypub;
|
||||||
@@ -83,6 +85,35 @@ Notes.updateLocalRecipients = async (id, { to, cc }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Notes.saveAttachments = async (id, attachments) => {
|
||||||
|
const bulkOps = {
|
||||||
|
hash: [],
|
||||||
|
zset: {
|
||||||
|
score: [],
|
||||||
|
value: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
attachments.filter(Boolean).map(({ mediaType, url, name, width, height }, idx) => {
|
||||||
|
if (!url) { // only required property
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hash = crypto.createHash('sha256').update(url).digest('hex');
|
||||||
|
const key = `attachment:${hash}`;
|
||||||
|
console.log('attachment key is', key);
|
||||||
|
|
||||||
|
bulkOps.hash.push([key, { mediaType, url, name, width, height }]);
|
||||||
|
bulkOps.zset.score.push(idx);
|
||||||
|
bulkOps.zset.value.push(hash);
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
db.setObjectBulk(bulkOps.hash),
|
||||||
|
db.sortedSetAdd(`post:${id}:attachments`, bulkOps.zset.score, bulkOps.zset.value),
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
Notes.getParentChain = async (uid, input) => {
|
Notes.getParentChain = async (uid, input) => {
|
||||||
// Traverse upwards via `inReplyTo` until you find the root-level Note
|
// Traverse upwards via `inReplyTo` until you find the root-level Note
|
||||||
const id = activitypub.helpers.isUri(input) ? input : input.id;
|
const id = activitypub.helpers.isUri(input) ? input : input.id;
|
||||||
|
|||||||
8
src/cache/lru.js
vendored
8
src/cache/lru.js
vendored
@@ -57,6 +57,14 @@ module.exports = function (opts) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cache.has = function (key) {
|
||||||
|
if (!cache.enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lruCache.has(key);
|
||||||
|
};
|
||||||
|
|
||||||
cache.set = function (key, value, ttl) {
|
cache.set = function (key, value, ttl) {
|
||||||
if (!cache.enabled) {
|
if (!cache.enabled) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -61,15 +61,12 @@ module.exports = function (Posts) {
|
|||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activitypub.helpers.isUri(postData.pid) || postData.hasOwnProperty('sourceContent')) {
|
|
||||||
({ postData } = await plugins.hooks.fire('filter:parse.post', { postData }));
|
({ postData } = await plugins.hooks.fire('filter:parse.post', { postData }));
|
||||||
} else {
|
|
||||||
postData.content = await Posts.sanitize(postData.content);
|
|
||||||
}
|
|
||||||
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(pid, postData.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return postData;
|
return postData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user