Skip to content

Commit b1b65d5

Browse files
committed
feat: add support for deepl free api token
1 parent 0b20276 commit b1b65d5

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

scripts/bundle.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ function generateInfo() {
2121
type: 'text',
2222
title: 'Token',
2323
},
24+
{
25+
identifier: 'api',
26+
type: 'menu',
27+
title: 'API',
28+
defaultValue: 'deepl-pro',
29+
menuValues: [
30+
{
31+
title: 'Pro',
32+
value: 'deepl-pro',
33+
},
34+
{
35+
title: 'Free',
36+
value: 'deepl-free',
37+
},
38+
],
39+
},
2440
{
2541
identifier: 'formality',
2642
type: 'menu',

src/api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import {
55
} from '../types/global'
66

77
export class Api {
8-
constructor(private provider: validProvider | null, private token: string) {}
8+
constructor(private provider: validProvider | null, private token: string) { }
99

1010
private get baseUrl(): string {
11-
return 'https://api.deepl.com'
11+
switch (this.provider) {
12+
case 'deepl-pro':
13+
return 'https://api.deepl.com'
14+
15+
default:
16+
return 'https://api-free.deepl.com'
17+
}
1218
}
1319

1420
async request<T = Record<string, unknown>>(

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export function translate(
1313
query: TranslateQuery,
1414
completion: (data: TranslateCompletion) => void,
1515
): void {
16-
const api = new Api('deepl', $option.token)
16+
const api = new Api($option.api, $option.token);
1717

18-
;(async () => {
18+
; (async () => {
1919
const targetLanguage = langMap.get(query.detectTo)
2020

2121
$log.info(`translate to ${targetLanguage}`)

types/global.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface RequestCallbackResponse<T = Record<string, unknown>> {
5252
interface $option {
5353
token: string
5454
formality: 'default' | 'more' | 'less'
55+
api: validProvider
5556
}
5657

5758
declare global {
@@ -61,4 +62,4 @@ declare global {
6162
const $option: $option
6263
}
6364

64-
type validProvider = 'deepl'
65+
type validProvider = 'deepl-pro' | 'deepl-free'

0 commit comments

Comments
 (0)