fix: re-fetch media from Fedify when stored timeline item has none
Post-detail view now re-fetches from the origin server when the stored timeline item has empty photo/video/audio arrays (from before the async iteration fix). On successful extraction, updates MongoDB so future views don't need to re-fetch.
This commit is contained in:
@@ -153,7 +153,15 @@ export function postDetailController(mountPath, plugin) {
|
|||||||
|
|
||||||
let object = null;
|
let object = null;
|
||||||
|
|
||||||
if (!timelineItem) {
|
// If stored item has no media, re-fetch from Fedify to pick up
|
||||||
|
// attachments that were missed before the async iteration fix.
|
||||||
|
const storedHasNoMedia =
|
||||||
|
timelineItem &&
|
||||||
|
(!timelineItem.photo || timelineItem.photo.length === 0) &&
|
||||||
|
(!timelineItem.video || timelineItem.video.length === 0) &&
|
||||||
|
(!timelineItem.audio || timelineItem.audio.length === 0);
|
||||||
|
|
||||||
|
if (!timelineItem || storedHasNoMedia) {
|
||||||
// Not in local timeline — fetch via lookupObject
|
// Not in local timeline — fetch via lookupObject
|
||||||
const handle = plugin.options.actor.handle;
|
const handle = plugin.options.actor.handle;
|
||||||
const ctx = plugin._federation.createContext(
|
const ctx = plugin._federation.createContext(
|
||||||
@@ -185,7 +193,8 @@ export function postDetailController(mountPath, plugin) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object) {
|
if (!object && !storedHasNoMedia) {
|
||||||
|
// Truly not found (no local item either)
|
||||||
return response.status(404).render("activitypub-post-detail", {
|
return response.status(404).render("activitypub-post-detail", {
|
||||||
title: response.locals.__("activitypub.reader.post.title"),
|
title: response.locals.__("activitypub.reader.post.title"),
|
||||||
notFound: true, objectUrl, mountPath,
|
notFound: true, objectUrl, mountPath,
|
||||||
@@ -194,6 +203,7 @@ export function postDetailController(mountPath, plugin) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (object) {
|
||||||
// If it's an actor (Person, Service, Application), redirect to profile
|
// If it's an actor (Person, Service, Application), redirect to profile
|
||||||
if (
|
if (
|
||||||
object instanceof Person ||
|
object instanceof Person ||
|
||||||
@@ -208,21 +218,43 @@ export function postDetailController(mountPath, plugin) {
|
|||||||
// Extract timeline item data from the Fedify object
|
// Extract timeline item data from the Fedify object
|
||||||
if (object instanceof Note || object instanceof Article) {
|
if (object instanceof Note || object instanceof Article) {
|
||||||
try {
|
try {
|
||||||
timelineItem = await extractObjectData(object);
|
const freshItem = await extractObjectData(object);
|
||||||
|
|
||||||
|
// If re-fetch found media that the stored item was missing, update MongoDB
|
||||||
|
if (storedHasNoMedia && timelineCol) {
|
||||||
|
const hasMedia =
|
||||||
|
(freshItem.photo && freshItem.photo.length > 0) ||
|
||||||
|
(freshItem.video && freshItem.video.length > 0) ||
|
||||||
|
(freshItem.audio && freshItem.audio.length > 0);
|
||||||
|
if (hasMedia) {
|
||||||
|
await timelineCol.updateOne(
|
||||||
|
{ $or: [{ uid: objectUrl }, { url: objectUrl }] },
|
||||||
|
{ $set: { photo: freshItem.photo, video: freshItem.video, audio: freshItem.audio } },
|
||||||
|
).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timelineItem = freshItem;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// If re-extraction fails but we have a stored item, use it
|
||||||
|
if (!storedHasNoMedia) {
|
||||||
console.error(`[post-detail] extractObjectData failed for ${objectUrl}:`, error.message);
|
console.error(`[post-detail] extractObjectData failed for ${objectUrl}:`, error.message);
|
||||||
return response.status(500).render("error", {
|
return response.status(500).render("error", {
|
||||||
title: "Error",
|
title: "Error",
|
||||||
content: "Failed to extract post data",
|
content: "Failed to extract post data",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
// storedHasNoMedia=true means timelineItem still has the stored data
|
||||||
|
}
|
||||||
|
} else if (!storedHasNoMedia) {
|
||||||
return response.status(400).render("error", {
|
return response.status(400).render("error", {
|
||||||
title: "Error",
|
title: "Error",
|
||||||
content: "Object is not a viewable post (must be Note or Article)",
|
content: "Object is not a viewable post (must be Note or Article)",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If object is null and storedHasNoMedia, we fall through with the stored timelineItem
|
||||||
|
}
|
||||||
|
|
||||||
// Build interaction state for this post
|
// Build interaction state for this post
|
||||||
const interactionMap = {};
|
const interactionMap = {};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rmdes/indiekit-endpoint-activitypub",
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
||||||
"version": "2.0.18",
|
"version": "2.0.19",
|
||||||
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"indiekit",
|
"indiekit",
|
||||||
|
|||||||
Reference in New Issue
Block a user