Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/apps/dashboard/features/storage/api/useSystemStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
api: Api,
options?: AxiosRequestConfig
) => {
const response = await getSystemApi(api)
.getSystemStorage(options);
const response = await getSystemApi(api).getSystemStorage(options);
return response.data;
};

const getSystemStorageQuery = (
api?: Api
) => queryOptions({
queryKey: [ 'SystemStorage' ],
queryFn: ({ signal }) => fetchSystemStorage(api!, { signal }),
enabled: !!api,
refetchOnWindowFocus: false
});
const getSystemStorageQuery = (api?: Api) =>
queryOptions({
queryKey: ['SystemStorage'],
queryFn: ({ signal }) => fetchSystemStorage(api!, { signal }),
enabled: !!api,
refetchOnWindowFocus: false,

Check failure on line 21 in src/apps/dashboard/features/storage/api/useSystemStorage.ts

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unexpected trailing comma
});
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected trailing comma. @stylistic/comma-dangle

Fix available:

Suggested change
refetchOnWindowFocus: false,
});
refetchOnWindowFocus: false
});


export const useSystemStorage = () => {
const { api } = useApi();
return useQuery(getSystemStorageQuery(api));
const query = useQuery(getSystemStorageQuery(api));

if (query.data) {
console.log('📦 System Storage API response:', query.data);
}

return query;
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@

const getStorageTypeText = (type?: string | null) => {
if (!type) return undefined;

if (Object.keys(StorageType).includes(type)) {
return globalize.translate(`StorageType.${type}`);
}

return type;
};

Expand All @@ -43,10 +41,16 @@
const readableUsedSpace = (typeof folder?.UsedSpace === 'undefined' || folder.UsedSpace < 0) ?
'?' : getReadableSize(folder.UsedSpace);
const totalSpace = calculateTotal(folder);
const readableTotalSpace = (totalSpace < 0) ? '?' : getReadableSize(totalSpace);

Check failure on line 44 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Remove this useless assignment to variable "readableTotalSpace"

Check failure on line 44 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Remove the declaration of the unused 'readableTotalSpace' variable

Check failure on line 44 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

'readableTotalSpace' is assigned a value but never used
const usedPercentage = calculateUsedPercentage(folder);
const statusColor = folder ? getStatusColor(usedPercentage) : 'primary';

const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;

Check failure on line 48 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unexpected any. Specify a different type

Check failure on line 48 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unexpected any. Specify a different type

Check failure on line 48 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unexpected any. Specify a different type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as unknown)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as never)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as unknown)?.SizeBytes ?? (folder as any)?.Size;
Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as never)?.SizeBytes ?? (folder as any)?.Size;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as unknown)?.Size;
Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as never)?.Size;

const hasFolderSize = typeof folderSize === 'number' && folderSize >= 0;
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;

Check failure on line 50 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unexpected any. Specify a different type

Check failure on line 50 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Unexpected any. Specify a different type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as unknown)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as never)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as unknown)?.DriveCapacity;
Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as never)?.DriveCapacity;

const readableFolderSize = hasFolderSize ? getReadableSize(folderSize) : undefined;
const readableDriveTotal = typeof driveTotal === 'number' && driveTotal >= 0 ? getReadableSize(driveTotal) : undefined;

return (
<ListItem>
<ListItemIcon title={getStorageTypeText(folder?.StorageType)}>
Expand All @@ -70,24 +74,33 @@
lineBreak: 'anywhere'
}}
>
{folder ? folder.Path : (
<Skeleton />
)}
</Typography>
<LinearProgress
variant={folder ? 'determinate' : 'indeterminate'}
color={statusColor}
value={usedPercentage}
/>
<Typography
variant='body2'
color='textSecondary'
sx={{
textAlign: 'end'
}}
>
{`${readableUsedSpace} / ${readableTotalSpace}`}
{folder ? folder.Path : <Skeleton />}
</Typography>

{hasFolderSize ? (
<>
<LinearProgress
variant='determinate'
color={statusColor}
value={usedPercentage}
/>
<Typography
variant='body2'
color='textSecondary'
sx={{ textAlign: 'end' }}
>
{`${readableFolderSize}${readableDriveTotal ? ` / ${readableDriveTotal}` : ''}`}

Check failure on line 92 in src/apps/dashboard/features/storage/components/StorageListItem.tsx

View workflow job for this annotation

GitHub Actions / Quality checks 👌🧪 / Run lint 🕵️‍♂️

Refactor this code to not use nested template literals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this code to not use nested template literals. sonarjs/no-nested-template-literals

</Typography>
</>
) : (
<Typography
variant='body2'
color='textSecondary'
sx={{ textAlign: 'end' }}
>
{readableUsedSpace === '?' ? '' : `${readableUsedSpace}`}
</Typography>
)}
</>
}
slots={{
Expand Down
27 changes: 19 additions & 8 deletions src/apps/dashboard/features/storage/utils/space.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import type { FolderStorageDto } from '@jellyfin/sdk/lib/generated-client/models/folder-storage-dto';

export const calculateTotal = (folder?: FolderStorageDto) => {
if (typeof folder?.UsedSpace === 'undefined' || folder.UsedSpace < 0) {
return -1;
}
if (!folder) return -1;

const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as unknown)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as never)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as unknown)?.SizeBytes ?? (folder as any)?.Size;
Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as never)?.SizeBytes ?? (folder as any)?.Size;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as unknown)?.Size;
Suggested change
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as never)?.Size;

if (typeof folderSize === 'number' && folderSize >= 0) return folderSize;

if (typeof folder?.UsedSpace === 'undefined' || folder.UsedSpace < 0) return -1;

const freeSpace = Math.max(0, folder.FreeSpace || 0);
const usedSpace = Math.max(0, folder.UsedSpace);
return freeSpace + usedSpace;
};

export const calculateUsedPercentage = (folder?: FolderStorageDto) => {
const totalSpace = calculateTotal(folder);
if (totalSpace <= 0) return 0;
if (!folder) return 0;

const usedSpace = folder?.UsedSpace || 0;
const used = Math.max(0, folder.UsedSpace || 0);

return Math.min(100, (usedSpace / totalSpace) * 100);
};
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as unknown)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as never)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as unknown)?.DriveCapacity;
Suggested change
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity;
const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as never)?.DriveCapacity;

const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderTotal = (folder as unknown)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
Suggested change
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderTotal = (folder as never)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as unknown)?.SizeBytes ?? (folder as any)?.Size;
Suggested change
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as never)?.SizeBytes ?? (folder as any)?.Size;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any

Suggestion(s) available:

Suggested change
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as unknown)?.Size;
Suggested change
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size;
const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as never)?.Size;


const total = (typeof driveTotal === 'number' && driveTotal > 0) ? driveTotal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not nest ternary expressions. no-nested-ternary

: (typeof folderTotal === 'number' && folderTotal > 0) ? folderTotal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this nested ternary operation into an independent statement. sonarjs/no-nested-conditional

: calculateTotal(folder);
Comment on lines +25 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

':' should be placed at the end of the line. @stylistic/operator-linebreak

Fix available:

Suggested change
: (typeof folderTotal === 'number' && folderTotal > 0) ? folderTotal
: calculateTotal(folder);
(typeof folderTotal === 'number' && folderTotal > 0) ? folderTotal
: calculateTotal(folder);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 12 spaces but found 8. @stylistic/indent

Fix available:

Suggested change
: calculateTotal(folder);
: calculateTotal(folder);


Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

':' should be placed at the end of the line. @stylistic/operator-linebreak

Fix available:

Suggested change
: calculateTotal(folder);
calculateTotal(folder);

if (total <= 0) return 0;

return Math.min(100, (used / total) * 100);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline required at end of file but not found. @stylistic/eol-last

Fix available:

Suggested change
};
};

Loading