mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-21 22:58:10 +00:00
refactor: add type field for all asset types
This commit is contained in:
parent
635b6dd0e4
commit
ec0103d527
@ -13,51 +13,58 @@ export const buildAssetsGet =
|
||||
Buffer.from(raw, 'base64url').toString('utf-8'),
|
||||
) as AssetRequest
|
||||
|
||||
if ('type' in data) {
|
||||
switch (data.type) {
|
||||
case 'marketface': {
|
||||
const downloadId = data.tabId + '::' + data.faceId
|
||||
switch (data.type) {
|
||||
case 'mediav1': {
|
||||
const downloadId = data.msgId + '::' + data.elementId
|
||||
|
||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||
emojiDownloadMap[downloadId] = res
|
||||
void ctx.chronocat.sleep(5000).then(rej)
|
||||
})
|
||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||
richMediaDownloadMap[downloadId] = res
|
||||
void ctx.chronocat.sleep(1000).then(rej)
|
||||
})
|
||||
|
||||
await fetchMarketEmoticonAioImage({
|
||||
marketEmoticonAioImageReq: {
|
||||
eId: data.faceId,
|
||||
epId: data.tabId,
|
||||
name: data.name,
|
||||
width: 200,
|
||||
height: 200,
|
||||
jobType: 0,
|
||||
encryptKey: data.key,
|
||||
filePath: data.filePath,
|
||||
downloadType: 3,
|
||||
},
|
||||
})
|
||||
if (
|
||||
data.chatType === ChatType.Private &&
|
||||
!data.peerUid.startsWith('u_')
|
||||
)
|
||||
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
|
||||
|
||||
return await downloadCompletePromise
|
||||
}
|
||||
await downloadRichMedia({
|
||||
getReq: {
|
||||
msgId: data.msgId,
|
||||
chatType: data.chatType,
|
||||
peerUid: data.peerUid,
|
||||
elementId: data.elementId,
|
||||
thumbSize: data.thumbSize,
|
||||
downloadType: 1,
|
||||
},
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
case 'mfacev1': {
|
||||
const downloadId = data.tabId + '::' + data.faceId
|
||||
|
||||
if (data.chatType === ChatType.Private && !data.peerUid.startsWith('u_'))
|
||||
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
|
||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||
emojiDownloadMap[downloadId] = res
|
||||
void ctx.chronocat.sleep(5000).then(rej)
|
||||
})
|
||||
|
||||
await downloadRichMedia({
|
||||
getReq: {
|
||||
...data,
|
||||
downloadType: 1,
|
||||
},
|
||||
})
|
||||
await fetchMarketEmoticonAioImage({
|
||||
marketEmoticonAioImageReq: {
|
||||
eId: data.faceId,
|
||||
epId: data.tabId,
|
||||
name: data.name,
|
||||
width: 200,
|
||||
height: 200,
|
||||
jobType: 0,
|
||||
encryptKey: data.key,
|
||||
filePath: data.filePath,
|
||||
downloadType: 3,
|
||||
},
|
||||
})
|
||||
|
||||
return await downloadCompletePromise
|
||||
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