server: remove deeplIsPro setting

This setting is unnecessary because DeepL free keys can be detected
easily according to <https://www.deepl.com/docs-api/api-access/authentication/>:
> DeepL API Free authentication keys can be identified easily by the suffix ":fx"

Changelog: Removed
This commit is contained in:
Johann150 2022-11-27 11:58:01 +01:00
parent 9fd23b5dae
commit 8130a2a9b1
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
6 changed files with 17 additions and 22 deletions

View file

@ -0,0 +1,12 @@
export class detectDeeplPro1669545702493 {
name = 'detectDeeplPro1669545702493';
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "deeplIsPro"`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "deeplIsPro" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`UPDATE "meta" SET "deeplIsPro" = true WHERE "deeplAuthKey" IS NOT NULL AND "deeplAuthKey" NOT LIKE '%:fx'`);
}
}

View file

@ -316,11 +316,6 @@ export class Meta {
}) })
public deeplAuthKey: string | null; public deeplAuthKey: string | null;
@Column('boolean', {
default: false,
})
public deeplIsPro: boolean;
@Column('varchar', { @Column('varchar', {
length: 128, length: 128,
nullable: true, nullable: true,

View file

@ -280,10 +280,6 @@ export const meta = {
type: 'string', type: 'string',
optional: true, nullable: true, optional: true, nullable: true,
}, },
deeplIsPro: {
type: 'boolean',
optional: true, nullable: false,
},
libreTranslateEndpoint: { libreTranslateEndpoint: {
type: 'string', type: 'string',
optional: true, nullable: true, optional: true, nullable: true,
@ -382,7 +378,6 @@ export default define(meta, paramDef, async (ps, me) => {
translatorAvailable: translatorAvailable(instance), translatorAvailable: translatorAvailable(instance),
translationService: instance.translationService, translationService: instance.translationService,
deeplAuthKey: instance.deeplAuthKey, deeplAuthKey: instance.deeplAuthKey,
deeplIsPro: instance.deeplIsPro,
libreTranslateEndpoint: instance.libreTranslateEndpoint, libreTranslateEndpoint: instance.libreTranslateEndpoint,
libreTranslateAuthKey: instance.libreTranslateAuthKey, libreTranslateAuthKey: instance.libreTranslateAuthKey,
}; };

View file

@ -58,7 +58,6 @@ export const paramDef = {
summalyProxy: { type: 'string', nullable: true }, summalyProxy: { type: 'string', nullable: true },
translationService: { type: 'string', nullable: true, enum: [null, ...Object.values(TranslationService)] }, translationService: { type: 'string', nullable: true, enum: [null, ...Object.values(TranslationService)] },
deeplAuthKey: { type: 'string', nullable: true }, deeplAuthKey: { type: 'string', nullable: true },
deeplIsPro: { type: 'boolean' },
libreTranslateAuthKey: { type: 'string', nullable: true }, libreTranslateAuthKey: { type: 'string', nullable: true },
libreTranslateEndpoint: { type: 'string', nullable: true }, libreTranslateEndpoint: { type: 'string', nullable: true },
enableTwitterIntegration: { type: 'boolean' }, enableTwitterIntegration: { type: 'boolean' },
@ -378,10 +377,6 @@ export default define(meta, paramDef, async (ps, me) => {
} }
} }
if (ps.deeplIsPro !== undefined) {
set.deeplIsPro = ps.deeplIsPro;
}
if (ps.libreTranslateEndpoint !== undefined) { if (ps.libreTranslateEndpoint !== undefined) {
if (ps.libreTranslateEndpoint === '') { if (ps.libreTranslateEndpoint === '') {
set.libreTranslateEndpoint = null; set.libreTranslateEndpoint = null;

View file

@ -139,7 +139,11 @@ export default define(meta, paramDef, async (ps, user) => {
params.append('target_lang', targetLang); params.append('target_lang', targetLang);
if (sourceLang) params.append('source_lang', sourceLang); if (sourceLang) params.append('source_lang', sourceLang);
const endpoint = instance.deeplIsPro ? 'https://api.deepl.com/v2/translate' : 'https://api-free.deepl.com/v2/translate'; // From the DeepL API docs:
//> DeepL API Free authentication keys can be identified easily by the suffix ":fx"
const endpoint = instance.deeplAuthKey.endsWith(':fx')
? 'https://api-free.deepl.com/v2/translate'
: 'https://api.deepl.com/v2/translate';
const res = await fetch(endpoint, { const res = await fetch(endpoint, {
method: 'POST', method: 'POST',

View file

@ -12,9 +12,6 @@
</FormSelect> </FormSelect>
<template v-if="translationService === 'deepl'"> <template v-if="translationService === 'deepl'">
<FormSwitch v-model="deeplIsPro" class="_formBlock">
<template #label>{{ i18n.ts._translationService._deepl.pro }}</template>
</FormSwitch>
<FormInput v-model="deeplAuthKey" class="_formBlock"> <FormInput v-model="deeplAuthKey" class="_formBlock">
<template #prefix><i class="fas fa-key"></i></template> <template #prefix><i class="fas fa-key"></i></template>
<template #label>{{ i18n.ts._translationService._deepl.authKey }}</template> <template #label>{{ i18n.ts._translationService._deepl.authKey }}</template>
@ -46,7 +43,6 @@ import { fetchInstance } from '@/instance';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
let translationService: string = $ref('none'); let translationService: string = $ref('none');
let deeplIsPro: boolean = $ref(false);
let deeplAuthKey: string = $ref(''); let deeplAuthKey: string = $ref('');
let libreTranslateEndpoint: string = $ref(''); let libreTranslateEndpoint: string = $ref('');
let libreTranslateAuthKey: string = $ref(''); let libreTranslateAuthKey: string = $ref('');
@ -54,7 +50,6 @@ let libreTranslateAuthKey: string = $ref('');
async function init(): Promise<void> { async function init(): Promise<void> {
const meta = await os.api('admin/meta'); const meta = await os.api('admin/meta');
translationService = meta.translationService ?? 'none'; translationService = meta.translationService ?? 'none';
deeplIsPro = meta.deeplIsPro;
deeplAuthKey = meta.deeplAuthKey; deeplAuthKey = meta.deeplAuthKey;
libreTranslateEndpoint = meta.libreTranslateEndpoint; libreTranslateEndpoint = meta.libreTranslateEndpoint;
libreTranslateAuthKey = meta.libreTranslateAuthKey; libreTranslateAuthKey = meta.libreTranslateAuthKey;
@ -64,7 +59,6 @@ function save(): void {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
translationService: translationService === 'none' ? null : translationService, translationService: translationService === 'none' ? null : translationService,
deeplAuthKey, deeplAuthKey,
deeplIsPro,
libreTranslateEndpoint, libreTranslateEndpoint,
libreTranslateAuthKey, libreTranslateAuthKey,
}).then(() => { }).then(() => {