2026-04-07 21:58:20 -04:00
|
|
|
import { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
|
|
|
|
|
import { createReadStream, createWriteStream } from 'fs';
|
2026-05-26 22:38:42 -04:00
|
|
|
import { readdir } from 'fs/promises';
|
|
|
|
|
import { join, extname } from 'path';
|
2026-04-07 21:58:20 -04:00
|
|
|
import { pipeline } from 'stream/promises';
|
|
|
|
|
|
2026-05-26 22:38:42 -04:00
|
|
|
const CONTENT_TYPES = {
|
|
|
|
|
'.m3u8': 'application/vnd.apple.mpegurl',
|
|
|
|
|
'.m4s': 'video/iso.segment',
|
|
|
|
|
'.mp4': 'video/mp4',
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-07 21:58:20 -04:00
|
|
|
const createS3Client = () => {
|
|
|
|
|
return new S3Client({
|
2026-05-16 00:29:48 -04:00
|
|
|
region: process.env.S3_REGION || 'us-east-1',
|
2026-04-07 21:58:20 -04:00
|
|
|
endpoint: process.env.S3_ENDPOINT,
|
|
|
|
|
credentials: {
|
2026-05-16 00:29:48 -04:00
|
|
|
accessKeyId: process.env.S3_ACCESS_KEY,
|
|
|
|
|
secretAccessKey: process.env.S3_SECRET_KEY,
|
2026-04-07 21:58:20 -04:00
|
|
|
},
|
|
|
|
|
forcePathStyle: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const downloadFromS3 = async (bucket, key, localPath) => {
|
|
|
|
|
const client = createS3Client();
|
|
|
|
|
try {
|
|
|
|
|
const response = await client.send(
|
|
|
|
|
new GetObjectCommand({ Bucket: bucket, Key: key })
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const writeStream = createWriteStream(localPath);
|
|
|
|
|
await pipeline(response.Body, writeStream);
|
|
|
|
|
} finally {
|
|
|
|
|
client.destroy();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const uploadToS3 = async (bucket, key, localPath) => {
|
|
|
|
|
const client = createS3Client();
|
|
|
|
|
try {
|
|
|
|
|
const readStream = createReadStream(localPath);
|
|
|
|
|
await client.send(
|
|
|
|
|
new PutObjectCommand({
|
|
|
|
|
Bucket: bucket,
|
|
|
|
|
Key: key,
|
|
|
|
|
Body: readStream,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
client.destroy();
|
|
|
|
|
}
|
|
|
|
|
};
|
feat: live HLS preview, proxy worker fixes, Settings tabs, growing-files + Premier panel
- worker/proxy: scale-to-even filter, analyzeduration 100M, skip images, hasAudio
- worker/promotion: SMB landing zone -> S3 on idle, queues proxy job, status='ready'
- web-ui screens-ingest: HlsPreview component replaces fake LiveStrip/FauxFrame
- web-ui screens-admin: functional Settings tabs (S3, GPU, Growing, SDI, AMPP)
- mam-api /settings/growing: GET/PUT growing-files config
- mam-api /assets/:id/live-path: SMB UNC/POSIX path for live growing assets
- capture-manager: GROWING_ENABLED -> write hires to /growing instead of S3 stream
- recorders.js: pass GROWING_ENABLED to capture container, bind /growing mount
- docker-compose: mount /mnt/NVME/MAM/wild-dragon-growing on mam-api + worker
- premiere-plugin: Mount Live button, Relink-to-HiRes, live->ready status poll
2026-05-22 19:12:53 -04:00
|
|
|
|
2026-05-26 22:38:42 -04:00
|
|
|
// Upload every file in `localDir` to `bucket` under `keyPrefix/`. Used for the
|
|
|
|
|
// HLS proxy output (init.mp4 + segment_*.m4s + playlist.m3u8). Each file goes
|
|
|
|
|
// up as its own PutObject so individual segments stay small and never trigger
|
|
|
|
|
// RustFS's broken byte-range path on large objects.
|
|
|
|
|
export const uploadDirectoryToS3 = async (bucket, keyPrefix, localDir) => {
|
|
|
|
|
const client = createS3Client();
|
|
|
|
|
try {
|
|
|
|
|
const entries = await readdir(localDir, { withFileTypes: true });
|
|
|
|
|
const files = entries.filter(e => e.isFile()).map(e => e.name);
|
|
|
|
|
for (const name of files) {
|
|
|
|
|
const ext = extname(name).toLowerCase();
|
|
|
|
|
const ct = CONTENT_TYPES[ext] || 'application/octet-stream';
|
|
|
|
|
await client.send(new PutObjectCommand({
|
|
|
|
|
Bucket: bucket,
|
|
|
|
|
Key: `${keyPrefix}/${name}`,
|
|
|
|
|
Body: createReadStream(join(localDir, name)),
|
|
|
|
|
ContentType: ct,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
return files;
|
|
|
|
|
} finally {
|
|
|
|
|
client.destroy();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
feat: live HLS preview, proxy worker fixes, Settings tabs, growing-files + Premier panel
- worker/proxy: scale-to-even filter, analyzeduration 100M, skip images, hasAudio
- worker/promotion: SMB landing zone -> S3 on idle, queues proxy job, status='ready'
- web-ui screens-ingest: HlsPreview component replaces fake LiveStrip/FauxFrame
- web-ui screens-admin: functional Settings tabs (S3, GPU, Growing, SDI, AMPP)
- mam-api /settings/growing: GET/PUT growing-files config
- mam-api /assets/:id/live-path: SMB UNC/POSIX path for live growing assets
- capture-manager: GROWING_ENABLED -> write hires to /growing instead of S3 stream
- recorders.js: pass GROWING_ENABLED to capture container, bind /growing mount
- docker-compose: mount /mnt/NVME/MAM/wild-dragon-growing on mam-api + worker
- premiere-plugin: Mount Live button, Relink-to-HiRes, live->ready status poll
2026-05-22 19:12:53 -04:00
|
|
|
// Multipart-aware streaming upload — used by the promotion worker to push
|
|
|
|
|
// large growing-file masters without buffering them entirely in memory.
|
|
|
|
|
export const uploadStreamToS3 = async (bucket, key, readable) => {
|
|
|
|
|
const { Upload } = await import('@aws-sdk/lib-storage');
|
|
|
|
|
const client = createS3Client();
|
|
|
|
|
try {
|
|
|
|
|
const upload = new Upload({
|
|
|
|
|
client,
|
|
|
|
|
params: { Bucket: bucket, Key: key, Body: readable },
|
|
|
|
|
queueSize: 4,
|
|
|
|
|
partSize: 8 * 1024 * 1024,
|
|
|
|
|
});
|
|
|
|
|
await upload.done();
|
|
|
|
|
} finally {
|
|
|
|
|
client.destroy();
|
|
|
|
|
}
|
|
|
|
|
};
|