@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 42 lines 1.15 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2
3 /** Only objects under this prefix trigger the indexer. */
4 export const UPLOADS_PREFIX = "uploads/";
5
6 /**
7 * Where the uploaded bytes live. `forceDestroy` empties the bucket on
8 * `alchemy destroy`; drop it in production so a destroy cannot take user
9 * data with it.
10 */
11 export const Uploads = GCP.Storage.Bucket("Uploads", {
12 forceDestroy: true,
13 });
14
15 /**
16 * One Firestore document per file, at `files/{name}`, written by the
17 * indexer once the object has landed.
18 */
19 export const Files = GCP.Firestore.Database("Files", {
20 type: "FIRESTORE_NATIVE",
21 });
22
23 /**
24 * File names double as Firestore document ids and object-name suffixes,
25 * so keep them to a URL- and id-safe alphabet.
26 */
27 export const isValidName = (name: string) => /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name);
28
29 export const objectFor = (name: string) => `${UPLOADS_PREFIX}${name}`;
30
31 export const documentFor = (name: string) => `files/${name}`;
32
33 /** What the indexer records for each upload. */
34 export interface FileRecord {
35 name: string;
36 object: string;
37 generation: string;
38 size: number;
39 contentType: string;
40 sha256: string;
41 indexedAt: Date;
42 }