mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
fix: adjust Peertube-specific handling to shove mp4 into post attachments, #13324
This commit is contained in:
@@ -42,7 +42,7 @@ const sanitizeConfig = {
|
|||||||
|
|
||||||
Mocks._normalize = async (object) => {
|
Mocks._normalize = async (object) => {
|
||||||
// Normalized incoming AP objects into expected types for easier mocking
|
// Normalized incoming AP objects into expected types for easier mocking
|
||||||
let { attributedTo, url, image, content, source } = object;
|
let { type, attributedTo, url, image, content, source, attachment } = object;
|
||||||
|
|
||||||
switch (true) { // non-string attributedTo handling
|
switch (true) { // non-string attributedTo handling
|
||||||
case Array.isArray(attributedTo): {
|
case Array.isArray(attributedTo): {
|
||||||
@@ -102,6 +102,30 @@ Mocks._normalize = async (object) => {
|
|||||||
|
|
||||||
if (url) { // Handle url array
|
if (url) { // Handle url array
|
||||||
if (Array.isArray(url)) {
|
if (Array.isArray(url)) {
|
||||||
|
// Special handling for Video type (from PeerTube specifically)
|
||||||
|
if (type === 'Video') {
|
||||||
|
const stream = url.reduce((memo, { type, mediaType, tag }) => {
|
||||||
|
if (!memo) {
|
||||||
|
if (type === 'Link' && mediaType === 'application/x-mpegURL') {
|
||||||
|
memo = tag.reduce((memo, { type, mediaType, href }) => {
|
||||||
|
if (!memo && (type === 'Link' && mediaType === 'video/mp4')) {
|
||||||
|
memo = { type, mediaType, href };
|
||||||
|
}
|
||||||
|
|
||||||
|
return memo;
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return memo;
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
|
attachment = attachment || [];
|
||||||
|
attachment.push(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
url = url.reduce((valid, cur) => {
|
url = url.reduce((valid, cur) => {
|
||||||
if (typeof cur === 'string') {
|
if (typeof cur === 'string') {
|
||||||
valid.push(cur);
|
valid.push(cur);
|
||||||
@@ -126,6 +150,7 @@ Mocks._normalize = async (object) => {
|
|||||||
sourceContent,
|
sourceContent,
|
||||||
image,
|
image,
|
||||||
url,
|
url,
|
||||||
|
attachment,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -332,7 +357,7 @@ Mocks.post = async (objects) => {
|
|||||||
attributedTo: uid,
|
attributedTo: uid,
|
||||||
inReplyTo: toPid,
|
inReplyTo: toPid,
|
||||||
published, updated, name, content, sourceContent,
|
published, updated, name, content, sourceContent,
|
||||||
type, to, cc, audience, attachment, tag, image,
|
to, cc, audience, attachment, tag, image,
|
||||||
} = object;
|
} = object;
|
||||||
|
|
||||||
await activitypub.actors.assert(uid);
|
await activitypub.actors.assert(uid);
|
||||||
@@ -346,11 +371,6 @@ Mocks.post = async (objects) => {
|
|||||||
let edited = new Date(updated);
|
let edited = new Date(updated);
|
||||||
edited = Number.isNaN(edited.valueOf()) ? undefined : edited;
|
edited = Number.isNaN(edited.valueOf()) ? undefined : edited;
|
||||||
|
|
||||||
if (type === 'Video') {
|
|
||||||
attachment = attachment || [];
|
|
||||||
attachment.push({ url });
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
uid,
|
uid,
|
||||||
pid,
|
pid,
|
||||||
|
|||||||
Reference in New Issue
Block a user