Skip to content

Commit f1b363a

Browse files
committed
feat: support new api endpoint
1 parent ecc5007 commit f1b363a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

scripts/bundle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ function generateInfo() {
3535
title: 'A Translator',
3636
value: 'a-translator',
3737
},
38+
{
39+
title: 'A Translator (Global)',
40+
value: 'a-translator-cf',
41+
},
3842
...(process.env.NODE_ENV === 'development'
3943
? [
4044
{

src/api.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import { RequestCallbackResponse, RequestObject } from '../types/global'
1+
import {
2+
RequestCallbackResponse,
3+
RequestObject,
4+
validProvider,
5+
} from '../types/global'
26

37
export class Api {
4-
constructor(
5-
private provider: 'deepl' | 'a-translator' | 'local',
6-
private token: string,
7-
) {}
8+
constructor(private provider: validProvider | null, private token: string) {}
89

910
private get baseUrl(): string {
1011
switch (this.provider) {
1112
case 'deepl':
1213
return 'https://api.deepl.com'
1314
case 'a-translator':
1415
return 'https://a-translator-api.nerdynerd.org'
16+
case 'a-translator-cf':
17+
return 'https://a-translator-api-cf.nerdynerd.org'
1518
case 'local':
1619
return 'http://localhost:1337'
20+
default:
21+
return 'https://a-translator-api.nerdynerd.org'
1722
}
1823
}
1924

@@ -32,7 +37,7 @@ export class Api {
3237
url,
3338
header: {
3439
'Content-Type': 'application/x-www-form-urlencoded',
35-
'User-Agent': 'sub-deepl-bob/' + process.env.__VERSION__,
40+
'User-Agent': 'a-translator-bob/' + process.env.__VERSION__,
3641
},
3742
body,
3843
})

types/global.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface RequestCallbackResponse<T = Record<string, unknown>> {
5151

5252
interface $option {
5353
token: string
54-
provider: 'deepl' | 'a-translator' | 'local'
54+
provider: validProvider | null
5555
formality: 'default' | 'more' | 'less'
5656
}
5757

@@ -61,3 +61,5 @@ declare global {
6161
const $http: $http
6262
const $option: $option
6363
}
64+
65+
type validProvider = 'deepl' | 'a-translator' | 'a-translator-cf' | 'local'

0 commit comments

Comments
 (0)