Skip to content

Commit d5c3edb

Browse files
committed
Add useragent and ref param
1 parent 9292b23 commit d5c3edb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { Response } from 'cross-fetch';
88

99
const SPECIAL_FUNCTION_REGEX: RegExp = /['"]__BEGINFUNCTION__(.*?)__ENDFUNCTION__['"]/g;
1010

11+
const USER_AGENT = `quickchart-js/3.1.0`;
12+
1113
interface PostData {
1214
chart: string;
1315
width?: number;
@@ -40,7 +42,10 @@ function doStringify(chartConfig: ChartConfiguration): string | undefined {
4042
function postJson(url: string, payload: PostData): Promise<Response> {
4143
return fetch(url, {
4244
method: 'POST',
43-
headers: { 'Content-Type': 'application/json' },
45+
headers: {
46+
'User-Agent': USER_AGENT,
47+
'Content-Type': 'application/json',
48+
},
4449
body: JSON.stringify(payload),
4550
});
4651
}
@@ -139,6 +144,7 @@ class QuickChart {
139144
ret.searchParams.append('c', this.chart!);
140145
ret.searchParams.append('w', String(this.width));
141146
ret.searchParams.append('h', String(this.height));
147+
ret.searchParams.append('ref', 'qc-js');
142148
if (this.devicePixelRatio !== 1.0) {
143149
ret.searchParams.append('devicePixelRatio', String(this.devicePixelRatio));
144150
}

0 commit comments

Comments
 (0)