From 1d9f2d908db91dcec79354889426f468505468bc Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 24 Jul 2024 22:13:00 +0200 Subject: [PATCH] fix(types): correct types for quota bytes As per RFC the value shall be octets representing the quota, in all cases I know the value will be parsed to `number` by the XML parser. (tested e.g. with Sabre / Nextcloud). Signed-off-by: Ferdinand Thiessen --- source/tools/dav.ts | 5 +++-- source/tools/quota.ts | 3 ++- source/types.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/tools/dav.ts b/source/tools/dav.ts index 367ef2ea..4f61ae07 100644 --- a/source/tools/dav.ts +++ b/source/tools/dav.ts @@ -233,7 +233,8 @@ export function parseSearch(result: DAVResult, searchArbiter: string, isDetailed * @returns The value in bytes, or another indicator */ export function translateDiskSpace(value: string | number): DiskQuotaAvailable { - switch (value.toString()) { + value = String(value); + switch (value) { case "-3": return "unlimited"; case "-2": @@ -242,6 +243,6 @@ export function translateDiskSpace(value: string | number): DiskQuotaAvailable { // -1 is non-computed return "unknown"; default: - return parseInt(value as string, 10); + return parseInt(value, 10); } } diff --git a/source/tools/quota.ts b/source/tools/quota.ts index eecc768d..1bd22e9c 100644 --- a/source/tools/quota.ts +++ b/source/tools/quota.ts @@ -11,7 +11,8 @@ export function parseQuota(result: DAVResult): DiskQuota | null { } = responseItem; return typeof quotaUsed !== "undefined" && typeof quotaAvail !== "undefined" ? { - used: parseInt(quotaUsed, 10), + // As it could be both a string or a number ensure we are working with a number + used: parseInt(String(quotaUsed), 10), available: translateDiskSpace(quotaAvail) } : null; diff --git a/source/types.ts b/source/types.ts index f6f328f6..18d60921 100644 --- a/source/types.ts +++ b/source/types.ts @@ -70,8 +70,8 @@ export interface DAVResultResponseProps { getetag?: string; getcontentlength?: string; getcontenttype?: string; - "quota-available-bytes"?: any; - "quota-used-bytes"?: string; + "quota-available-bytes"?: string | number; + "quota-used-bytes"?: string | number; [additionalProp: string]: unknown; }