mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-22 07:07:53 +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'),
|
Buffer.from(raw, 'base64url').toString('utf-8'),
|
||||||
) as AssetRequest
|
) as AssetRequest
|
||||||
|
|
||||||
if ('type' in data) {
|
switch (data.type) {
|
||||||
switch (data.type) {
|
case 'mediav1': {
|
||||||
case 'marketface': {
|
const downloadId = data.msgId + '::' + data.elementId
|
||||||
const downloadId = data.tabId + '::' + data.faceId
|
|
||||||
|
|
||||||
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||||
emojiDownloadMap[downloadId] = res
|
richMediaDownloadMap[downloadId] = res
|
||||||
void ctx.chronocat.sleep(5000).then(rej)
|
void ctx.chronocat.sleep(1000).then(rej)
|
||||||
})
|
})
|
||||||
|
|
||||||
await fetchMarketEmoticonAioImage({
|
if (
|
||||||
marketEmoticonAioImageReq: {
|
data.chatType === ChatType.Private &&
|
||||||
eId: data.faceId,
|
!data.peerUid.startsWith('u_')
|
||||||
epId: data.tabId,
|
)
|
||||||
name: data.name,
|
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
|
||||||
width: 200,
|
|
||||||
height: 200,
|
|
||||||
jobType: 0,
|
|
||||||
encryptKey: data.key,
|
|
||||||
filePath: data.filePath,
|
|
||||||
downloadType: 3,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
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) => {
|
case 'mfacev1': {
|
||||||
richMediaDownloadMap[downloadId] = res
|
const downloadId = data.tabId + '::' + data.faceId
|
||||||
void ctx.chronocat.sleep(1000).then(rej)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (data.chatType === ChatType.Private && !data.peerUid.startsWith('u_'))
|
const downloadCompletePromise = new Promise<string>((res, rej) => {
|
||||||
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
|
emojiDownloadMap[downloadId] = res
|
||||||
|
void ctx.chronocat.sleep(5000).then(rej)
|
||||||
|
})
|
||||||
|
|
||||||
await downloadRichMedia({
|
await fetchMarketEmoticonAioImage({
|
||||||
getReq: {
|
marketEmoticonAioImageReq: {
|
||||||
...data,
|
eId: data.faceId,
|
||||||
downloadType: 1,
|
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 { AtType, ChatType, FaceType, MsgType, SendType } from '@chronocat/red'
|
||||||
import type {
|
import type {
|
||||||
Channel,
|
Channel,
|
||||||
@ -422,12 +422,13 @@ async function parseElements(
|
|||||||
ctx.chronocat.h('img', {
|
ctx.chronocat.h('img', {
|
||||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
type: 'mediav1',
|
||||||
msgId: message.msgId,
|
msgId: message.msgId,
|
||||||
chatType: message.chatType,
|
chatType: message.chatType,
|
||||||
peerUid: message.peerUid,
|
peerUid: message.peerUid,
|
||||||
elementId: m.elementId,
|
elementId: m.elementId,
|
||||||
thumbSize: m.picElement!.thumbFileSize,
|
thumbSize: m.picElement!.thumbFileSize,
|
||||||
}),
|
} satisfies Media),
|
||||||
).toString('base64url')}`,
|
).toString('base64url')}`,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -440,12 +441,13 @@ async function parseElements(
|
|||||||
ctx.chronocat.h('file', {
|
ctx.chronocat.h('file', {
|
||||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
type: 'mediav1',
|
||||||
msgId: message.msgId,
|
msgId: message.msgId,
|
||||||
chatType: message.chatType,
|
chatType: message.chatType,
|
||||||
peerUid: message.peerUid,
|
peerUid: message.peerUid,
|
||||||
elementId: m.elementId,
|
elementId: m.elementId,
|
||||||
thumbSize: m.fileElement!.thumbFileSize,
|
thumbSize: m.fileElement!.thumbFileSize,
|
||||||
}),
|
} satisfies Media),
|
||||||
).toString('base64url')}`,
|
).toString('base64url')}`,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -458,12 +460,13 @@ async function parseElements(
|
|||||||
ctx.chronocat.h('audio', {
|
ctx.chronocat.h('audio', {
|
||||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
type: 'mediav1',
|
||||||
msgId: message.msgId,
|
msgId: message.msgId,
|
||||||
chatType: message.chatType,
|
chatType: message.chatType,
|
||||||
peerUid: message.peerUid,
|
peerUid: message.peerUid,
|
||||||
elementId: m.elementId,
|
elementId: m.elementId,
|
||||||
thumbSize: 0,
|
thumbSize: 0,
|
||||||
}),
|
} satisfies Media),
|
||||||
).toString('base64url')}`,
|
).toString('base64url')}`,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -476,12 +479,13 @@ async function parseElements(
|
|||||||
ctx.chronocat.h('video', {
|
ctx.chronocat.h('video', {
|
||||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
type: 'mediav1',
|
||||||
msgId: message.msgId,
|
msgId: message.msgId,
|
||||||
chatType: message.chatType,
|
chatType: message.chatType,
|
||||||
peerUid: message.peerUid,
|
peerUid: message.peerUid,
|
||||||
elementId: m.elementId,
|
elementId: m.elementId,
|
||||||
thumbSize: m.videoElement!.thumbSize,
|
thumbSize: m.videoElement!.thumbSize,
|
||||||
}),
|
} satisfies Media),
|
||||||
).toString('base64url')}`,
|
).toString('base64url')}`,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -565,13 +569,13 @@ async function parseElements(
|
|||||||
ctx.chronocat.h('img', {
|
ctx.chronocat.h('img', {
|
||||||
src: `${config.self_url}/v1/assets/${Buffer.from(
|
src: `${config.self_url}/v1/assets/${Buffer.from(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'marketface',
|
type: 'mfacev1',
|
||||||
tabId: m.marketFaceElement!.emojiPackageId,
|
tabId: m.marketFaceElement!.emojiPackageId,
|
||||||
faceId: m.marketFaceElement!.emojiId,
|
faceId: m.marketFaceElement!.emojiId,
|
||||||
key: m.marketFaceElement!.key,
|
key: m.marketFaceElement!.key,
|
||||||
name: m.marketFaceElement!.faceName,
|
name: m.marketFaceElement!.faceName,
|
||||||
filePath: m.marketFaceElement!.staticFacePath,
|
filePath: m.marketFaceElement!.staticFacePath,
|
||||||
}),
|
} satisfies MarketFaceAssetRequest),
|
||||||
).toString('base64url')}`,
|
).toString('base64url')}`,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -678,16 +678,16 @@ export interface RoleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Media {
|
export interface Media {
|
||||||
|
type: 'mediav1'
|
||||||
msgId: string
|
msgId: string
|
||||||
chatType: ChatType
|
chatType: ChatType
|
||||||
peerUid: string
|
peerUid: string
|
||||||
elementId: string
|
elementId: string
|
||||||
thumbSize: number
|
thumbSize: number
|
||||||
downloadType: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MarketFaceAssetRequest {
|
export interface MarketFaceAssetRequest {
|
||||||
type: 'marketface'
|
type: 'mfacev1'
|
||||||
tabId: number
|
tabId: number
|
||||||
faceId: string
|
faceId: string
|
||||||
key: string
|
key: string
|
||||||
|
Loading…
Reference in New Issue
Block a user