mirror of
https://github.com/immich-app/immich.git
synced 2025-12-22 01:11:20 +03:00
feat(server, web): quotas (#4471)
* feat: quotas * chore: open api * chore: update status box and upload error message --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
37
web/src/lib/utils/byte-converter.ts
Normal file
37
web/src/lib/utils/byte-converter.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Convert to bytes from on a specified unit.
|
||||
*
|
||||
* * `1, 'GiB'`, returns `1073741824` bytes
|
||||
*
|
||||
* @param size value to be converted
|
||||
* @param unit unit to convert from
|
||||
* @returns bytes (number)
|
||||
*/
|
||||
export function convertToBytes(size: number, unit: string): number {
|
||||
let bytes = 0;
|
||||
|
||||
if (unit === 'GiB') {
|
||||
bytes = size * 1073741824;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from bytes to a specified unit.
|
||||
*
|
||||
* * `11073741824, 'GiB'`, returns `1` GiB
|
||||
*
|
||||
* @param bytes value to be converted
|
||||
* @param unit unit to convert to
|
||||
* @returns bytes (number)
|
||||
*/
|
||||
export function convertFromBytes(bytes: number, unit: string): number {
|
||||
let size = 0;
|
||||
|
||||
if (unit === 'GiB') {
|
||||
size = bytes / 1073741824;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import { uploadAssetsStore } from '$lib/stores/upload';
|
||||
import { addAssetsToAlbum } from '$lib/utils/asset-utils';
|
||||
import { api, AssetFileUploadResponseDto } from '@api';
|
||||
import { notificationController, NotificationType } from './../components/shared-components/notification/notification';
|
||||
import { UploadState } from '$lib/models/upload-asset';
|
||||
import { ExecutorQueue } from '$lib/utils/executor-queue';
|
||||
import { getServerErrorMessage, handleError } from './handle-error';
|
||||
|
||||
let _extensions: string[];
|
||||
|
||||
@@ -115,26 +115,10 @@ async function fileUploader(asset: File, albumId: string | undefined = undefined
|
||||
return res.id;
|
||||
}
|
||||
})
|
||||
.catch((reason) => {
|
||||
console.log('error uploading file ', reason);
|
||||
.catch(async (error) => {
|
||||
await handleError(error, 'Unable to upload file');
|
||||
const reason = (await getServerErrorMessage(error)) || error;
|
||||
uploadAssetsStore.updateAsset(deviceAssetId, { state: UploadState.ERROR, error: reason });
|
||||
handleUploadError(asset, JSON.stringify(reason));
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
function handleUploadError(asset: File, respBody = '{}', extraMessage?: string) {
|
||||
try {
|
||||
const res = JSON.parse(respBody);
|
||||
const extraMsg = res ? ' ' + res?.message : '';
|
||||
const messageSuffix = extraMessage !== undefined ? ` ${extraMessage}` : '';
|
||||
|
||||
notificationController.show({
|
||||
type: NotificationType.Error,
|
||||
message: `Cannot upload file ${asset.name} ${extraMsg}${messageSuffix}`,
|
||||
timeout: 5000,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('ERROR parsing data JSON in handleUploadError');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user