1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-22 01:47:08 +02:00

Update server dependencies and fixed Typeorm API changes in new version (#276)

* Fixed dependencies

* Adapt typeorm API to be compatible with new version

* Fixed typeorm API in tests

* Remove console.log
This commit is contained in:
Alex 2022-06-29 13:39:58 -05:00 committed by GitHub
parent 5f00d8b9c6
commit a2e1d4caa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1166 additions and 1247 deletions

View File

@ -3,7 +3,7 @@ import { AssetAlbumEntity } from '@app/database/entities/asset-album.entity';
import { UserAlbumEntity } from '@app/database/entities/user-album.entity'; import { UserAlbumEntity } from '@app/database/entities/user-album.entity';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { getConnection, Repository, SelectQueryBuilder } from 'typeorm'; import { Repository, SelectQueryBuilder, DataSource } from 'typeorm';
import { AddAssetsDto } from './dto/add-assets.dto'; import { AddAssetsDto } from './dto/add-assets.dto';
import { AddUsersDto } from './dto/add-users.dto'; import { AddUsersDto } from './dto/add-users.dto';
import { CreateAlbumDto } from './dto/create-album.dto'; import { CreateAlbumDto } from './dto/create-album.dto';
@ -36,10 +36,12 @@ export class AlbumRepository implements IAlbumRepository {
@InjectRepository(UserAlbumEntity) @InjectRepository(UserAlbumEntity)
private userAlbumRepository: Repository<UserAlbumEntity>, private userAlbumRepository: Repository<UserAlbumEntity>,
private dataSource: DataSource,
) {} ) {}
async create(ownerId: string, createAlbumDto: CreateAlbumDto): Promise<AlbumEntity> { async create(ownerId: string, createAlbumDto: CreateAlbumDto): Promise<AlbumEntity> {
return getConnection().transaction(async (transactionalEntityManager) => { return this.dataSource.transaction(async (transactionalEntityManager) => {
// Create album entity // Create album entity
const newAlbum = new AlbumEntity(); const newAlbum = new AlbumEntity();
newAlbum.ownerId = ownerId; newAlbum.ownerId = ownerId;

View File

@ -154,7 +154,7 @@ export class AssetService {
public async getAssetThumbnail(assetId: string): Promise<StreamableFile> { public async getAssetThumbnail(assetId: string): Promise<StreamableFile> {
try { try {
const asset = await this.assetRepository.findOne({ id: assetId }); const asset = await this.assetRepository.findOne({ where: { id: assetId } });
if (!asset) { if (!asset) {
throw new NotFoundException('Asset not found'); throw new NotFoundException('Asset not found');
} }

View File

@ -18,22 +18,22 @@ export class AuthService {
) {} ) {}
private async validateUser(loginCredential: LoginCredentialDto): Promise<UserEntity | null> { private async validateUser(loginCredential: LoginCredentialDto): Promise<UserEntity | null> {
const user = await this.userRepository.findOne( const user = await this.userRepository.findOne({
{ email: loginCredential.email }, where: {
{ email: loginCredential.email,
select: [
'id',
'email',
'password',
'salt',
'firstName',
'lastName',
'isAdmin',
'profileImagePath',
'shouldChangePassword',
],
}, },
); select: [
'id',
'email',
'password',
'salt',
'firstName',
'lastName',
'isAdmin',
'profileImagePath',
'shouldChangePassword',
],
});
if (!user) { if (!user) {
return null; return null;

View File

@ -33,7 +33,7 @@ export class CommunicationGateway implements OnGatewayConnection, OnGatewayDisco
? await this.immichJwtService.validateToken(accessToken) ? await this.immichJwtService.validateToken(accessToken)
: { status: false, userId: null }; : { status: false, userId: null };
if (!res.status) { if (!res.status || res.userId == null) {
client.emit('error', 'unauthorized'); client.emit('error', 'unauthorized');
client.disconnect(); client.disconnect();
return; return;

View File

@ -15,8 +15,10 @@ export class DeviceInfoService {
async create(createDeviceInfoDto: CreateDeviceInfoDto, authUser: AuthUserDto) { async create(createDeviceInfoDto: CreateDeviceInfoDto, authUser: AuthUserDto) {
const res = await this.deviceRepository.findOne({ const res = await this.deviceRepository.findOne({
deviceId: createDeviceInfoDto.deviceId, where: {
userId: authUser.id, deviceId: createDeviceInfoDto.deviceId,
userId: authUser.id,
},
}); });
if (res) { if (res) {

View File

@ -38,7 +38,7 @@ export class UserService {
} }
async getUserInfo(authUser: AuthUserDto) { async getUserInfo(authUser: AuthUserDto) {
return this.userRepository.findOne({ id: authUser.id }); return this.userRepository.findOne({ where: { id: authUser.id } });
} }
async getUserCount(isAdmin: boolean) { async getUserCount(isAdmin: boolean) {
@ -85,7 +85,7 @@ export class UserService {
} }
async updateUser(updateUserDto: UpdateUserDto) { async updateUser(updateUserDto: UpdateUserDto) {
const user = await this.userRepository.findOne(updateUserDto.id); const user = await this.userRepository.findOne({ where: { id: updateUserDto.id } });
if (!user) { if (!user) {
throw new NotFoundException('User not found'); throw new NotFoundException('User not found');
} }
@ -148,7 +148,7 @@ export class UserService {
async getUserProfileImage(userId: string, res: Res) { async getUserProfileImage(userId: string, res: Res) {
try { try {
const user = await this.userRepository.findOne({ id: userId }); const user = await this.userRepository.findOne({ where: { id: userId } });
if (!user) { if (!user) {
throw new NotFoundException('User not found'); throw new NotFoundException('User not found');
} }

View File

@ -25,7 +25,7 @@ export class AdminRolesGuard implements CanActivate {
return false; return false;
} }
const user = await this.userRepository.findOne(userId); const user = await this.userRepository.findOne({ where: { id: userId } });
if (!user) { if (!user) {
return false; return false;
} }

View File

@ -22,7 +22,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
async validate(payload: JwtPayloadDto) { async validate(payload: JwtPayloadDto) {
const { userId } = payload; const { userId } = payload;
const user = await this.usersRepository.findOne({ id: userId }); const user = await this.usersRepository.findOne({ where: { id: userId } });
if (!user) { if (!user) {
throw new UnauthorizedException('Failure to validate JWT payload'); throw new UnauthorizedException('Failure to validate JWT payload');

View File

@ -2,7 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule'; import { Cron, CronExpression } from '@nestjs/schedule';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { AssetEntity } from '@app/database/entities/asset.entity'; import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
import { InjectQueue } from '@nestjs/bull'; import { InjectQueue } from '@nestjs/bull';
import { Queue } from 'bull'; import { Queue } from 'bull';
import { randomUUID } from 'crypto'; import { randomUUID } from 'crypto';
@ -44,7 +44,7 @@ export class ScheduleTasksService {
async videoConversion() { async videoConversion() {
const assets = await this.assetRepository.find({ const assets = await this.assetRepository.find({
where: { where: {
type: 'VIDEO', type: AssetType.VIDEO,
mimeType: 'video/quicktime', mimeType: 'video/quicktime',
encodedVideoPath: '', encodedVideoPath: '',
}, },

View File

@ -1,15 +1,18 @@
import { getConnection } from 'typeorm'; import { DataSource } from 'typeorm';
import { CanActivate, ExecutionContext } from '@nestjs/common'; import { CanActivate, ExecutionContext } from '@nestjs/common';
import { TestingModuleBuilder } from '@nestjs/testing'; import { TestingModuleBuilder } from '@nestjs/testing';
import { AuthUserDto } from '../src/decorators/auth-user.decorator'; import { AuthUserDto } from '../src/decorators/auth-user.decorator';
import { JwtAuthGuard } from '../src/modules/immich-jwt/guards/jwt-auth.guard'; import { JwtAuthGuard } from '../src/modules/immich-jwt/guards/jwt-auth.guard';
import databaseConfig from '@app/database/config/database.config';
type CustomAuthCallback = () => AuthUserDto; type CustomAuthCallback = () => AuthUserDto;
export async function clearDb() { export async function clearDb() {
const entities = getConnection().entityMetadatas; const db = new DataSource(databaseConfig);
const entities = db.entityMetadatas;
for (const entity of entities) { for (const entity of entities) {
const repository = getConnection().getRepository(entity.name); const repository = db.getRepository(entity.name);
await repository.query(`TRUNCATE ${entity.tableName} RESTART IDENTITY CASCADE;`); await repository.query(`TRUNCATE ${entity.tableName} RESTART IDENTITY CASCADE;`);
} }
} }

View File

@ -1,6 +1,7 @@
import { TypeOrmModuleOptions } from '@nestjs/typeorm'; import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
export const databaseConfig: TypeOrmModuleOptions = { export const databaseConfig: PostgresConnectionOptions = {
type: 'postgres', type: 'postgres',
host: process.env.DB_HOSTNAME || 'immich_postgres', host: process.env.DB_HOSTNAME || 'immich_postgres',
port: 5432, port: 5432,
@ -10,11 +11,7 @@ export const databaseConfig: TypeOrmModuleOptions = {
entities: [__dirname + '/../**/*.entity.{js,ts}'], entities: [__dirname + '/../**/*.entity.{js,ts}'],
synchronize: false, synchronize: false,
migrations: [__dirname + '/../migrations/*.{js,ts}'], migrations: [__dirname + '/../migrations/*.{js,ts}'],
cli: {
migrationsDir: __dirname + '/../migrations',
},
migrationsRun: true, migrationsRun: true,
autoLoadEntities: true,
}; };
export default databaseConfig; export default databaseConfig;

2307
server/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,19 +26,19 @@
}, },
"dependencies": { "dependencies": {
"@mapbox/mapbox-sdk": "^0.13.3", "@mapbox/mapbox-sdk": "^0.13.3",
"@nestjs/bull": "^0.4.2", "@nestjs/bull": "^0.5.5",
"@nestjs/common": "^8.0.0", "@nestjs/common": "^8.4.7",
"@nestjs/config": "^1.1.6", "@nestjs/config": "^2.1.0",
"@nestjs/core": "^8.0.0", "@nestjs/core": "^8.4.7",
"@nestjs/jwt": "^8.0.0", "@nestjs/jwt": "^8.0.1",
"@nestjs/mapped-types": "*", "@nestjs/mapped-types": "*",
"@nestjs/passport": "^8.1.0", "@nestjs/passport": "^8.2.2",
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.4.7",
"@nestjs/platform-fastify": "^8.2.6", "@nestjs/platform-fastify": "^8.4.7",
"@nestjs/platform-socket.io": "^8.2.6", "@nestjs/platform-socket.io": "^8.4.7",
"@nestjs/schedule": "^2.0.1", "@nestjs/schedule": "^2.0.1",
"@nestjs/typeorm": "^8.0.3", "@nestjs/typeorm": "^8.1.4",
"@nestjs/websockets": "^8.2.6", "@nestjs/websockets": "^8.4.7",
"@socket.io/redis-adapter": "^7.1.0", "@socket.io/redis-adapter": "^7.1.0",
"axios": "^0.26.0", "axios": "^0.26.0",
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
@ -61,12 +61,12 @@
"sharp": "^0.28.0", "sharp": "^0.28.0",
"socket.io-redis": "^6.1.1", "socket.io-redis": "^6.1.1",
"systeminformation": "^5.11.0", "systeminformation": "^5.11.0",
"typeorm": "^0.2.41" "typeorm": "^0.3.6"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^8.2.4", "@nestjs/cli": "^8.2.8",
"@nestjs/schematics": "^8.0.0", "@nestjs/schematics": "^8.0.11",
"@nestjs/testing": "^8.0.0", "@nestjs/testing": "^8.4.7",
"@types/bcrypt": "^5.0.0", "@types/bcrypt": "^5.0.0",
"@types/bull": "^3.15.7", "@types/bull": "^3.15.7",
"@types/cron": "^2.0.0", "@types/cron": "^2.0.0",