chore(server,cli,web): housekeeping and stricter code style (#6751)

* add unicorn to eslint

* fix lint errors for cli

* fix merge

* fix album name extraction

* Update cli/src/commands/upload.command.ts

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

* es2k23

* use lowercase os

* return undefined album name

* fix bug in asset response dto

* auto fix issues

* fix server code style

* es2022 and formatting

* fix compilation error

* fix test

* fix config load

* fix last lint errors

* set string type

* bump ts

* start work on web

* web formatting

* Fix UUIDParamDto as UUIDParamDto

* fix library service lint

* fix web errors

* fix errors

* formatting

* wip

* lints fixed

* web can now start

* alphabetical package json

* rename error

* chore: clean up

---------

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Jonathan Jogenfors 2024-02-02 04:18:00 +01:00 committed by GitHub
parent e4d0560d49
commit f44fa45aa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
218 changed files with 2471 additions and 1244 deletions

View file

@ -19,7 +19,7 @@ export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids:
message: `${force ? 'Permanently deleted' : 'Trashed'} ${ids.length} assets`,
type: NotificationType.Info,
});
} catch (e) {
handleError(e, 'Error deleting assets');
} catch (error) {
handleError(error, 'Error deleting assets');
}
};

View file

@ -29,7 +29,7 @@ describe('get file extension from filename', () => {
describe('get asset filename', () => {
it('returns the filename including file extension', () => {
[
for (const { asset, result } of [
{
asset: {
originalFileName: 'filename',
@ -51,8 +51,8 @@ describe('get asset filename', () => {
},
result: 'new-filename.txt.jpg',
},
].forEach(({ asset, result }) => {
]) {
expect(getAssetFilename(asset as AssetResponseDto)).toEqual(result);
});
}
});
});

View file

@ -36,9 +36,9 @@ export const downloadBlob = (data: Blob, filename: string) => {
anchor.href = url;
anchor.download = filename;
document.body.appendChild(anchor);
document.body.append(anchor);
anchor.click();
document.body.removeChild(anchor);
anchor.remove();
URL.revokeObjectURL(url);
};
@ -57,14 +57,14 @@ export const downloadArchive = async (fileName: string, options: DownloadInfoDto
// TODO: prompt for big download
// const total = downloadInfo.totalSize;
for (let i = 0; i < downloadInfo.archives.length; i++) {
const archive = downloadInfo.archives[i];
const suffix = downloadInfo.archives.length === 1 ? '' : `+${i + 1}`;
for (let index = 0; index < downloadInfo.archives.length; index++) {
const archive = downloadInfo.archives[index];
const suffix = downloadInfo.archives.length === 1 ? '' : `+${index + 1}`;
const archiveName = fileName.replace('.zip', `${suffix}-${DateTime.now().toFormat('yyyy-LL-dd-HH-mm-ss')}.zip`);
let downloadKey = `${archiveName} `;
if (downloadInfo.archives.length > 1) {
downloadKey = `${archiveName} (${i + 1}/${downloadInfo.archives.length})`;
downloadKey = `${archiveName} (${index + 1}/${downloadInfo.archives.length})`;
}
const abort = new AbortController();
@ -81,12 +81,12 @@ export const downloadArchive = async (fileName: string, options: DownloadInfoDto
);
downloadBlob(data, archiveName);
} catch (e) {
handleError(e, 'Unable to download files');
} catch (error) {
handleError(error, 'Unable to download files');
downloadManager.clear(downloadKey);
return;
} finally {
setTimeout(() => downloadManager.clear(downloadKey), 5_000);
setTimeout(() => downloadManager.clear(downloadKey), 5000);
}
}
};
@ -140,11 +140,11 @@ export const downloadFile = async (asset: AssetResponseDto) => {
});
downloadBlob(data, filename);
} catch (e) {
handleError(e, `Error downloading ${filename}`);
} catch (error) {
handleError(error, `Error downloading ${filename}`);
downloadManager.clear(downloadKey);
} finally {
setTimeout(() => downloadManager.clear(downloadKey), 5_000);
setTimeout(() => downloadManager.clear(downloadKey), 5000);
}
}
};
@ -155,7 +155,7 @@ export const downloadFile = async (asset: AssetResponseDto) => {
*/
export function getFilenameExtension(filename: string): string {
const lastIndex = Math.max(0, filename.lastIndexOf('.'));
const startIndex = (lastIndex || Infinity) + 1;
const startIndex = (lastIndex || Number.POSITIVE_INFINITY) + 1;
return filename.slice(startIndex).toLowerCase();
}
@ -182,10 +182,8 @@ export function getAssetRatio(asset: AssetResponseDto) {
let height = asset.exifInfo?.exifImageHeight || 235;
let width = asset.exifInfo?.exifImageWidth || 235;
const orientation = Number(asset.exifInfo?.orientation);
if (orientation) {
if (isRotated90CW(orientation) || isRotated270CW(orientation)) {
[width, height] = [height, width];
}
if (orientation && (isRotated90CW(orientation) || isRotated270CW(orientation))) {
[width, height] = [height, width];
}
return { width, height };
}
@ -204,21 +202,22 @@ export function isWebCompatibleImage(asset: AssetResponseDto): boolean {
export const getAssetType = (type: AssetTypeEnum) => {
switch (type) {
case 'IMAGE':
case 'IMAGE': {
return 'Photo';
case 'VIDEO':
}
case 'VIDEO': {
return 'Video';
default:
}
default: {
return 'Asset';
}
}
};
export const getSelectedAssets = (assets: Set<AssetResponseDto>, user: UserResponseDto | null): string[] => {
const ids = Array.from(assets)
.filter((a) => !a.isExternal && user && a.ownerId === user.id)
.map((a) => a.id);
const ids = [...assets].filter((a) => !a.isExternal && user && a.ownerId === user.id).map((a) => a.id);
const numberOfIssues = Array.from(assets).filter((a) => a.isExternal || (user && a.ownerId !== user.id)).length;
const numberOfIssues = [...assets].filter((a) => a.isExternal || (user && a.ownerId !== user.id)).length;
if (numberOfIssues > 0) {
notificationController.show({
message: `Can't change metadata of ${numberOfIssues} asset${numberOfIssues > 1 ? 's' : ''}`,

View file

@ -11,7 +11,7 @@ export function convertToBytes(size: number, unit: string): number {
let bytes = 0;
if (unit === 'GiB') {
bytes = size * 1073741824;
bytes = size * 1_073_741_824;
}
return bytes;
@ -30,7 +30,7 @@ export function convertFromBytes(bytes: number, unit: string): number {
let size = 0;
if (unit === 'GiB') {
size = bytes / 1073741824;
size = bytes / 1_073_741_824;
}
return size;

View file

@ -22,7 +22,7 @@ export function getBytesWithUnit(bytes: number, maxPrecision = 1): [number, stri
}
}
remainder = parseFloat(remainder.toFixed(maxPrecision));
remainder = Number.parseFloat(remainder.toFixed(maxPrecision));
return [remainder, units[magnitude]];
}

View file

@ -5,12 +5,15 @@ export const getContextMenuPosition = (event: MouseEvent, align: Align = 'middle
const box = ((currentTarget || target) as HTMLElement)?.getBoundingClientRect();
if (box) {
switch (align) {
case 'middle':
case 'middle': {
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
case 'top-left':
}
case 'top-left': {
return { x: box.x, y: box.y };
case 'top-right':
}
case 'top-right': {
return { x: box.x + box.width, y: box.y };
}
}
}

View file

@ -26,7 +26,9 @@ export class ExecutorQueue {
const v = concurrency - this.running;
if (v > 0) {
[...new Array(this._concurrency)].forEach(() => this.tryRun());
for (let i = 0; i < v; i++) {
this.tryRun();
}
}
}
@ -38,8 +40,8 @@ export class ExecutorQueue {
this.running++;
const result = task();
resolve(await result);
} catch (e) {
reject(e);
} catch (error) {
reject(error);
} finally {
this.taskFinished();
}

View file

@ -17,7 +17,7 @@ const getExtensions = async () => {
return _extensions;
};
export const openFileUploadDialog = async (albumId: string | undefined = undefined) => {
export const openFileUploadDialog = async (albumId?: string | undefined) => {
const extensions = await getExtensions();
return new Promise<(string | undefined)[]>((resolve, reject) => {
@ -27,7 +27,7 @@ export const openFileUploadDialog = async (albumId: string | undefined = undefin
fileSelector.type = 'file';
fileSelector.multiple = true;
fileSelector.accept = extensions.join(',');
fileSelector.onchange = async (e: Event) => {
fileSelector.addEventListener('change', async (e: Event) => {
const target = e.target as HTMLInputElement;
if (!target.files) {
return;
@ -35,12 +35,12 @@ export const openFileUploadDialog = async (albumId: string | undefined = undefin
const files = Array.from(target.files);
resolve(fileUploadHandler(files, albumId));
};
});
fileSelector.click();
} catch (e) {
console.log('Error selecting file', e);
reject(e);
} catch (error) {
console.log('Error selecting file', error);
reject(error);
}
});
};
@ -50,7 +50,7 @@ export const fileUploadHandler = async (files: File[], albumId: string | undefin
const promises = [];
for (const file of files) {
const name = file.name.toLowerCase();
if (extensions.some((ext) => name.endsWith(ext))) {
if (extensions.some((extension) => name.endsWith(extension))) {
uploadAssetsStore.addNewUploadAsset({ id: getDeviceAssetId(file), file, albumId });
promises.push(uploadExecutionQueue.addTask(() => fileUploader(file, albumId)));
}

View file

@ -6,27 +6,21 @@ export const searchNameLocal = (
slice: number,
personId?: string,
): PersonResponseDto[] => {
return name.indexOf(' ') >= 0
return name.includes(' ')
? people
.filter((person: PersonResponseDto) => {
if (personId) {
return person.name.toLowerCase().startsWith(name.toLowerCase()) && person.id !== personId;
} else {
return person.name.toLowerCase().startsWith(name.toLowerCase());
}
return personId
? person.name.toLowerCase().startsWith(name.toLowerCase()) && person.id !== personId
: person.name.toLowerCase().startsWith(name.toLowerCase());
})
.slice(0, slice)
: people
.filter((person: PersonResponseDto) => {
const nameParts = person.name.split(' ');
if (personId) {
return (
nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase())) &&
person.id !== personId
);
} else {
return nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase()));
}
return personId
? nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase())) &&
person.id !== personId
: nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase()));
})
.slice(0, slice);
};

View file

@ -14,7 +14,7 @@ describe('converting time to seconds', () => {
});
it('parses hhh:mm:ss.SSS correctly', () => {
expect(timeToSeconds('100:02:03.456')).toBeCloseTo(360123.456);
expect(timeToSeconds('100:02:03.456')).toBeCloseTo(360_123.456);
});
it('ignores ignores double milliseconds hh:mm:ss.SSS.SSSSSS', () => {