mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-25 09:37:35 +00:00
refactor: add type field for all asset types
This commit is contained in:
parent
635b6dd0e4
commit
ec0103d527
@ -13,9 +13,36 @@ export const buildAssetsGet =
|
||||
Buffer.from(raw, 'base64url').toString('utf-8'),
|
||||
) as AssetRequest
|
||||
|
||||
if ('type' in data) {
|
||||
switch (data.type) {
|
||||
case 'marketface': {
|
||||
case 'mediav1': {
|
||||
const downloadId = data.msgId + '::' + data.elementId
|
||||
|
||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||
richMediaDownloadMap[downloadId] = res
|
||||
void ctx.chronocat.sleep(1000).then(rej)
|
||||
})
|
||||
|
||||
if (
|
||||
data.chatType === ChatType.Private &&
|
||||
!data.peerUid.startsWith('u_')
|
||||
)
|
||||
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
|
||||
|
||||
await downloadRichMedia({
|
||||
getReq: {
|
||||
msgId: data.msgId,
|
||||
chatType: data.chatType,
|
||||
peerUid: data.peerUid,
|
||||
elementId: data.elementId,
|
||||
thumbSize: data.thumbSize,
|
||||
downloadType: 1,
|
||||
},
|
||||
})
|
||||
|
||||
return await downloadCompletePromise
|
||||
}
|
||||
|
||||
case 'mfacev1': {
|
||||
const downloadId = data.tabId + '::' + data.faceId
|
||||
|
||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||
@ -40,24 +67,4 @@ export const buildAssetsGet =
|
||||
return await downloadCompletePromise
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const downloadId = data.msgId + '::' + data.elementId
|
||||
|
||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||
richMediaDownloadMap[downloadId] = res
|
||||
void ctx.chronocat.sleep(1000).then(rej)
|
||||
})
|
||||
|
||||
if (data.chatType === ChatType.Private && !data.peerUid.startsWith('u_'))
|
||||
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
|
||||
|
||||
await downloadRichMedia({
|
||||
getReq: {
|
||||
...data,
|
||||
downloadType: 1,
|
||||
},
|
||||
})
|
||||
|
||||
return await downloadCompletePromise
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { RedMessage } from '@chronocat/red'
|
||||
import type { MarketFaceAssetRequest, Media, RedMessage } from '@chronocat/red'
|
||||
import { AtType, ChatType, FaceType, MsgType, SendType } from '@chronocat/red'
|
||||
import type {
|
||||
Channel,
|
||||
@ -422,12 +422,13 @@ async function parseElements(
|
||||
ctx.chronocat.h('img', {
|
||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||
JSON.stringify({
|
||||
type: 'mediav1',
|
||||
msgId: message.msgId,
|
||||
chatType: message.chatType,
|
||||
peerUid: message.peerUid,
|
||||
elementId: m.elementId,
|
||||
thumbSize: m.picElement!.thumbFileSize,
|
||||
}),
|
||||
} satisfies Media),
|
||||
).toString('base64url')}`,
|
||||
}),
|
||||
)
|
||||
@ -440,12 +441,13 @@ async function parseElements(
|
||||
ctx.chronocat.h('file', {
|
||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||
JSON.stringify({
|
||||
type: 'mediav1',
|
||||
msgId: message.msgId,
|
||||
chatType: message.chatType,
|
||||
peerUid: message.peerUid,
|
||||
elementId: m.elementId,
|
||||
thumbSize: m.fileElement!.thumbFileSize,
|
||||
}),
|
||||
} satisfies Media),
|
||||
).toString('base64url')}`,
|
||||
}),
|
||||
)
|
||||
@ -458,12 +460,13 @@ async function parseElements(
|
||||
ctx.chronocat.h('audio', {
|
||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||
JSON.stringify({
|
||||
type: 'mediav1',
|
||||
msgId: message.msgId,
|
||||
chatType: message.chatType,
|
||||
peerUid: message.peerUid,
|
||||
elementId: m.elementId,
|
||||
thumbSize: 0,
|
||||
}),
|
||||
} satisfies Media),
|
||||
).toString('base64url')}`,
|
||||
}),
|
||||
)
|
||||
@ -476,12 +479,13 @@ async function parseElements(
|
||||
ctx.chronocat.h('video', {
|
||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||
JSON.stringify({
|
||||
type: 'mediav1',
|
||||
msgId: message.msgId,
|
||||
chatType: message.chatType,
|
||||
peerUid: message.peerUid,
|
||||
elementId: m.elementId,
|
||||
thumbSize: m.videoElement!.thumbSize,
|
||||
}),
|
||||
} satisfies Media),
|
||||
).toString('base64url')}`,
|
||||
}),
|
||||
)
|
||||
@ -565,13 +569,13 @@ async function parseElements(
|
||||
ctx.chronocat.h('img', {
|
||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||
JSON.stringify({
|
||||
type: 'marketface',
|
||||
type: 'mfacev1',
|
||||
tabId: m.marketFaceElement!.emojiPackageId,
|
||||
faceId: m.marketFaceElement!.emojiId,
|
||||
key: m.marketFaceElement!.key,
|
||||
name: m.marketFaceElement!.faceName,
|
||||
filePath: m.marketFaceElement!.staticFacePath,
|
||||
}),
|
||||
} satisfies MarketFaceAssetRequest),
|
||||
).toString('base64url')}`,
|
||||
}),
|
||||
],
|
||||
|
@ -678,16 +678,16 @@ export interface RoleInfo {
|
||||
}
|
||||
|
||||
export interface Media {
|
||||
type: 'mediav1'
|
||||
msgId: string
|
||||
chatType: ChatType
|
||||
peerUid: string
|
||||
elementId: string
|
||||
thumbSize: number
|
||||
downloadType: number
|
||||
}
|
||||
|
||||
export interface MarketFaceAssetRequest {
|
||||
type: 'marketface'
|
||||
type: 'mfacev1'
|
||||
tabId: number
|
||||
faceId: string
|
||||
key: string
|
||||
|
Loading…
Reference in New Issue
Block a user