Enable more specific AttachmentDownload prioritization
This commit is contained in:
parent
87ea909ae9
commit
fc02762588
26 changed files with 2245 additions and 817 deletions
|
@ -70,7 +70,6 @@ export type AttachmentType = {
|
|||
flags?: number;
|
||||
thumbnail?: ThumbnailType;
|
||||
isCorrupted?: boolean;
|
||||
downloadJobId?: string;
|
||||
cdnNumber?: number;
|
||||
cdnId?: string;
|
||||
cdnKey?: string;
|
||||
|
@ -696,7 +695,7 @@ export function hasNotResolved(attachment?: AttachmentType): boolean {
|
|||
|
||||
export function isDownloading(attachment?: AttachmentType): boolean {
|
||||
const resolved = resolveNestedAttachment(attachment);
|
||||
return Boolean(resolved && resolved.downloadJobId && resolved.pending);
|
||||
return Boolean(resolved && resolved.pending);
|
||||
}
|
||||
|
||||
export function hasFailed(attachment?: AttachmentType): boolean {
|
||||
|
|
56
ts/types/AttachmentDownload.ts
Normal file
56
ts/types/AttachmentDownload.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import { z } from 'zod';
|
||||
import { MIMETypeSchema, type MIMEType } from './MIME';
|
||||
import type { AttachmentType } from './Attachment';
|
||||
|
||||
export const attachmentDownloadTypeSchema = z.enum([
|
||||
'long-message',
|
||||
'attachment',
|
||||
'preview',
|
||||
'contact',
|
||||
'quote',
|
||||
'sticker',
|
||||
]);
|
||||
|
||||
export type AttachmentDownloadJobTypeType = z.infer<
|
||||
typeof attachmentDownloadTypeSchema
|
||||
>;
|
||||
|
||||
export type AttachmentDownloadJobType = {
|
||||
messageId: string;
|
||||
receivedAt: number;
|
||||
sentAt: number;
|
||||
attachmentType: AttachmentDownloadJobTypeType;
|
||||
attachment: AttachmentType;
|
||||
attempts: number;
|
||||
active: boolean;
|
||||
retryAfter: number | null;
|
||||
lastAttemptTimestamp: number | null;
|
||||
digest: string;
|
||||
contentType: MIMEType;
|
||||
size: number;
|
||||
};
|
||||
|
||||
export const attachmentDownloadJobSchema = z.object({
|
||||
messageId: z.string(),
|
||||
receivedAt: z.number(),
|
||||
sentAt: z.number(),
|
||||
attachmentType: attachmentDownloadTypeSchema,
|
||||
attachment: z
|
||||
.object({ size: z.number(), contentType: MIMETypeSchema })
|
||||
.passthrough(),
|
||||
attempts: z.number(),
|
||||
active: z.boolean(),
|
||||
retryAfter: z.number().nullable(),
|
||||
lastAttemptTimestamp: z.number().nullable(),
|
||||
digest: z.string(),
|
||||
contentType: MIMETypeSchema,
|
||||
size: z.number(),
|
||||
messageIdForLogging: z.string().optional(),
|
||||
}) satisfies z.ZodType<
|
||||
Omit<AttachmentDownloadJobType, 'attachment' | 'contentType'> & {
|
||||
contentType: string;
|
||||
attachment: Record<string, unknown>;
|
||||
}
|
||||
>;
|
|
@ -1,7 +1,9 @@
|
|||
// Copyright 2018 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import { z } from 'zod';
|
||||
|
||||
export type MIMEType = string & { _mimeTypeBrand: never };
|
||||
export const MIMETypeSchema = z.string().brand('mimeType');
|
||||
export type MIMEType = z.infer<typeof MIMETypeSchema>;
|
||||
|
||||
export const stringToMIMEType = (value: string): MIMEType => {
|
||||
return value as MIMEType;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue