From fdf3aa3c88a17ad7c6eecf11504888cad84ad701 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Thu, 30 Jan 2025 13:48:29 +0100 Subject: [PATCH 1/2] fix: rename certificateService to .ts Signed-off-by: Maksim Sukharev --- src/components/AdminSettings/TurnServer.vue | 2 +- src/services/{certificateService.js => certificateService.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/services/{certificateService.js => certificateService.ts} (100%) diff --git a/src/components/AdminSettings/TurnServer.vue b/src/components/AdminSettings/TurnServer.vue index 1c1db3d8b7..bc4d31d06d 100644 --- a/src/components/AdminSettings/TurnServer.vue +++ b/src/components/AdminSettings/TurnServer.vue @@ -89,7 +89,7 @@ import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js' import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js' import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' -import { isCertificateValid } from '../../services/certificateService.js' +import { isCertificateValid } from '../../services/certificateService.ts' export default { name: 'TurnServer', diff --git a/src/services/certificateService.js b/src/services/certificateService.ts similarity index 100% rename from src/services/certificateService.js rename to src/services/certificateService.ts From af7f428b8c1584b5f5f61dabe3c3db49c5b246cc Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Thu, 30 Jan 2025 13:53:00 +0100 Subject: [PATCH 2/2] fix: migrate certificateService to .ts Signed-off-by: Maksim Sukharev --- src/services/certificateService.ts | 55 +++++++++++++++--------------- src/types/index.ts | 4 +++ 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/services/certificateService.ts b/src/services/certificateService.ts index 5875e165a1..e31726c741 100644 --- a/src/services/certificateService.ts +++ b/src/services/certificateService.ts @@ -5,46 +5,47 @@ import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' +import type { certificateExpirationParams, certificateExpirationResponse } from '../types/index.ts' + /** * Retrieves the certificate expiration of the specified host * - * @param {string} host The host to check the certificate - * @return {number|null} Null if unable to retrieve the certificates expiration, otherwise the expiration in days (negative if already expired) + * @param host The host to check the certificate */ -const getCertificateExpiration = async (host) => { - try { - const response = await axios.get(generateOcsUrl('apps/spreed/api/v1/certificate/expiration'), { - params: { - host, - }, - }) - - return response.data.ocs.data.expiration_in_days - } catch (error) { - console.error(error) - } - - return null +const getCertificateExpiration = async (host: certificateExpirationParams['host']): certificateExpirationResponse => { + return axios.get(generateOcsUrl('apps/spreed/api/v1/certificate/expiration'), { + params: { + host, + } as certificateExpirationParams, + }) } /** * Checks if the certificate of a host is valid * - * @param {string} host The host to check the certificate + * @param host The host to check the certificate * @return {boolean} true if the certificate is valid, false otherwise */ -const isCertificateValid = async (host) => { - const expiration = await getCertificateExpiration(host) +const isCertificateValid = async (host: certificateExpirationParams['host']): Promise => { + try { + const response = await getCertificateExpiration(host) - if (expiration == null) { - console.warn('Unable to check certificate of', host) - } else if (expiration < 0) { - console.error('Certificate of', host, 'expired') - } else { - console.info('Certificate of', host, 'is valid for', expiration, 'days') + // Null if unable to retrieve the certificates expiration, otherwise the expiration in days (negative if already expired) + const expiration = response.data.ocs.data.expiration_in_days + + if (expiration == null) { + console.warn('Unable to check certificate of', host) + return false + } else if (expiration < 0) { + console.error('Certificate of', host, 'expired') + } else { + console.info('Certificate of', host, 'is valid for', expiration, 'days') + } + return expiration > 0 + } catch (error) { + console.error(error) + return false } - - return expiration > 0 } export { diff --git a/src/types/index.ts b/src/types/index.ts index 36b78b1558..924ed5fa49 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -177,6 +177,10 @@ export type getBotsAdminResponse = ApiResponse export type disableBotResponse = ApiResponse +// Certificate +export type certificateExpirationParams = operations['certificate-get-certificate-expiration']['parameters']['query'] +export type certificateExpirationResponse = ApiResponse + // Federations export type FederationInvite = components['schemas']['FederationInvite'] type FederationInviteRichParameters = {