add configurable timeout for note translations

This commit is contained in:
Hazelnoot 2025-05-12 00:23:59 -04:00
parent 00cfeca3d7
commit e7ee2cc398
9 changed files with 66 additions and 3 deletions

8
locales/index.d.ts vendored
View file

@ -13045,6 +13045,14 @@ export interface Locale extends ILocale {
* Note: the bubble timeline is hidden by default, and must be enabled via roles.
*/
"bubbleTimelineMustBeEnabled": string;
/**
* Translation timeout
*/
"translationTimeoutLabel": string;
/**
* Timeout in milliseconds for translation API requests (default 5000)
*/
"translationTimeoutCaption": string;
}
declare const locales: {
[lang: string]: Locale;

View file

@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class AddMetaTranslationTimeout1747023091463 {
name = 'AddMetaTranslationTimeout1747023091463'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "translationTimeout" integer NOT NULL DEFAULT '5000'`);
await queryRunner.query(`COMMENT ON COLUMN "meta"."translationTimeout" IS 'Timeout in milliseconds for translation API requests'`);
}
async down(queryRunner) {
await queryRunner.query(`COMMENT ON COLUMN "meta"."translationTimeout" IS 'Timeout in milliseconds for translation API requests'`);
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "translationTimeout"`);
}
}

View file

@ -382,6 +382,12 @@ export class MiMeta {
})
public swPrivateKey: string | null;
@Column('integer', {
default: 5000,
comment: 'Timeout in milliseconds for translation API requests',
})
public translationTimeout: number;
@Column('varchar', {
length: 1024,
nullable: true,

View file

@ -445,6 +445,10 @@ export const meta = {
type: 'string',
optional: false, nullable: true,
},
translationTimeout: {
type: 'number',
optional: false, nullable: false,
},
deeplAuthKey: {
type: 'string',
optional: false, nullable: true,
@ -723,6 +727,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
objectStorageUseProxy: instance.objectStorageUseProxy,
objectStorageSetPublicRead: instance.objectStorageSetPublicRead,
objectStorageS3ForcePathStyle: instance.objectStorageS3ForcePathStyle,
translationTimeout: instance.translationTimeout,
deeplAuthKey: instance.deeplAuthKey,
deeplIsPro: instance.deeplIsPro,
deeplFreeMode: instance.deeplFreeMode,

View file

@ -103,6 +103,7 @@ export const paramDef = {
type: 'string',
},
},
translationTimeout: { type: 'number' },
deeplAuthKey: { type: 'string', nullable: true },
deeplIsPro: { type: 'boolean' },
deeplFreeMode: { type: 'boolean' },
@ -560,6 +561,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.objectStorageS3ForcePathStyle = ps.objectStorageS3ForcePathStyle;
}
if (ps.translationTimeout !== undefined) {
set.translationTimeout = ps.translationTimeout;
}
if (ps.deeplAuthKey !== undefined) {
if (ps.deeplAuthKey === '') {
set.deeplAuthKey = null;

View file

@ -116,6 +116,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
Accept: 'application/json, */*',
},
body: params.toString(),
timeout: this.serverSettings.translationTimeout,
});
if (this.serverSettings.deeplAuthKey) {
const json = (await res.json()) as {
@ -165,6 +166,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
format: 'text',
api_key: this.serverSettings.libreTranslateKey ?? '',
}),
timeout: this.serverSettings.translationTimeout,
});
const json = (await res.json()) as {

View file

@ -8,6 +8,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<div class="_spacer" style="--MI_SPACER-w: 700px; --MI_SPACER-min: 16px; --MI_SPACER-max: 32px;">
<FormSuspense :p="init">
<div class="_gaps_m">
<MkInput v-model="translationTimeout" type="number" debounce>
<template #label>{{ i18n.ts.translationTimeoutLabel }}</template>
<template #caption>{{ i18n.ts.translationTimeoutCaption }}</template>
</MkInput>
<MkFolder>
<template #label>DeepL Translation</template>
@ -57,7 +62,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { ref, computed, watch } from 'vue';
import MkInput from '@/components/MkInput.vue';
import MkButton from '@/components/MkButton.vue';
import MkSwitch from '@/components/MkSwitch.vue';
@ -69,6 +74,7 @@ import { i18n } from '@/i18n.js';
import { definePage } from '@/page.js';
import MkFolder from '@/components/MkFolder.vue';
const translationTimeout = ref(0);
const deeplAuthKey = ref<string | null>('');
const deeplIsPro = ref<boolean>(false);
const deeplFreeMode = ref<boolean>(false);
@ -78,12 +84,20 @@ const libreTranslateKey = ref<string | null>('');
async function init() {
const meta = await misskeyApi('admin/meta');
translationTimeout.value = meta.translationTimeout;
deeplAuthKey.value = meta.deeplAuthKey;
deeplIsPro.value = meta.deeplIsPro;
deeplFreeMode.value = meta.deeplFreeMode;
deeplFreeInstance.value = meta.deeplFreeInstance;
libreTranslateURL.value = meta.libreTranslateURL;
libreTranslateKey.value = meta.libreTranslateKey;
watch(translationTimeout, async newValue => {
await os.apiWithDialog('admin/update-meta', {
translationTimeout: newValue,
});
await os.promiseDialog(fetchInstance(true));
});
}
function save_deepl() {
@ -93,7 +107,7 @@ function save_deepl() {
deeplFreeMode: deeplFreeMode.value,
deeplFreeInstance: deeplFreeInstance.value,
}).then(() => {
fetchInstance(true);
os.promiseDialog(fetchInstance(true));
});
}
@ -102,7 +116,7 @@ function save_libre() {
libreTranslateURL: libreTranslateURL.value,
libreTranslateKey: libreTranslateKey.value,
}).then(() => {
fetchInstance(true);
os.promiseDialog(fetchInstance(true));
});
}

View file

@ -9249,6 +9249,7 @@ export type operations = {
enableReactionsBuffering: boolean;
notesPerOneAd: number;
backgroundImageUrl: string | null;
translationTimeout: number;
deeplAuthKey: string | null;
deeplIsPro: boolean;
deeplFreeMode: boolean;
@ -12159,6 +12160,7 @@ export type operations = {
maintainerName?: string | null;
maintainerEmail?: string | null;
langs?: string[];
translationTimeout?: number;
deeplAuthKey?: string | null;
deeplIsPro?: boolean;
deeplFreeMode?: boolean;

View file

@ -564,3 +564,6 @@ wordMuteTestNoMatch: "Text does not match any patterns."
bubbleTimeline: "Bubble timeline"
bubbleTimelineDescription: "Choose which instances should be displayed in the bubble."
bubbleTimelineMustBeEnabled: "Note: the bubble timeline is hidden by default, and must be enabled via roles."
translationTimeoutLabel: "Translation timeout"
translationTimeoutCaption: "Timeout in milliseconds for translation API requests (default 5000)"