mirror of
https://github.com/samsonjs/immich.git
synced 2026-03-25 09:15:56 +00:00
* Add Exif-Rating * Integrate star rating as own component * Add e2e tests for rating and validation * Rename component and async handleChangeRating * Display rating can be enabled in app settings * Correct i18n reference Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> * Star rating: change from slider to buttons * Star rating for clarity * Design updates. * Renaming and code optimization * chore: clean up * chore: e2e formatting * light mode border and default value --------- Co-authored-by: Christoph Suter <christoph@suter-burri.ch> Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Co-authored-by: Mert <101130780+mertalev@users.noreply.github.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
96 lines
2.2 KiB
TypeScript
96 lines
2.2 KiB
TypeScript
import { UserEntity } from 'src/entities/user.entity';
|
|
import { HumanReadableSize } from 'src/utils/bytes';
|
|
import { Column, DeepPartial, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
|
|
|
|
@Entity('user_metadata')
|
|
export class UserMetadataEntity<T extends keyof UserMetadata = UserMetadataKey> {
|
|
@PrimaryColumn({ type: 'uuid' })
|
|
userId!: string;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.metadata, { onUpdate: 'CASCADE', onDelete: 'CASCADE' })
|
|
user!: UserEntity;
|
|
|
|
@PrimaryColumn({ type: 'varchar' })
|
|
key!: T;
|
|
|
|
@Column({ type: 'jsonb' })
|
|
value!: UserMetadata[T];
|
|
}
|
|
|
|
export enum UserAvatarColor {
|
|
PRIMARY = 'primary',
|
|
PINK = 'pink',
|
|
RED = 'red',
|
|
YELLOW = 'yellow',
|
|
BLUE = 'blue',
|
|
GREEN = 'green',
|
|
PURPLE = 'purple',
|
|
ORANGE = 'orange',
|
|
GRAY = 'gray',
|
|
AMBER = 'amber',
|
|
}
|
|
|
|
export interface UserPreferences {
|
|
rating: {
|
|
enabled: boolean;
|
|
};
|
|
memories: {
|
|
enabled: boolean;
|
|
};
|
|
avatar: {
|
|
color: UserAvatarColor;
|
|
};
|
|
emailNotifications: {
|
|
enabled: boolean;
|
|
albumInvite: boolean;
|
|
albumUpdate: boolean;
|
|
};
|
|
download: {
|
|
archiveSize: number;
|
|
};
|
|
purchase: {
|
|
showSupportBadge: boolean;
|
|
hideBuyButtonUntil: string;
|
|
};
|
|
}
|
|
|
|
export const getDefaultPreferences = (user: { email: string }): UserPreferences => {
|
|
const values = Object.values(UserAvatarColor);
|
|
const randomIndex = Math.floor(
|
|
[...user.email].map((letter) => letter.codePointAt(0) ?? 0).reduce((a, b) => a + b, 0) % values.length,
|
|
);
|
|
|
|
return {
|
|
rating: {
|
|
enabled: false,
|
|
},
|
|
memories: {
|
|
enabled: true,
|
|
},
|
|
avatar: {
|
|
color: values[randomIndex],
|
|
},
|
|
emailNotifications: {
|
|
enabled: true,
|
|
albumInvite: true,
|
|
albumUpdate: true,
|
|
},
|
|
download: {
|
|
archiveSize: HumanReadableSize.GiB * 4,
|
|
},
|
|
purchase: {
|
|
showSupportBadge: true,
|
|
hideBuyButtonUntil: new Date(2022, 1, 12).toISOString(),
|
|
},
|
|
};
|
|
};
|
|
|
|
export enum UserMetadataKey {
|
|
PREFERENCES = 'preferences',
|
|
LICENSE = 'license',
|
|
}
|
|
|
|
export interface UserMetadata extends Record<UserMetadataKey, Record<string, any>> {
|
|
[UserMetadataKey.PREFERENCES]: DeepPartial<UserPreferences>;
|
|
[UserMetadataKey.LICENSE]: { licenseKey: string; activationKey: string; activatedAt: Date };
|
|
}
|