Skip to content

Commit ed00409

Browse files
authored
Merge pull request #155 from wchaws/dev2
fix: add split1 function to support base64url
2 parents 126ad97 + ba1ef23 commit ed00409

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ export class ActionMask implements IActionMask {
6969
cb(action, this.isEnabled(index), index);
7070
});
7171
}
72-
}
72+
}
73+
74+
export function split1(s: string, sep: string = ',') {
75+
const split = s.split(sep, 1);
76+
return [split[0], s.substring(split[0].length + sep.length)];
77+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as sharp from 'sharp';
22
import { IImageContext } from '.';
33
import { IActionOpts, ReadOnly, InvalidArgument, Features, IProcessContext } from '..';
44
import * as is from '../../is';
5-
import { BaseImageAction } from './_base';
5+
import { BaseImageAction, split1 } from './_base';
66

77
export interface WatermarkOpts extends IActionOpts {
88
text: string;
@@ -69,7 +69,7 @@ export class WatermarkAction extends BaseImageAction {
6969
if ((this.name === param) || (!param)) {
7070
continue;
7171
}
72-
const [k, v] = param.split('_');
72+
const [k, v] = split1(param, '_');
7373
if (k === 'text') {
7474
if (v) {
7575
const buff = Buffer.from(v, 'base64');

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ActionMask } from '../../../src/processor/image/_base';
1+
import { ActionMask, split1 } from '../../../src/processor/image/_base';
22

33
test(`${ActionMask.name} all enabled by default`, () => {
44
const actions = '1 1 1 1 1 1'.split(' ');
@@ -58,4 +58,12 @@ test(`${ActionMask.name} index out of range`, () => {
5858
}).toThrowError(/Index out of range/);
5959
});
6060

61+
test(`${split1.name} split`, () => {
62+
const s = 'text_SG9ZT0xBQkBvZmZjaWFsK0DvvIEjQO-8gSPvvIEj77-l77yBQO-_pe-8gUAj77-l77yB77-l77yBZQ==';
63+
expect(split1(s, '_')).toEqual([
64+
'text',
65+
'SG9ZT0xBQkBvZmZjaWFsK0DvvIEjQO-8gSPvvIEj77-l77yBQO-_pe-8gUAj77-l77yB77-l77yBZQ==',
66+
]);
67+
});
68+
6169

0 commit comments

Comments
 (0)