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;
@Column('boolean', {
default: false,
})
public deeplIsPro: boolean;
@Column('varchar', {
length: 128,
nullable: true,

View file

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

View file

@ -58,7 +58,6 @@ export const paramDef = {
summalyProxy: { type: 'string', nullable: true },
translationService: { type: 'string', nullable: true, enum: [null, ...Object.values(TranslationService)] },
deeplAuthKey: { type: 'string', nullable: true },
deeplIsPro: { type: 'boolean' },
libreTranslateAuthKey: { type: 'string', nullable: true },
libreTranslateEndpoint: { type: 'string', nullable: true },
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 === '') {
set.libreTranslateEndpoint = null;

View file

@ -139,7 +139,11 @@ export default define(meta, paramDef, async (ps, user) => {
params.append('target_lang', targetLang);
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, {
method: 'POST',

View file

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