-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.zod.ts
More file actions
52 lines (44 loc) · 2.1 KB
/
storage.zod.ts
File metadata and controls
52 lines (44 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { z } from 'zod';
import { BaseResponseSchema } from './contract.zod';
import { FileMetadataSchema } from '../system/object-storage.zod';
/**
* Storage Service Protocol
*
* Defines the API contract for client-side file operations.
* Focuses on secure, direct-to-cloud uploads (Presigned URLs)
* rather than proxying bytes through the API server.
*/
// ==========================================
// Requests
// ==========================================
export const GetPresignedUrlRequestSchema = z.object({
filename: z.string().describe('Original filename'),
mimeType: z.string().describe('File MIME type'),
size: z.number().describe('File size in bytes'),
scope: z.string().default('user').describe('Target storage scope (e.g. user, private, public)'),
bucket: z.string().optional().describe('Specific bucket override (admin only)'),
});
export const CompleteUploadRequestSchema = z.object({
fileId: z.string().describe('File ID returned from presigned request'),
eTag: z.string().optional().describe('S3 ETag verification'),
});
// ==========================================
// Responses
// ==========================================
export const PresignedUrlResponseSchema = BaseResponseSchema.extend({
data: z.object({
uploadUrl: z.string().describe('PUT/POST URL for direct upload'),
downloadUrl: z.string().optional().describe('Public/Private preview URL'),
fileId: z.string().describe('Temporary File ID'),
method: z.enum(['PUT', 'POST']).describe('HTTP Method to use'),
headers: z.record(z.string(), z.string()).optional().describe('Required headers for upload'),
expiresIn: z.number().describe('URL expiry in seconds'),
}),
});
export const FileUploadResponseSchema = BaseResponseSchema.extend({
data: FileMetadataSchema.describe('Uploaded file metadata'),
});
export type GetPresignedUrlRequest = z.infer<typeof GetPresignedUrlRequestSchema>;
export type CompleteUploadRequest = z.infer<typeof CompleteUploadRequestSchema>;
export type PresignedUrlResponse = z.infer<typeof PresignedUrlResponseSchema>;
export type FileUploadResponse = z.infer<typeof FileUploadResponseSchema>;