From ad1bc6fa6f2b7028dea1e4418a85f07a4f27d482 Mon Sep 17 00:00:00 2001 From: Grigory Vodyanov Date: Mon, 16 Dec 2024 20:05:58 +0100 Subject: [PATCH] fix: remove plain text endpoint call and decode on frontend Signed-off-by: Grigory Vodyanov --- src/components/ThreadEnvelope.vue | 7 ++++--- src/components/TranslationModal.vue | 4 +++- src/service/plainTextService.js | 20 -------------------- src/util/text.js | 2 +- 4 files changed, 8 insertions(+), 25 deletions(-) delete mode 100644 src/service/plainTextService.js diff --git a/src/components/ThreadEnvelope.vue b/src/components/ThreadEnvelope.vue index 4492acbdff..bdc4963cdc 100644 --- a/src/components/ThreadEnvelope.vue +++ b/src/components/ThreadEnvelope.vue @@ -314,7 +314,7 @@ import { mapStores } from 'pinia' import moment from '@nextcloud/moment' import { translateTagDisplayName } from '../util/tag.js' import { FOLLOW_UP_TAG_LABEL } from '../store/constants.js' -import { getPlainText } from '../service/plainTextService.js' +import { Text, toPlain } from '../util/text.js' // Ternary loading state const LOADING_DONE = 0 @@ -881,8 +881,9 @@ export default { }, async handleHtmlBodyMessages() { if (this.message.hasHtmlBody) { - const message = await getPlainText(this.message.databaseId) - this.plainTextBody = message.body + let text = new Text('html', this.message.body) + text = toPlain(text) + this.plainTextBody = text.value } else { this.plainTextBody = this.message.body } diff --git a/src/components/TranslationModal.vue b/src/components/TranslationModal.vue index d23be84f50..8223f1bce8 100644 --- a/src/components/TranslationModal.vue +++ b/src/components/TranslationModal.vue @@ -44,12 +44,14 @@ @@ -213,7 +215,7 @@ export default { async translateMessage(sourceLanguage = null) { try { this.isLoading = true - const response = await translateText(this.message, sourceLanguage, this.selectedTo?.id) + const response = await translateText(this.message.trim(), sourceLanguage, this.selectedTo?.id) this.translatedMessage = response.data.ocs.data.text } catch (error) { console.error(error) diff --git a/src/service/plainTextService.js b/src/service/plainTextService.js deleted file mode 100644 index 87f85d821a..0000000000 --- a/src/service/plainTextService.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' -import { convertAxiosError } from '../errors/convert.js' - -export async function getPlainText(id) { - const url = generateUrl('/apps/mail/api/messages/{id}/body?plain=true', { - id, - }) - - const response = await axios.get(url).catch((error) => { - throw convertAxiosError(error) - }) - - return response.data -} diff --git a/src/util/text.js b/src/util/text.js index 5d32878a40..fb4f86cef6 100644 --- a/src/util/text.js +++ b/src/util/text.js @@ -10,7 +10,7 @@ import { convert } from 'html-to-text' /** * @type {Text} */ -class Text { +export class Text { constructor(format, value) { this.format = format