🎉 Add Nextcloud widget

Add a widget supporting the `capabilites`, `user`
and `serverinfo` Nextcloud APIs.

Basic branding, user and quota information is always displayed
and when the provided credentials are for and admin user then
server information is also displayed.

APIs:
* [capabilities](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#capabilities-api)
* [user](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata)
* [serverinfo](https://github.com/nextcloud/serverinfo)
This commit is contained in:
Marcell Fülöp
2022-06-11 23:41:40 +00:00
parent e24fa10f0f
commit 0bf6fee180
5 changed files with 501 additions and 0 deletions

View File

@@ -105,6 +105,15 @@ export const convertBytes = (bytes, decimals = 2) => {
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / (k ** i)).toFixed(decimals))} ${sizes[i]}`;
};
/* Returns a numbers shortened version with suffixes for thousand, million, billion
and trillion, e.g. 105_411 => 105.4K, 4_294_967_295 => 4.3B */
export const formatNumber = (number) => {
if (number > -1000 && number < 1000) return number;
const k = 1000;
const units = ['', 'K', 'M', 'B', 'T'];
const i = Math.floor(Math.log(number) / Math.log(k));
return `${(number / (k ** i)).toFixed(1)}${units[i]}`;
};
/* Round price to appropriate number of decimals */
export const roundPrice = (price) => {