Merge branch 'dev' into feat/clean-cec

This commit is contained in:
mrjvs 2025-09-18 21:17:36 +02:00 committed by GitHub
commit 36be92449b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 12 deletions

View File

@ -9,7 +9,7 @@ env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DEFAULT_BRANCH: ${{ format('refs/heads/{0}', github.event.repository.default_branch) }}
SHOULD_PUSH_IMAGE: ${{ (github.event_name == 'push' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.ref == 'refs/heads/dev')) || github.event_name == 'workflow_dispatch' }}
SHOULD_PUSH_IMAGE: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev')) || github.event_name == 'workflow_dispatch' }}
jobs:
build-publish-amd64:
@ -41,7 +41,7 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == env.DEFAULT_BRANCH }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=edge,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha
@ -85,7 +85,7 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest-arm,enable=${{ github.ref == env.DEFAULT_BRANCH }}
type=raw,value=latest-arm,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=edge-arm,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha,suffix=-arm

View File

@ -38,7 +38,7 @@ function buildLocalCDNPath(fullKey: string): string {
return path.join(config.cdn.disk_path, fullKey);
}
export async function getCDNFileAsStream(namespace: CDNNamespace, key: string): Promise<Readable | null> {
export async function getCDNFileAsStream(namespace: CDNNamespace, key: string): Promise<{ size: number | null; stream: Readable } | null> {
const fullKey = buildKey(namespace, key);
if (!s3) {
@ -49,7 +49,10 @@ export async function getCDNFileAsStream(namespace: CDNNamespace, key: string):
return null;
}
return fs.createReadStream(filePath);
return {
stream: fs.createReadStream(filePath),
size: fileInfo.size
};
}
const response = await s3.send(new GetObjectCommand({
@ -61,15 +64,18 @@ export async function getCDNFileAsStream(namespace: CDNNamespace, key: string):
return null;
}
return response.Body;
return {
stream: response.Body,
size: response.ContentLength ?? null
};
}
export async function getCDNFileAsBuffer(namespace: CDNNamespace, key: string): Promise<Buffer | null> {
const stream = await getCDNFileAsStream(namespace, key);
if (!stream) {
const streamOutput = await getCDNFileAsStream(namespace, key);
if (!streamOutput) {
return null;
}
return bufferConsumer(stream);
return bufferConsumer(streamOutput.stream);
}
export async function uploadCDNFile(namespace: CDNNamespace, key: string, data: Buffer): Promise<void> {
@ -131,8 +137,13 @@ export async function bulkDeleteCdnFiles(namespace: CDNNamespace, keys: string[]
}));
}
export function streamFileToResponse(response: Response, stream: Readable, headers: Record<string, string> = {}): void {
export function streamFileToResponse(response: Response, stream: Readable, size: number | null, headers: Record<string, string> = {}): void {
response.setHeaders(new Headers(headers));
if (size !== null) {
response.setHeader('Content-Length', size);
}
Stream.pipeline(stream, response, (err) => {
if (err) {
logger.error('Error with response stream: ' + err.message);

View File

@ -23,7 +23,7 @@ npdi.get('/p01/data/1/:bossAppId/:dataId/:fileHash', async (request, response) =
throw new Error('File not found in CDN');
}
return streamFileToResponse(response, fileStream, {
return streamFileToResponse(response, fileStream.stream, fileStream.size, {
// * The misspelling here is intentional, it's what the official server sets
'Content-Type': 'applicatoin/octet-stream',
'Content-Disposition': 'attachment',

View File

@ -35,7 +35,7 @@ npdl.get([
return;
}
return streamFileToResponse(response, readStream, {
return streamFileToResponse(response, readStream.stream, readStream.size, {
'Last-Modified': new Date(Number(file.updated)).toUTCString()
});
});