mirror of https://github.com/Lissy93/dashy.git
🩹 Address Sonar code smell report findings
This commit is contained in:
parent
cf25dbce4a
commit
3ac0585c5c
|
@ -59,10 +59,11 @@ export default {
|
||||||
},
|
},
|
||||||
/* HTTP headers for Nextcloud API requests */
|
/* HTTP headers for Nextcloud API requests */
|
||||||
headers() {
|
headers() {
|
||||||
|
const authBase = `${this.username}:${this.password}`;
|
||||||
return {
|
return {
|
||||||
'OCS-APIREQUEST': true,
|
'OCS-APIREQUEST': true,
|
||||||
Accept: 'application/json',
|
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 */
|
/* TTL for data delivered by the capabilities endpoint, ms */
|
||||||
|
@ -78,9 +79,6 @@ export default {
|
||||||
/* Nextcloud API endpoints */
|
/* Nextcloud API endpoints */
|
||||||
endpoint(id) {
|
endpoint(id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 'capabilities':
|
|
||||||
default:
|
|
||||||
return `${this.hostname}/ocs/v1.php/cloud/capabilities`;
|
|
||||||
case 'user':
|
case 'user':
|
||||||
return `${this.hostname}/ocs/v1.php/cloud/users/${this.username}`;
|
return `${this.hostname}/ocs/v1.php/cloud/users/${this.username}`;
|
||||||
case 'userstatus':
|
case 'userstatus':
|
||||||
|
@ -89,6 +87,9 @@ export default {
|
||||||
return `${this.hostname}/ocs/v2.php/apps/serverinfo/api/v1/info`;
|
return `${this.hostname}/ocs/v2.php/apps/serverinfo/api/v1/info`;
|
||||||
case 'notifications':
|
case 'notifications':
|
||||||
return `${this.hostname}/ocs/v2.php/apps/notifications/api/v2/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 */
|
/* Helper for widgets to terminate {fetchData} early */
|
||||||
|
@ -172,14 +173,14 @@ export default {
|
||||||
convertBytes(bytes, decimals = 2, formatHtml = true) {
|
convertBytes(bytes, decimals = 2, formatHtml = true) {
|
||||||
const formatted = convertBytes(bytes, decimals).toString();
|
const formatted = convertBytes(bytes, decimals).toString();
|
||||||
if (!formatHtml) return formatted;
|
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]}<span class="decimals">${m[2]}</span>`;
|
return `${m[1]}<span class="decimals">${m[2]}</span>`;
|
||||||
},
|
},
|
||||||
/* Add additional formatting to {MiscHelpers.formatNumber()} */
|
/* Add additional formatting to {MiscHelpers.formatNumber()} */
|
||||||
formatNumber(number, decimals = 1, formatHtml = true) {
|
formatNumber(number, decimals = 1, formatHtml = true) {
|
||||||
const formatted = formatNumber(number, decimals).toString();
|
const formatted = formatNumber(number, decimals).toString();
|
||||||
if (!formatHtml) return formatted;
|
if (!formatHtml) return formatted;
|
||||||
const m = formatted.match(/([0-9]+)((\.[0-9]+)?([KMBT]?))/);
|
const m = formatted.match(/(\d+)((\.\d+)?([KMBT]?))/);
|
||||||
return `${m[1]}<span class="decimals">${m[2]}</span>`;
|
return `${m[1]}<span class="decimals">${m[2]}</span>`;
|
||||||
},
|
},
|
||||||
/* Format a number as percentage value */
|
/* Format a number as percentage value */
|
||||||
|
|
Loading…
Reference in New Issue