Files
Signal-Desktop/ts/types/AttachmentDownload.ts
2024-05-30 09:46:43 +10:00

65 lines
1.6 KiB
TypeScript

// 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';
import {
type JobManagerJobType,
jobManagerJobSchema,
} from '../jobs/JobManager';
export enum MediaTier {
STANDARD = 'standard',
BACKUP = 'backup',
}
export const attachmentDownloadTypeSchema = z.enum([
'long-message',
'attachment',
'preview',
'contact',
'quote',
'sticker',
]);
export type AttachmentDownloadJobTypeType = z.infer<
typeof attachmentDownloadTypeSchema
>;
export type CoreAttachmentDownloadJobType = {
messageId: string;
receivedAt: number;
sentAt: number;
attachmentType: AttachmentDownloadJobTypeType;
attachment: AttachmentType;
digest: string;
contentType: MIMEType;
size: number;
};
export type AttachmentDownloadJobType = CoreAttachmentDownloadJobType &
JobManagerJobType;
export const coreAttachmentDownloadJobSchema = z.object({
messageId: z.string(),
receivedAt: z.number(),
sentAt: z.number(),
attachmentType: attachmentDownloadTypeSchema,
attachment: z
.object({ size: z.number(), contentType: MIMETypeSchema })
.passthrough(),
digest: z.string(),
contentType: MIMETypeSchema,
size: z.number(),
messageIdForLogging: z.string().optional(),
});
export const attachmentDownloadJobSchema = coreAttachmentDownloadJobSchema.and(
jobManagerJobSchema
) satisfies z.ZodType<
Omit<AttachmentDownloadJobType, 'attachment' | 'contentType'> & {
contentType: string;
attachment: Record<string, unknown>;
}
>;