feat(platform): v0.6.1 image guild emoji staging and preview API
stageGuildEmojiImage on __emoji__ channel, upsertGuildEmoji with image blob, gossip ATTACHMENT_META with EMOJI_UPSERT, readEmojiImage for UI IPC. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -1410,7 +1410,25 @@ class PearcordPlatform extends EventEmitter {
|
||||
return this.slashCommands.list()
|
||||
}
|
||||
|
||||
async upsertGuildEmoji ({ name, glyph, description }) {
|
||||
async stageGuildEmojiImage ({ data, filename, mimeType }) {
|
||||
if (!this.attachments) throw new Error('attachments not ready')
|
||||
const user = this.identity.user
|
||||
if (!user) throw new Error('register first')
|
||||
const guildId = this.guild?.guild?.id
|
||||
if (!guildId) throw new Error('no guild')
|
||||
const mt = String(mimeType || '')
|
||||
if (!mt.startsWith('image/')) throw new Error('emoji image must be image/*')
|
||||
return this.attachments.stage({
|
||||
data,
|
||||
filename: filename || 'emoji.png',
|
||||
mimeType: mt,
|
||||
guildId,
|
||||
channelId: '__emoji__',
|
||||
authorId: user.id
|
||||
})
|
||||
}
|
||||
|
||||
async upsertGuildEmoji ({ name, glyph, description, attachmentId, image }) {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const user = this.identity.user
|
||||
if (!user) throw new Error('register first')
|
||||
@@ -1419,17 +1437,43 @@ class PearcordPlatform extends EventEmitter {
|
||||
throw new Error('no permission to manage emojis')
|
||||
}
|
||||
if (!this.emojiRegistry) await this._initEmojiRegistry(this.guild.guild.id)
|
||||
let att = null
|
||||
if (image?.data) {
|
||||
att = await this.stageGuildEmojiImage({
|
||||
data: image.data,
|
||||
filename: image.filename,
|
||||
mimeType: image.mimeType
|
||||
})
|
||||
} else if (attachmentId) {
|
||||
att = await this.attachments?.get(attachmentId)
|
||||
if (!att) throw new Error('attachment not found')
|
||||
}
|
||||
const row = await this.emojiRegistry.upsert({
|
||||
name,
|
||||
glyph,
|
||||
glyph: att ? undefined : glyph,
|
||||
description,
|
||||
authorId: user.id
|
||||
authorId: user.id,
|
||||
kind: att ? 'image' : 'unicode',
|
||||
imageAttachmentId: att?.id || null,
|
||||
driveKey: att?.driveKey || null,
|
||||
drivePath: att?.drivePath || null,
|
||||
mimeType: att?.mimeType || null,
|
||||
filename: att?.filename || null
|
||||
})
|
||||
if (att) this.guild.gossipAttachmentMeta(att)
|
||||
this.guild.gossipEmojiUpsert(row)
|
||||
this.emit('guild-emoji', row)
|
||||
return row
|
||||
}
|
||||
|
||||
async readEmojiImage (nameOrAttachmentId) {
|
||||
const byName = this.emojiRegistry
|
||||
? await this.emojiRegistry.get(nameOrAttachmentId)
|
||||
: null
|
||||
const attachmentId = byName?.imageAttachmentId || nameOrAttachmentId
|
||||
return this.readAttachmentPreview(attachmentId)
|
||||
}
|
||||
|
||||
async listGuildEmojis () {
|
||||
if (!this.emojiRegistry) return []
|
||||
return this.emojiRegistry.list()
|
||||
|
||||
Reference in New Issue
Block a user