Initial boilerplate scaffold for continuum-backend
Bun + ElysiaJS control plane: Drizzle/Postgres schema (printers, farms, print_jobs, pgvector frame_embeddings), R2 presigned URLs, Redis Streams frame ingestion queue, REST routes, and the /ws/edge/v1 edge-gateway WebSocket uplink.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
|
||||
const accountId = process.env.R2_ACCOUNT_ID ?? "";
|
||||
const bucket = process.env.R2_BUCKET ?? "continuum";
|
||||
|
||||
export const s3 = new S3Client({
|
||||
region: "auto",
|
||||
endpoint: process.env.R2_ENDPOINT ?? `https://${accountId}.r2.cloudflarestorage.com`,
|
||||
credentials: {
|
||||
accessKeyId: process.env.R2_ACCESS_KEY_ID ?? "",
|
||||
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY ?? "",
|
||||
},
|
||||
});
|
||||
|
||||
/** Presigned PUT for clients uploading a G-code/3MF file directly to R2. */
|
||||
export async function getUploadUrl(key: string, contentType = "application/octet-stream", expiresInSeconds = 900) {
|
||||
const command = new PutObjectCommand({ Bucket: bucket, Key: key, ContentType: contentType });
|
||||
return getSignedUrl(s3, command, { expiresIn: expiresInSeconds });
|
||||
}
|
||||
|
||||
/** Presigned GET for the edge proxy to download a job file over LAN via FTPS relay or direct fetch. */
|
||||
export async function getDownloadUrl(key: string, expiresInSeconds = 900) {
|
||||
const command = new GetObjectCommand({ Bucket: bucket, Key: key });
|
||||
return getSignedUrl(s3, command, { expiresIn: expiresInSeconds });
|
||||
}
|
||||
|
||||
export function jobFileKey(farmId: string, jobId: string, fileName: string) {
|
||||
return `farms/${farmId}/jobs/${jobId}/${fileName}`;
|
||||
}
|
||||
|
||||
export function frameKey(farmId: string, printerId: string, frameId: string) {
|
||||
return `farms/${farmId}/printers/${printerId}/frames/${frameId}.jpg`;
|
||||
}
|
||||
Reference in New Issue
Block a user