fixed psychoJS serving

This commit is contained in:
Shaheed Azaad
2025-07-14 00:24:44 +02:00
parent 9fba3becb8
commit cde21e9286
107 changed files with 3974 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
import { randomUUID } from 'crypto';
import { expect, test } from 'vitest';
import 'dotenv/config';
const s3 = new S3Client({
region: 'us-east-1',
endpoint: process.env.S3_ENDPOINT,
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY!,
secretAccessKey: process.env.S3_SECRET_KEY!,
},
forcePathStyle: true,
});
const BUCKET = process.env.S3_BUCKET!;
test('can upload and download a file from S3', async () => {
const key = `test-file-${randomUUID()}.txt`;
const content = 'hello s3 world!';
// Upload
await s3.send(new PutObjectCommand({
Bucket: BUCKET,
Key: key,
Body: content,
}));
// Download
const getObj = await s3.send(new GetObjectCommand({
Bucket: BUCKET,
Key: key,
}));
const downloaded = await streamToString(getObj.Body);
expect(downloaded).toBe(content);
});
function streamToString(stream: any): Promise<string> {
return new Promise((resolve, reject) => {
const chunks: any[] = [];
stream.on('data', (chunk: any) => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
});
}