feat(route): Include enclosures for mp3, mp4, and m4a files attached to kemono posts (#13821)

* Include enclosures for mp3 and mp4 files in kemono posts.

* Don't engage with attachment links that don't have a href.

* Use the attachment's download attribute to derive a filename.

This way, kemono can change the query string in its URLs without
breaking how we're deriving relevance and mime type.

* Accept m4a as a type of audio enclosure.
This commit is contained in:
ティン・ルーフ 2023-11-18 13:49:22 +00:00 committed by GitHub
parent 8364aa2006
commit 6fb730b18d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -92,6 +92,26 @@ module.exports = async (ctx) => {
item.guid = item.link.replace('kemono.su', 'kemono.party');
item.pubDate = parseDate(content('.timestamp').attr('datetime'));
// find the first attachment with a file extension we
// want, and set it as the enclosure
content('.post__attachment-link[href][download]').each(function () {
const extension = content(this).attr('download').replace(/.*\./, '').toLowerCase();
const mimeType =
{
m4a: 'audio/mp4',
mp3: 'audio/mpeg',
mp4: 'video/mp4',
}[extension] || null;
if (mimeType === null) {
return;
}
item.enclosure_url = content(this).attr('href');
item.enclosure_type = mimeType;
return false;
});
return item;
})
)