Skip to content

Commit ea890e5

Browse files
authored
Merge pull request #140 from wchaws/dev2
feat: add strip-metadata action api
2 parents a2d2a11 + be0f2c6 commit ea890e5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ResizeAction } from './resize';
1919
import { RotateAction } from './rotate';
2020
import { RoundedCornersAction } from './rounded-corners';
2121
import { SharpenAction } from './sharpen';
22+
import { StripMetadataAction } from './strip-metadata';
2223
import { WatermarkAction } from './watermark';
2324

2425
export interface IImageInfo {
@@ -194,6 +195,7 @@ ImageProcessor.getInstance().register(
194195
new WatermarkAction(),
195196
new InfoAction(),
196197
new CgifAction(),
198+
new StripMetadataAction(),
197199
);
198200

199201

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ReadOnly, IActionOpts, IProcessContext } from '..';
2+
import { BaseImageAction } from './_base';
3+
4+
export class StripMetadataAction extends BaseImageAction {
5+
public readonly name: string = 'strip-metadata';
6+
7+
validate(_: string[]): ReadOnly<IActionOpts> {
8+
return {};
9+
}
10+
process(_1: IProcessContext, _2: string[]): Promise<void> {
11+
return Promise.resolve();
12+
}
13+
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ test('f.jpg?x-oss-process=image/resize,w_100/auto-orient,0', async () => {
238238
expect(ctx.headers['Last-Modified']).toBe('fake-last-modified');
239239
});
240240

241+
test('f.jpg?x-oss-process=image/strip-metadata', async () => {
242+
const ctx = await ImageProcessor.getInstance().newContext('f.jpg', 'image/strip-metadata'.split('/'), fixtureStore);
243+
const { data } = await ImageProcessor.getInstance().process(ctx);
244+
const metadata = await sharp(data).metadata();
245+
246+
expect(ctx.metadata.exif).not.toBeUndefined();
247+
expect(metadata.exif).toBeUndefined();
248+
});
249+
241250
test('f.jpg?x-oss-process=image/resize,w_100/auto-orient,1', async () => {
242251
const ctx = await ImageProcessor.getInstance().newContext('f.jpg', 'image/resize,w_100/auto-orient,1'.split('/'), fixtureStore);
243252
const { data, type } = await ImageProcessor.getInstance().process(ctx);

0 commit comments

Comments
 (0)