Skip to content

Commit

Permalink
Merge pull request #171 from wchaws/dev
Browse files Browse the repository at this point in the history
fix: missing bucket name for cache key
  • Loading branch information
wchaws committed Sep 11, 2023
2 parents 3400f78 + 47e47e3 commit 2e1d62b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion source/new-image-handler/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Dockerfile*
node_modules
coverage
test-reports
**/*.md
**/*.md
**/*.bin
3 changes: 3 additions & 0 deletions source/new-image-handler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ app.use(errorHandler());
app.use(bodyParser());
app.use(koaCash({
setCachedHeader: true,
hash(ctx) {
return ctx.headers['x-bucket'] + ctx.request.url;
},
get: (key) => {
return Promise.resolve(lruCache.get(key));
},
Expand Down
14 changes: 7 additions & 7 deletions source/new-image-handler/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class LocalStore implements IBufferStore {
type: filetype(p),
headers: {
'Etag': 'fake-etag',
'Last-Modified': 'fake-last-modified',
'Cache-Control': 'no-cache',
'Last-Modified': 'Wed, 21 Oct 2014 07:28:00 GMT',
'Cache-Control': 'max-age',
},
};
}
Expand All @@ -72,14 +72,14 @@ export class S3Store implements IBufferStore {
}).promise();

if (Buffer.isBuffer(res.Body)) {
const headers: IHttpHeaders = {};
if (res.ETag) { headers.Etag = res.ETag; }
if (res.LastModified) { headers['Last-Modified'] = res.LastModified; }
if (res.CacheControl) { headers['Cache-Control'] = res.CacheControl; }
return {
buffer: res.Body as Buffer,
type: res.ContentType ?? '',
headers: {
'Etag': res.ETag,
'Last-Modified': res.LastModified,
'Cache-Control': res.CacheControl,
},
headers,
};
};
throw new Error('S3 response body is not a Buffer type');
Expand Down
4 changes: 2 additions & 2 deletions source/new-image-handler/test/index-lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ test('index-lambda.ts example.jpg?x-oss-process=image/resize,w_100/quality,q_50'
expect(res.isBase64Encoded).toBeTruthy();
expect(res.statusCode).toBe(200);
expect(res.headers['Content-Type']).toBe('image/jpeg');
expect(res.headers['Last-Modified']).toBe('fake-last-modified');
expect(res.headers['Cache-Control']).toBe('no-cache');
expect(res.headers['Last-Modified']).toBe('Wed, 21 Oct 2014 07:28:00 GMT');
expect(res.headers['Cache-Control']).toBe('max-age');

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

Expand Down
2 changes: 1 addition & 1 deletion source/new-image-handler/test/processor/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ test('f.jpg?x-oss-process=image/resize,w_100/auto-orient,0', async () => {
expect(type).toBe('image/jpeg');
expect(metadata.width).toBe(100);
expect(metadata.height).toBe(78);
expect(ctx.headers['Last-Modified']).toBe('fake-last-modified');
expect(ctx.headers['Last-Modified']).toBe('Wed, 21 Oct 2014 07:28:00 GMT');
});

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

0 comments on commit 2e1d62b

Please sign in to comment.