From 8844a3824453289c2d7ba2fc96211f2134392a5d 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 | 4 ++-- source/tools/quota.ts | 3 ++- source/types.ts | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/tools/dav.ts b/source/tools/dav.ts index d1d1ad03..6291c50c 100644 --- a/source/tools/dav.ts +++ b/source/tools/dav.ts @@ -237,7 +237,7 @@ 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()) { + switch (String(value)) { case "-3": return "unlimited"; case "-2": @@ -246,6 +246,6 @@ export function translateDiskSpace(value: string | number): DiskQuotaAvailable { // -1 is non-computed return "unknown"; default: - return parseInt(value as string, 10); + return parseInt(String(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 b0b14376..ff4cab80 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; }