1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-09-28 23:07:30 +00:00
bibliogram/src/lib/structures/User.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-01-14 14:38:33 +00:00
const constants = require("../constants")
2020-04-04 14:57:31 +00:00
const {proxyProfilePic} = require("../utils/proxyurl")
const {structure} = require("../utils/structuretext")
2020-01-12 12:50:21 +00:00
const Timeline = require("./Timeline")
2020-01-14 14:38:33 +00:00
require("../testimports")(constants, Timeline)
2020-01-12 12:50:21 +00:00
class User {
/**
* @param {import("../types").GraphUser} data
*/
constructor(data) {
this.data = data
this.following = data.edge_follow.count
this.followedBy = data.edge_followed_by.count
this.posts = data.edge_owner_to_timeline_media.count
this.timeline = new Timeline(this)
2020-01-14 14:38:33 +00:00
this.cachedAt = Date.now()
2020-04-04 14:57:31 +00:00
this.computeProxyProfilePic()
}
computeProxyProfilePic() {
this.proxyProfilePicture = proxyProfilePic(this.data.profile_pic_url, this.data.id)
2020-01-14 14:38:33 +00:00
}
getStructuredBio() {
if (!this.data.biography) return null
return structure(this.data.biography)
}
2020-01-14 14:38:33 +00:00
getTtl(scale = 1) {
2020-01-28 03:14:21 +00:00
const expiresAt = this.cachedAt + constants.caching.resource_cache_time
2020-01-14 14:38:33 +00:00
const ttl = expiresAt - Date.now()
return Math.ceil(Math.max(ttl, 0) / scale)
2020-01-12 12:50:21 +00:00
}
export() {
return this.data
}
}
module.exports = User