Fixed .false file extension.
This commit is contained in:
@@ -8,22 +8,41 @@ function resolveMediaUrl(media) {
|
||||
return url ? url.replace(/&/g, '&') : null;
|
||||
}
|
||||
|
||||
// reddit sends the non-standard 'image/jpg' instead of the real IANA 'image/jpeg' for
|
||||
// gallery items - left as-is, this silently breaks anything matching against real mime
|
||||
// types downstream (interpolate.js's extension lookup ends up with a '.false' extension,
|
||||
// fetch/content.js's addMeta() skips embedding metadata since it only matches 'image/jpeg')
|
||||
function normalizeType(type) {
|
||||
return type === 'image/jpg' ? 'image/jpeg' : type;
|
||||
}
|
||||
|
||||
async function redditAlbum(host, post, { reddit }) {
|
||||
// fetched through the authenticated/throttled client, not a raw fetch()/bhttp request -
|
||||
// reddit's anonymous-traffic bot challenge blocks plain unauthenticated .json requests
|
||||
const data = await reddit.getSubmission(post.id);
|
||||
const mediaMetadata = data.media_metadata || {};
|
||||
|
||||
const items = (data.gallery_data?.items || [])
|
||||
// gallery_data (the ordered {media_id, is_deleted, ...} list for this gallery) has been
|
||||
// seen coming back null on a freshly-posted gallery even though media_metadata itself
|
||||
// was already fully populated - fall back to media_metadata's own keys, in the order the
|
||||
// JSON provided them (reddit sends them in gallery order, and object key order is
|
||||
// preserved through JSON.parse), skipping anything not (yet, or any longer) valid
|
||||
const galleryItems = data.gallery_data?.items
|
||||
|| Object.entries(mediaMetadata)
|
||||
.filter(([, media]) => media.status === 'valid')
|
||||
.map(([mediaId]) => ({ media_id: mediaId }));
|
||||
|
||||
const items = galleryItems
|
||||
.filter((item) => !item.is_deleted)
|
||||
.map((item) => {
|
||||
const media = data.media_metadata?.[item.media_id];
|
||||
const media = mediaMetadata[item.media_id];
|
||||
const url = resolveMediaUrl(media);
|
||||
|
||||
return url && {
|
||||
id: item.media_id,
|
||||
url,
|
||||
datetime: post.datetime,
|
||||
type: media.m || 'image/jpeg',
|
||||
type: normalizeType(media.m) || 'image/jpeg',
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user