feat: proxy GetObject from Telegram CDN for real S3 client compatibility

- Add proxyS3Get config (PROXY_S3_GET env, default true) to env.ts
- Proxy handleGetObject and handleGetMultipartObject: fetch from Telegram
  CDN and return 200 with streaming body instead of 302 redirect
- Real S3 clients (AWS SDK v3) expect 200+body on GetObject, not redirect
- Legacy 302 redirect path preserved when proxyS3Get=false
- Updated production-e2e: GetObject asserts 200 with body content
- Updated s3-sdk.test.ts: GetObject asserts 200 with body (removed try/catch)
- Cleaned up unused multipart imports in s3-sdk.test.ts

All 49 tests pass (29 production-e2e + 20 s3-sdk).
This commit is contained in:
asepharyana
2026-07-07 02:54:51 +07:00
parent f88ac1a124
commit 06f93e30f6
4 changed files with 94 additions and 32 deletions
+13 -6
View File
@@ -236,10 +236,12 @@ describe('S3 API (production, SigV4)', () => {
expect(Number(r.headers.get('content-length'))).toBeGreaterThan(0);
});
it('GetObject (GET /{bucket}/{key}) — redirects to Telegram', async () => {
it('GetObject (GET /{bucket}/{key}) — proxies content from Telegram', async () => {
const r = await s3Request('GET', `/${bucketName}/test-file.txt`);
expect([200, 302]).toContain(r.status);
if (r.status === 302) expect(r.headers.get('location')).toBeTruthy();
expect(r.status).toBe(200);
const text = await r.text();
expect(text).toContain('hello s3');
expect(r.headers.get('content-type')).toMatch(/text|octet/);
});
it('ListObjectsV1 (GET /{bucket})', async () => {
@@ -337,12 +339,17 @@ describe('S3 API (production, SigV4)', () => {
const presignedUrl = `${BASE_URL}/${bucketName}/presigned-test.txt?${sp.toString()}`;
const r = await fetch(presignedUrl);
// Presigned URL should return 302 (redirect to Telegram) or 403 (auth fail)
// Presigned URL: 200 (proxied body), 302 (redirect), or 403 (auth fail)
if (r.status === 403) {
console.warn('⚠️ Presigned URL returned 403 — verification mismatch');
}
expect([302, 403]).toContain(r.status);
if (r.status === 302) expect(r.headers.get('location')).toBeTruthy();
expect([200, 302, 403]).toContain(r.status);
if (r.status === 200) {
const text = await r.text();
expect(text).toContain('presigned content');
} else if (r.status === 302) {
expect(r.headers.get('location')).toBeTruthy();
}
});
it('Delete bucket — must be empty first', async () => {