fix(chat): make cached media load on safari
This commit is contained in:
@@ -109,10 +109,13 @@ export class ChatMediaCacheCoordinator {
|
||||
);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
if (blob.size <= 0) {
|
||||
throw new Error("Media download returned an empty blob.");
|
||||
const bytes = await response.arrayBuffer();
|
||||
if (bytes.byteLength <= 0) {
|
||||
throw new Error("Media download returned empty bytes.");
|
||||
}
|
||||
const mimeType =
|
||||
response.headers.get("content-type") ||
|
||||
fallbackChatMediaMimeType(input.kind);
|
||||
|
||||
const saveResult = await this.mediaStorage.saveMedia({
|
||||
cacheKey,
|
||||
@@ -120,11 +123,8 @@ export class ChatMediaCacheCoordinator {
|
||||
messageId: input.messageId,
|
||||
kind: input.kind,
|
||||
remoteUrl: input.remoteUrl,
|
||||
blob,
|
||||
mimeType:
|
||||
blob.type ||
|
||||
response.headers.get("content-type") ||
|
||||
fallbackChatMediaMimeType(input.kind),
|
||||
bytes,
|
||||
mimeType,
|
||||
});
|
||||
if (Result.isErr(saveResult)) throw saveResult.error;
|
||||
void requestBrowserPersistentStorageOnce();
|
||||
|
||||
@@ -69,12 +69,12 @@ export interface IChatRepository {
|
||||
/** 获取本地消息数量。 */
|
||||
getLocalMessageCount(): Promise<Result<number>>;
|
||||
|
||||
/** 获取本地缓存的图片 / 音频 Blob。 */
|
||||
/** 获取本地缓存的图片 / 音频。 */
|
||||
getCachedMedia(
|
||||
input: ChatMediaLookupInput,
|
||||
): Promise<Result<LocalChatMediaRow | null>>;
|
||||
|
||||
/** 下载并缓存远程图片 / 音频 Blob。 */
|
||||
/** 下载并缓存远程图片 / 音频。 */
|
||||
cacheRemoteMedia(
|
||||
input: CacheRemoteChatMediaInput,
|
||||
): Promise<Result<LocalChatMediaRow>>;
|
||||
|
||||
Reference in New Issue
Block a user