Rewrite feeds
This commit is contained in:
@@ -13,11 +13,16 @@ class ReelUser {
|
||||
this.following = 0
|
||||
this.followedBy = 0
|
||||
this.posts = 0
|
||||
/** @type {import("./Timeline")} */
|
||||
this.timeline = new Timeline(this)
|
||||
this.cachedAt = Date.now()
|
||||
this.proxyProfilePicture = proxyImage(this.data.profile_pic_url)
|
||||
}
|
||||
|
||||
getStructuredBio() {
|
||||
return null
|
||||
}
|
||||
|
||||
getTtl(scale = 1) {
|
||||
const expiresAt = this.cachedAt + constants.caching.resource_cache_time
|
||||
const ttl = expiresAt - Date.now()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const RSS = require("rss")
|
||||
const {Feed} = require("feed")
|
||||
const constants = require("../constants")
|
||||
const config = require("../../../config")
|
||||
const TimelineEntry = require("./TimelineEntry")
|
||||
@@ -54,18 +54,27 @@ class Timeline {
|
||||
}
|
||||
|
||||
async fetchFeed() {
|
||||
const feed = new RSS({
|
||||
title: `@${this.user.data.username}`,
|
||||
feed_url: `${config.website_origin}/u/${this.user.data.username}/rss.xml`,
|
||||
site_url: config.website_origin,
|
||||
// we likely cannot use full_name here - reel fallback would make the feed title inconsistent, leading to confusing experience
|
||||
const usedName = `@${this.user.data.username}`
|
||||
const feed = new Feed({
|
||||
title: usedName,
|
||||
description: this.user.data.biography,
|
||||
image_url: config.website_origin+this.user.proxyProfilePicture,
|
||||
pubDate: new Date(this.user.cachedAt),
|
||||
ttl: this.user.getTtl(1000*60) // scale to minute
|
||||
id: `bibliogram:user/${this.user.data.username}`,
|
||||
link: `${constants.website_origin}/u/${this.user.data.username}`,
|
||||
feedLinks: {
|
||||
rss: `${constants.website_origin}/u/${this.user.data.username}/rss.xml`,
|
||||
atom: `${constants.website_origin}/u/${this.user.data.username}/atom.xml`
|
||||
},
|
||||
image: constants.website_origin+this.user.proxyProfilePicture,
|
||||
updated: new Date(this.user.cachedAt),
|
||||
author: {
|
||||
name: usedName,
|
||||
link: `${constants.website_origin}/u/${this.user.data.username}`
|
||||
}
|
||||
})
|
||||
const page = this.pages[0] // only get posts from first page
|
||||
await Promise.all(page.map(item =>
|
||||
item.fetchFeedData().then(feedData => feed.item(feedData))
|
||||
item.fetchFeedData().then(feedData => feed.addItem(feedData))
|
||||
))
|
||||
return feed
|
||||
}
|
||||
|
||||
@@ -217,6 +217,9 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
else return this.update().then(() => this.getVideoUrlP())
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<import("feed/src/typings/index").Item>}
|
||||
*/
|
||||
async fetchFeedData() {
|
||||
const children = await this.fetchChildren()
|
||||
return {
|
||||
@@ -230,10 +233,10 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
height: child.data.dimensions.height
|
||||
}))
|
||||
}),
|
||||
author: this.data.owner.username,
|
||||
url: `${constants.website_origin}/p/${this.data.shortcode}`,
|
||||
guid: `${constants.website_origin}/p/${this.data.shortcode}`, // Is it wise to keep the origin in here? The same post would have a different ID from different servers.
|
||||
date: new Date(this.data.taken_at_timestamp*1000)
|
||||
link: `${constants.website_origin}/p/${this.data.shortcode}`,
|
||||
id: `bibliogram:post/${this.data.shortcode}`, // Is it wise to keep the origin in here? The same post would have a different ID from different servers.
|
||||
published: new Date(this.data.taken_at_timestamp*1000), // first published date
|
||||
date: new Date(this.data.taken_at_timestamp*1000) // last modified date
|
||||
/*
|
||||
Readers should display the description as HTML rather than using the media enclosure.
|
||||
enclosure: {
|
||||
|
||||
Reference in New Issue
Block a user