index.js (1184B)
1 // src/lib/storage/index.js - object storage backend selection 2 // 3 // S3 is used when storage.s3.bucket is configured, otherwise objects go to 4 // the local filesystem. Both backends expose the same surface: 5 // 6 // put(key, body, opts) -> { key, size, sha256 } 7 // get(key, { range }) -> { key, size, stream }, throws StorageNotFound 8 // head(key) -> { key, size, modified } or null 9 // delete(key) -> resolves even when the key is absent 10 // presign(key, opts) -> absolute URL, or null when unsupported 11 // 12 // Callers must handle a null from presign by streaming get() themselves, 13 // since the local backend has no URL to hand out. 14 15 import { createLocalStorage } from './local.js'; 16 import { createS3Storage } from './s3.js'; 17 18 export { StorageNotFound, assertKey, sanitizeRelativePath } from './key.js'; 19 20 export function createStorage(cfg) { 21 return cfg.storage.driver === 's3' ? createS3Storage(cfg) : createLocalStorage(cfg); 22 } 23 24 // Key layout, kept in one place so every caller agrees. 25 export const keys = { 26 artifact: (jobId, taskId, relPath) => `artifacts/${jobId}/${taskId}/${relPath}`, 27 log: (jobId, taskId) => `logs/${jobId}/${taskId}.log`, 28 };