From 3ac0585c5c02ced00732a38725e99c624d4c01ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20F=C3=BCl=C3=B6p?= Date: Sun, 19 Jun 2022 16:47:40 +0000 Subject: [PATCH] :adhesive_bandage: Address Sonar code smell report findings --- src/mixins/NextcloudMixin.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mixins/NextcloudMixin.js b/src/mixins/NextcloudMixin.js index cb827a90..bdbe753e 100644 --- a/src/mixins/NextcloudMixin.js +++ b/src/mixins/NextcloudMixin.js @@ -59,10 +59,11 @@ export default { }, /* HTTP headers for Nextcloud API requests */ headers() { + const authBase = `${this.username}:${this.password}`; return { 'OCS-APIREQUEST': true, Accept: 'application/json', - Authorization: `Basic ${window.btoa(`${this.username}:${this.password}`)}`, + Authorization: `Basic ${window.btoa(authBase)}`, }; }, /* TTL for data delivered by the capabilities endpoint, ms */ @@ -78,9 +79,6 @@ export default { /* Nextcloud API endpoints */ endpoint(id) { switch (id) { - case 'capabilities': - default: - return `${this.hostname}/ocs/v1.php/cloud/capabilities`; case 'user': return `${this.hostname}/ocs/v1.php/cloud/users/${this.username}`; case 'userstatus': @@ -89,6 +87,9 @@ export default { return `${this.hostname}/ocs/v2.php/apps/serverinfo/api/v1/info`; case 'notifications': return `${this.hostname}/ocs/v2.php/apps/notifications/api/v2/notifications`; + case 'capabilities': + default: + return `${this.hostname}/ocs/v1.php/cloud/capabilities`; } }, /* Helper for widgets to terminate {fetchData} early */ @@ -172,14 +173,14 @@ export default { convertBytes(bytes, decimals = 2, formatHtml = true) { const formatted = convertBytes(bytes, decimals).toString(); if (!formatHtml) return formatted; - const m = formatted.match(/(-?[0-9]+)((\.[0-9]+)?\s(([KMGTPEZY]B|Bytes)))/); + const m = formatted.match(/(-?\d+)((\.\d+)?\s(([KMGTPEZY]B|Bytes)))/); return `${m[1]}${m[2]}`; }, /* Add additional formatting to {MiscHelpers.formatNumber()} */ formatNumber(number, decimals = 1, formatHtml = true) { const formatted = formatNumber(number, decimals).toString(); if (!formatHtml) return formatted; - const m = formatted.match(/([0-9]+)((\.[0-9]+)?([KMBT]?))/); + const m = formatted.match(/(\d+)((\.\d+)?([KMBT]?))/); return `${m[1]}${m[2]}`; }, /* Format a number as percentage value */