mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-03-21 17:34:19 -05:00
Merge branch 'feat/clean-cec' of github.com:PretendoNetwork/BOSS into feat/clean-cec
This commit is contained in:
commit
ea6b47d652
6
.github/workflows/docker.yml
vendored
6
.github/workflows/docker.yml
vendored
|
|
@ -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
|
||||
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
|
||||
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> {
|
||||
|
|
@ -134,8 +140,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);
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user