Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Sep 17, 2024
1 parent 8619d9d commit 3218136
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
12 changes: 0 additions & 12 deletions server/src/dtos/user-profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,3 @@ export class CreateProfileImageResponseDto {
profileChangedAt!: Date;
profileImagePath!: string;
}

export function mapCreateProfileImageResponse(
userId: string,
profileImagePath: string,
profileChangedAt: Date,
): CreateProfileImageResponseDto {
return {
userId,
profileChangedAt,
profileImagePath,
};
}
2 changes: 1 addition & 1 deletion server/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export class UserEntity {
@OneToMany(() => UserMetadataEntity, (metadata) => metadata.user)
metadata!: UserMetadataEntity[];

@UpdateDateColumn({ type: 'timestamptz' })
@Column({ type: 'timestamptz' })
profileChangedAt!: Date;
}
20 changes: 13 additions & 7 deletions server/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SystemConfigCore } from 'src/cores/system-config.core';
import { AuthDto } from 'src/dtos/auth.dto';
import { LicenseKeyDto, LicenseResponseDto } from 'src/dtos/license.dto';
import { UserPreferencesResponseDto, UserPreferencesUpdateDto, mapPreferences } from 'src/dtos/user-preferences.dto';
import { CreateProfileImageResponseDto, mapCreateProfileImageResponse } from 'src/dtos/user-profile.dto';
import { CreateProfileImageResponseDto } from 'src/dtos/user-profile.dto';
import { UserAdminResponseDto, UserResponseDto, UserUpdateMeDto, mapUser, mapUserAdmin } from 'src/dtos/user.dto';
import { UserMetadataEntity } from 'src/entities/user-metadata.entity';
import { UserEntity } from 'src/entities/user.entity';
Expand Down Expand Up @@ -93,17 +93,23 @@ export class UserService {
return mapUser(user);
}

async createProfileImage(auth: AuthDto, fileInfo: Express.Multer.File): Promise<CreateProfileImageResponseDto> {
async createProfileImage(auth: AuthDto, file: Express.Multer.File): Promise<CreateProfileImageResponseDto> {
const { profileImagePath: oldpath } = await this.findOrFail(auth.user.id, { withDeleted: false });
const profileChangedAt = new Date();
const updatedUser = await this.userRepository.update(auth.user.id, {
profileImagePath: fileInfo.path,
profileChangedAt,

const user = await this.userRepository.update(auth.user.id, {
profileImagePath: file.path,
profileChangedAt: new Date(),
});

if (oldpath !== '') {
await this.jobRepository.queue({ name: JobName.DELETE_FILES, data: { files: [oldpath] } });
}
return mapCreateProfileImageResponse(updatedUser.id, updatedUser.profileImagePath, profileChangedAt);

return {
userId: user.id,
profileImagePath: user.profileImagePath,
profileChangedAt: user.profileChangedAt,
};
}

async deleteProfileImage(auth: AuthDto): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{#if showProfileImage && user.profileImagePath}
<img
bind:this={img}
src={getProfileImageUrl(user.id, user.profileChangedAt)}
src={getProfileImageUrl(user)}
alt={$t('profile_image_of_user', { values: { user: title } })}
class="h-full w-full object-cover"
class:hidden={showFallback}
Expand Down
5 changes: 3 additions & 2 deletions web/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type AssetResponseDto,
type PersonResponseDto,
type SharedLinkResponseDto,
type UserResponseDto,
} from '@immich/sdk';
import { mdiCogRefreshOutline, mdiDatabaseRefreshOutline, mdiImageRefreshOutline } from '@mdi/js';
import { sortBy } from 'lodash-es';
Expand Down Expand Up @@ -204,8 +205,8 @@ export const getAssetPlaybackUrl = (options: string | { id: string; checksum?: s
return createUrl(getAssetPlaybackPath(id), { key: getKey(), c: checksum });
};

export const getProfileImageUrl = (userId: string, updatedAt?: string) =>
createUrl(getUserProfileImagePath(userId), { updatedAt });
export const getProfileImageUrl = (user: UserResponseDto) =>
createUrl(getUserProfileImagePath(user.id), { updatedAt: user.profileChangedAt });

export const getPeopleThumbnailUrl = (person: PersonResponseDto, updatedAt?: string) =>
createUrl(getPeopleThumbnailPath(person.id), { updatedAt: updatedAt ?? person.updatedAt });
Expand Down

0 comments on commit 3218136

Please sign in to comment.