feat(platform): upload activity images via Hyperdrive staging
Add setActivityImageFromBytes (256 KB image cap, __presence__ channel) and readActivityImagePreview for UI thumbnails. Merges large/small image keys into the current activity and reuses presence enrichment for P2P gossip.
This commit is contained in:
@@ -5174,6 +5174,51 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setActivityImageFromBytes ({ data, filename, mimeType, slot = 'large' }) {
|
||||||
|
if (!this.attachments) throw new Error('attachments not ready')
|
||||||
|
const user = this.identity.user
|
||||||
|
if (!user) throw new Error('register first')
|
||||||
|
const mt = String(mimeType || '')
|
||||||
|
if (!mt.startsWith('image/')) throw new Error('activity image must be image/*')
|
||||||
|
if (data && data.length > 256 * 1024) {
|
||||||
|
throw new Error('activity image must be 256 KB or smaller')
|
||||||
|
}
|
||||||
|
const guildId = this.guild?.guild?.id || '__presence__'
|
||||||
|
const att = await this.attachments.stage({
|
||||||
|
data,
|
||||||
|
filename: filename || 'activity.png',
|
||||||
|
mimeType: mt,
|
||||||
|
guildId,
|
||||||
|
channelId: '__presence__',
|
||||||
|
authorId: user.id
|
||||||
|
})
|
||||||
|
if (this.guild) this.guild.gossipAttachmentMeta(att)
|
||||||
|
const cur = this.presence?.activity || {
|
||||||
|
type: 'custom',
|
||||||
|
name: 'Activity',
|
||||||
|
startedAt: Date.now()
|
||||||
|
}
|
||||||
|
const assets = { ...(cur.assets || {}) }
|
||||||
|
if (String(slot).toLowerCase() === 'small') {
|
||||||
|
assets.smallImageKey = att.id
|
||||||
|
} else {
|
||||||
|
assets.largeImageKey = att.id
|
||||||
|
}
|
||||||
|
return this.setActivity({ ...cur, assets })
|
||||||
|
}
|
||||||
|
|
||||||
|
async readActivityImagePreview (attachmentId, slot = 'large') {
|
||||||
|
const id =
|
||||||
|
attachmentId ||
|
||||||
|
(String(slot).toLowerCase() === 'small'
|
||||||
|
? this.presence?.activity?.assets?.smallImageKey
|
||||||
|
: this.presence?.activity?.assets?.largeImageKey) ||
|
||||||
|
this.presence?.activity?.assets?.largeImageKey
|
||||||
|
if (!id) return null
|
||||||
|
await this._ensureBannerAttachmentReady(id)
|
||||||
|
return this.readAttachmentPreview(id)
|
||||||
|
}
|
||||||
|
|
||||||
setActivity (activity) {
|
setActivity (activity) {
|
||||||
if (!this.presence) throw new Error('presence unavailable')
|
if (!this.presence) throw new Error('presence unavailable')
|
||||||
return this.setPresence(
|
return this.setPresence(
|
||||||
|
|||||||
Reference in New Issue
Block a user