Skip to content

Commit 47e47e3

Browse files
committed
fix: missing bucket name for cache key
1 parent 3400f78 commit 47e47e3

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

source/new-image-handler/.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Dockerfile*
55
node_modules
66
coverage
77
test-reports
8-
**/*.md
8+
**/*.md
9+
**/*.bin

source/new-image-handler/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ app.use(errorHandler());
3939
app.use(bodyParser());
4040
app.use(koaCash({
4141
setCachedHeader: true,
42+
hash(ctx) {
43+
return ctx.headers['x-bucket'] + ctx.request.url;
44+
},
4245
get: (key) => {
4346
return Promise.resolve(lruCache.get(key));
4447
},

source/new-image-handler/src/store.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export class LocalStore implements IBufferStore {
4646
type: filetype(p),
4747
headers: {
4848
'Etag': 'fake-etag',
49-
'Last-Modified': 'fake-last-modified',
50-
'Cache-Control': 'no-cache',
49+
'Last-Modified': 'Wed, 21 Oct 2014 07:28:00 GMT',
50+
'Cache-Control': 'max-age',
5151
},
5252
};
5353
}
@@ -72,14 +72,14 @@ export class S3Store implements IBufferStore {
7272
}).promise();
7373

7474
if (Buffer.isBuffer(res.Body)) {
75+
const headers: IHttpHeaders = {};
76+
if (res.ETag) { headers.Etag = res.ETag; }
77+
if (res.LastModified) { headers['Last-Modified'] = res.LastModified; }
78+
if (res.CacheControl) { headers['Cache-Control'] = res.CacheControl; }
7579
return {
7680
buffer: res.Body as Buffer,
7781
type: res.ContentType ?? '',
78-
headers: {
79-
'Etag': res.ETag,
80-
'Last-Modified': res.LastModified,
81-
'Cache-Control': res.CacheControl,
82-
},
82+
headers,
8383
};
8484
};
8585
throw new Error('S3 response body is not a Buffer type');

source/new-image-handler/test/index-lambda.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ test('index-lambda.ts example.jpg?x-oss-process=image/resize,w_100/quality,q_50'
7373
expect(res.isBase64Encoded).toBeTruthy();
7474
expect(res.statusCode).toBe(200);
7575
expect(res.headers['Content-Type']).toBe('image/jpeg');
76-
expect(res.headers['Last-Modified']).toBe('fake-last-modified');
77-
expect(res.headers['Cache-Control']).toBe('no-cache');
76+
expect(res.headers['Last-Modified']).toBe('Wed, 21 Oct 2014 07:28:00 GMT');
77+
expect(res.headers['Cache-Control']).toBe('max-age');
7878

7979
const metadata = await sharp(Buffer.from(res.body, 'base64')).metadata();
8080

source/new-image-handler/test/processor/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ test('f.jpg?x-oss-process=image/resize,w_100/auto-orient,0', async () => {
255255
expect(type).toBe('image/jpeg');
256256
expect(metadata.width).toBe(100);
257257
expect(metadata.height).toBe(78);
258-
expect(ctx.headers['Last-Modified']).toBe('fake-last-modified');
258+
expect(ctx.headers['Last-Modified']).toBe('Wed, 21 Oct 2014 07:28:00 GMT');
259259
});
260260

261261
test('f.jpg?x-oss-process=image/strip-metadata', async () => {

0 commit comments

Comments
 (0)