-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
216 additions
and
19 deletions.
There are no files selected for viewing
68 changes: 50 additions & 18 deletions
68
packages/engine-chronocat-api/src/api/internal/assets/get.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
import type { Media } from '@chronocat/red' | ||
import type { AssetRequest } from '@chronocat/red' | ||
import { ChatType } from '@chronocat/red' | ||
import type { ChronocatContext } from '@chronocat/shell' | ||
import { downloadRichMedia } from '../../../definitions/msgService' | ||
import { richMediaDownloadMap } from '../../../globalVars' | ||
import { | ||
downloadRichMedia, | ||
fetchMarketEmoticonAioImage, | ||
} from '../../../definitions/msgService' | ||
import { emojiDownloadMap, richMediaDownloadMap } from '../../../globalVars' | ||
|
||
export const buildAssetsGet = | ||
(ctx: ChronocatContext) => async (raw: string) => { | ||
const data = JSON.parse( | ||
Buffer.from(raw, 'base64url').toString('utf-8'), | ||
) as Media | ||
) as AssetRequest | ||
|
||
const downloadId = data.msgId + '::' + data.elementId | ||
if ('type' in data) { | ||
switch (data.type) { | ||
case 'marketface': { | ||
const downloadId = data.tabId + '::' + data.faceId | ||
|
||
const downloadCompletePromise = new Promise<string>((res, rej) => { | ||
richMediaDownloadMap[downloadId] = res | ||
void ctx.chronocat.sleep(1000).then(rej) | ||
}) | ||
const downloadCompletePromise = new Promise<string>((res, rej) => { | ||
emojiDownloadMap[downloadId] = res | ||
void ctx.chronocat.sleep(5000).then(rej) | ||
}) | ||
|
||
if (data.chatType === ChatType.Private && !data.peerUid.startsWith('u_')) | ||
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)! | ||
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, | ||
}, | ||
}) | ||
|
||
await downloadRichMedia({ | ||
getReq: { | ||
...data, | ||
downloadType: 1, | ||
}, | ||
}) | ||
return await downloadCompletePromise | ||
} | ||
} | ||
} else { | ||
const downloadId = data.msgId + '::' + data.elementId | ||
|
||
return await downloadCompletePromise | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters