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
218 changed files with 2471 additions and 1244 deletions

View File

@@ -90,7 +90,7 @@ export class AssetStore {
setTimeout(() => {
this.pendingChanges.push(...changes);
this.processPendingChanges();
}, 1_000);
}, 1000);
}
connect() {
@@ -124,19 +124,22 @@ export class AssetStore {
processPendingChanges = throttle(() => {
for (const { type, value } of this.pendingChanges) {
switch (type) {
case 'add':
case 'add': {
this.addAsset(value);
break;
}
case 'trash':
case 'trash': {
if (!this.options.isTrashed) {
this.removeAsset(value);
}
break;
}
case 'delete':
case 'delete': {
this.removeAsset(value);
break;
}
}
}
@@ -174,7 +177,7 @@ export class AssetStore {
};
});
this.timelineHeight = this.buckets.reduce((acc, b) => acc + b.bucketHeight, 0);
this.timelineHeight = this.buckets.reduce((accumulator, b) => accumulator + b.bucketHeight, 0);
this.emit(false);
@@ -199,7 +202,7 @@ export class AssetStore {
bucket.position = position;
if (bucket.assets.length !== 0) {
if (bucket.assets.length > 0) {
this.emit(false);
return;
}
@@ -324,7 +327,9 @@ export class AssetStore {
}
async getRandomAsset(): Promise<AssetResponseDto | null> {
let index = Math.floor(Math.random() * this.buckets.reduce((acc, bucket) => acc + bucket.bucketCount, 0));
let index = Math.floor(
Math.random() * this.buckets.reduce((accumulator, bucket) => accumulator + bucket.bucketCount, 0),
);
for (const bucket of this.buckets) {
if (index < bucket.bucketCount) {
await this.loadBucket(bucket.bucketDate, BucketPosition.Unknown);
@@ -356,17 +361,17 @@ export class AssetStore {
}
removeAsset(id: string) {
for (let i = 0; i < this.buckets.length; i++) {
const bucket = this.buckets[i];
for (let j = 0; j < bucket.assets.length; j++) {
const asset = bucket.assets[j];
for (let index = 0; index < this.buckets.length; index++) {
const bucket = this.buckets[index];
for (let index_ = 0; index_ < bucket.assets.length; index_++) {
const asset = bucket.assets[index_];
if (asset.id !== id) {
continue;
}
bucket.assets.splice(j, 1);
bucket.assets.splice(index_, 1);
if (bucket.assets.length === 0) {
this.buckets.splice(i, 1);
this.buckets.splice(index, 1);
}
this.emit(true);
@@ -422,14 +427,14 @@ export class AssetStore {
this.assets = this.buckets.flatMap(({ assets }) => assets);
const assetToBucket: Record<string, AssetLookup> = {};
for (let i = 0; i < this.buckets.length; i++) {
const bucket = this.buckets[i];
if (bucket.assets.length !== 0) {
for (let index = 0; index < this.buckets.length; index++) {
const bucket = this.buckets[index];
if (bucket.assets.length > 0) {
bucket.bucketCount = bucket.assets.length;
}
for (let j = 0; j < bucket.assets.length; j++) {
const asset = bucket.assets[j];
assetToBucket[asset.id] = { bucket, bucketIndex: i, assetIndex: j };
for (let index_ = 0; index_ < bucket.assets.length; index_++) {
const asset = bucket.assets[index_];
assetToBucket[asset.id] = { bucket, bucketIndex: index, assetIndex: index_ };
}
}
this.assetToBucket = assetToBucket;

View File

@@ -10,7 +10,7 @@ export interface DownloadProgress {
export const downloadAssets = writable<Record<string, DownloadProgress>>({});
export const isDownloading = derived(downloadAssets, ($downloadAssets) => {
if (Object.keys($downloadAssets).length == 0) {
if (Object.keys($downloadAssets).length === 0) {
return false;
}

View File

@@ -15,10 +15,8 @@ export const handleToggleTheme = () => {
};
const initTheme = (): ThemeSetting => {
if (browser) {
if (!window.matchMedia('(prefers-color-scheme: dark)').matches) {
return { value: Theme.LIGHT, system: false };
}
if (browser && !window.matchMedia('(prefers-color-scheme: dark)').matches) {
return { value: Theme.LIGHT, system: false };
}
return { value: Theme.DARK, system: false };
};
@@ -30,13 +28,9 @@ export const colorTheme = persisted<ThemeSetting>('color-theme', initialTheme, {
serializer: {
parse: (text: string): ThemeSetting => {
const parsedText: ThemeSetting = JSON.parse(text);
if (Object.values(Theme).includes(parsedText.value)) {
return parsedText;
} else {
return initTheme();
}
return Object.values(Theme).includes(parsedText.value) ? parsedText : initTheme();
},
stringify: (obj) => JSON.stringify(obj),
stringify: (object) => JSON.stringify(object),
},
});
@@ -44,7 +38,7 @@ export const colorTheme = persisted<ThemeSetting>('color-theme', initialTheme, {
export const locale = persisted<string | undefined>('locale', undefined, {
serializer: {
parse: (text) => text,
stringify: (obj) => obj ?? '',
stringify: (object) => object ?? '',
},
});

View File

@@ -65,8 +65,8 @@ function createUploadStore() {
});
};
const updateAsset = (id: string, partialObj: Partial<UploadAsset>) => {
updateAssetMap(id, (v) => ({ ...v, ...partialObj }));
const updateAsset = (id: string, partialObject: Partial<UploadAsset>) => {
updateAssetMap(id, (v) => ({ ...v, ...partialObject }));
};
const removeUploadAsset = (id: string) => {

View File

@@ -55,8 +55,8 @@ export const openWebsocketConnection = async () => {
.on('on_config_update', () => loadConfig())
.on('on_new_release', (data) => websocketStore.onRelease.set(data))
.on('error', (e) => console.log('Websocket Error', e));
} catch (e) {
console.log('Cannot connect to websocket ', e);
} catch (error) {
console.log('Cannot connect to websocket', error);
}
};