mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-04-26 00:13:57 -05:00
Merge branch 'dev' into feat/clean-cec
This commit is contained in:
commit
36be92449b
6
.github/workflows/docker.yml
vendored
6
.github/workflows/docker.yml
vendored
|
|
@ -9,7 +9,7 @@ env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
IMAGE_NAME: ${{ github.repository }}
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
DEFAULT_BRANCH: ${{ format('refs/heads/{0}', github.event.repository.default_branch) }}
|
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:
|
jobs:
|
||||||
build-publish-amd64:
|
build-publish-amd64:
|
||||||
|
|
@ -41,7 +41,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
tags: |
|
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=raw,value=edge,enable=${{ github.ref == 'refs/heads/dev' }}
|
||||||
type=sha
|
type=sha
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
tags: |
|
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=raw,value=edge-arm,enable=${{ github.ref == 'refs/heads/dev' }}
|
||||||
type=sha,suffix=-arm
|
type=sha,suffix=-arm
|
||||||
|
|
||||||
|
|
|
||||||
25
src/cdn.ts
25
src/cdn.ts
|
|
@ -38,7 +38,7 @@ function buildLocalCDNPath(fullKey: string): string {
|
||||||
return path.join(config.cdn.disk_path, fullKey);
|
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);
|
const fullKey = buildKey(namespace, key);
|
||||||
|
|
||||||
if (!s3) {
|
if (!s3) {
|
||||||
|
|
@ -49,7 +49,10 @@ export async function getCDNFileAsStream(namespace: CDNNamespace, key: string):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs.createReadStream(filePath);
|
return {
|
||||||
|
stream: fs.createReadStream(filePath),
|
||||||
|
size: fileInfo.size
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await s3.send(new GetObjectCommand({
|
const response = await s3.send(new GetObjectCommand({
|
||||||
|
|
@ -61,15 +64,18 @@ export async function getCDNFileAsStream(namespace: CDNNamespace, key: string):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Body;
|
return {
|
||||||
|
stream: response.Body,
|
||||||
|
size: response.ContentLength ?? null
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCDNFileAsBuffer(namespace: CDNNamespace, key: string): Promise<Buffer | null> {
|
export async function getCDNFileAsBuffer(namespace: CDNNamespace, key: string): Promise<Buffer | null> {
|
||||||
const stream = await getCDNFileAsStream(namespace, key);
|
const streamOutput = await getCDNFileAsStream(namespace, key);
|
||||||
if (!stream) {
|
if (!streamOutput) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return bufferConsumer(stream);
|
return bufferConsumer(streamOutput.stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadCDNFile(namespace: CDNNamespace, key: string, data: Buffer): Promise<void> {
|
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));
|
response.setHeaders(new Headers(headers));
|
||||||
|
|
||||||
|
if (size !== null) {
|
||||||
|
response.setHeader('Content-Length', size);
|
||||||
|
}
|
||||||
|
|
||||||
Stream.pipeline(stream, response, (err) => {
|
Stream.pipeline(stream, response, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error('Error with response stream: ' + err.message);
|
logger.error('Error with response stream: ' + err.message);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ npdi.get('/p01/data/1/:bossAppId/:dataId/:fileHash', async (request, response) =
|
||||||
throw new Error('File not found in CDN');
|
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
|
// * The misspelling here is intentional, it's what the official server sets
|
||||||
'Content-Type': 'applicatoin/octet-stream',
|
'Content-Type': 'applicatoin/octet-stream',
|
||||||
'Content-Disposition': 'attachment',
|
'Content-Disposition': 'attachment',
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ npdl.get([
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return streamFileToResponse(response, readStream, {
|
return streamFileToResponse(response, readStream.stream, readStream.size, {
|
||||||
'Last-Modified': new Date(Number(file.updated)).toUTCString()
|
'Last-Modified': new Date(Number(file.updated)).toUTCString()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user