Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): remove unused code #13367

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions server/src/cores/storage.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interf
import { getAssetFiles } from 'src/utils/asset.util';
import { getConfig } from 'src/utils/config';

export const THUMBNAIL_DIR = resolve(join(APP_MEDIA_LOCATION, StorageFolder.THUMBNAILS));
export const ENCODED_VIDEO_DIR = resolve(join(APP_MEDIA_LOCATION, StorageFolder.ENCODED_VIDEO));

export interface MoveRequest {
entityId: string;
pathType: PathType;
Expand Down Expand Up @@ -118,10 +115,6 @@ export class StorageCore {
return normalizedPath.startsWith(normalizedAppMediaLocation);
}

static isGeneratedAsset(path: string) {
return path.startsWith(THUMBNAIL_DIR) || path.startsWith(ENCODED_VIDEO_DIR);
}

async moveAssetImage(asset: AssetEntity, pathType: GeneratedImageType, format: ImageFormat) {
const { id: entityId, files } = asset;
const { thumbnailFile, previewFile } = getAssetFiles(files);
Expand Down
6 changes: 0 additions & 6 deletions server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ export interface IAssetRepository {
order?: FindOptionsOrder<AssetEntity>,
): Promise<AssetEntity | null>;
getWithout(pagination: PaginationOptions, property: WithoutProperty): Paginated<AssetEntity>;
getWith(
pagination: PaginationOptions,
property: WithProperty,
libraryId?: string,
withDeleted?: boolean,
): Paginated<AssetEntity>;
getRandom(userIds: string[], count: number): Promise<AssetEntity[]>;
getLastUpdatedAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise<AssetEntity | null>;
Expand Down
1 change: 0 additions & 1 deletion server/src/interfaces/database.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface IDatabaseRepository {
getPostgresVersion(): Promise<string>;
getPostgresVersionRange(): string;
createExtension(extension: DatabaseExtension): Promise<void>;
updateExtension(extension: DatabaseExtension, version?: string): Promise<void>;
updateVectorExtension(extension: VectorExtension, version?: string): Promise<VectorUpdateResult>;
reindex(index: VectorIndex): Promise<void>;
shouldReindex(name: VectorIndex): Promise<boolean>;
Expand Down
1 change: 0 additions & 1 deletion server/src/interfaces/map.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ export interface IMapRepository {
init(): Promise<void>;
reverseGeocode(point: GeoPoint): Promise<ReverseGeocodeResult>;
getMapMarkers(ownerIds: string[], albumIds: string[], options?: MapMarkerSearchOptions): Promise<MapMarker[]>;
fetchStyle(url: string): Promise<any>;
}
2 changes: 0 additions & 2 deletions server/src/interfaces/person.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export interface IPersonRepository {

create(person: Partial<PersonEntity>): Promise<PersonEntity>;
createAll(people: Partial<PersonEntity>[]): Promise<string[]>;
createFaces(entities: Partial<AssetFaceEntity>[]): Promise<string[]>;
delete(entities: PersonEntity[]): Promise<void>;
deleteAll(): Promise<void>;
deleteFaces(options: DeleteFacesOptions): Promise<void>;
refreshFaces(
facesToAdd: Partial<AssetFaceEntity>[],
Expand Down
33 changes: 0 additions & 33 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,39 +499,6 @@ export class AssetRepository implements IAssetRepository {
});
}

getWith(
pagination: PaginationOptions,
property: WithProperty,
libraryId?: string,
withDeleted = false,
): Paginated<AssetEntity> {
let where: FindOptionsWhere<AssetEntity> | FindOptionsWhere<AssetEntity>[] = {};

switch (property) {
case WithProperty.SIDECAR: {
where = [{ sidecarPath: Not(IsNull()), isVisible: true }];
break;
}

default: {
throw new Error(`Invalid getWith property: ${property}`);
}
}

if (libraryId) {
where = [{ ...where, libraryId }];
}

return paginate(this.repository, pagination, {
where,
withDeleted,
order: {
// Ensures correct order when paginating
createdAt: 'ASC',
},
});
}

getLastUpdatedAssetForAlbumId(albumId: string): Promise<AssetEntity | null> {
return this.repository.findOne({
where: { albums: { id: albumId } },
Expand Down
4 changes: 0 additions & 4 deletions server/src/repositories/database.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ export class DatabaseRepository implements IDatabaseRepository {
await this.dataSource.query(`CREATE EXTENSION IF NOT EXISTS ${extension}`);
}

async updateExtension(extension: DatabaseExtension, version?: string): Promise<void> {
await this.dataSource.query(`ALTER EXTENSION ${extension} UPDATE${version ? ` TO '${version}'` : ''}`);
}

async updateVectorExtension(extension: VectorExtension, targetVersion?: string): Promise<VectorUpdateResult> {
const { availableVersion, installedVersion } = await this.getExtensionVersion(extension);
if (!installedVersion) {
Expand Down
14 changes: 0 additions & 14 deletions server/src/repositories/map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ export class MapRepository implements IMapRepository {
}));
}

async fetchStyle(url: string) {
try {
const response = await fetch(url);

if (!response.ok) {
throw new Error(`Failed to fetch data from ${url} with status ${response.status}: ${await response.text()}`);
}

return response.json();
} catch (error) {
throw new Error(`Failed to fetch data from ${url}: ${error}`);
}
}

async reverseGeocode(point: GeoPoint): Promise<ReverseGeocodeResult> {
this.logger.debug(`Request: ${point.latitude},${point.longitude}`);

Expand Down
9 changes: 0 additions & 9 deletions server/src/repositories/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ export class PersonRepository implements IPersonRepository {
await this.personRepository.remove(entities);
}

async deleteAll(): Promise<void> {
await this.personRepository.clear();
}

async deleteFaces({ sourceType }: DeleteFacesOptions): Promise<void> {
await this.assetFaceRepository
.createQueryBuilder('asset_faces')
Expand Down Expand Up @@ -269,11 +265,6 @@ export class PersonRepository implements IPersonRepository {
return results.map((person) => person.id);
}

async createFaces(entities: AssetFaceEntity[]): Promise<string[]> {
const res = await this.assetFaceRepository.save(entities);
return res.map((row) => row.id);
}

async refreshFaces(
facesToAdd: Partial<AssetFaceEntity>[],
faceIdsToRemove: string[],
Expand Down
36 changes: 27 additions & 9 deletions server/src/services/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interf
import { IUserRepository } from 'src/interfaces/user.interface';
import { AuthService } from 'src/services/auth.service';
import { keyStub } from 'test/fixtures/api-key.stub';
import { authStub, loginResponseStub } from 'test/fixtures/auth.stub';
import { authStub } from 'test/fixtures/auth.stub';
import { sessionStub } from 'test/fixtures/session.stub';
import { sharedLinkStub } from 'test/fixtures/shared-link.stub';
import { systemConfigStub } from 'test/fixtures/system-config.stub';
import { userStub } from 'test/fixtures/user.stub';
import { newTestService } from 'test/utils';
import { Mocked } from 'vitest';

const oauthResponse = {
accessToken: 'cmFuZG9tLWJ5dGVz',
userId: 'user-id',
userEmail: '[email protected]',
name: 'immich_name',
profileImagePath: '',
isAdmin: false,
shouldChangePassword: false,
};

// const token = Buffer.from('my-api-key', 'utf8').toString('base64');

const email = '[email protected]';
Expand Down Expand Up @@ -100,7 +110,15 @@ describe('AuthService', () => {
it('should successfully log the user in', async () => {
userMock.getByEmail.mockResolvedValue(userStub.user1);
sessionMock.create.mockResolvedValue(sessionStub.valid);
await expect(sut.login(fixtures.login, loginDetails)).resolves.toEqual(loginResponseStub.user1password);
await expect(sut.login(fixtures.login, loginDetails)).resolves.toEqual({
accessToken: 'cmFuZG9tLWJ5dGVz',
userId: 'user-id',
userEmail: '[email protected]',
name: 'immich_name',
profileImagePath: '',
isAdmin: false,
shouldChangePassword: false,
});
expect(userMock.getByEmail).toHaveBeenCalledTimes(1);
});
});
Expand Down Expand Up @@ -469,7 +487,7 @@ describe('AuthService', () => {
sessionMock.create.mockResolvedValue(sessionStub.valid);

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.getByEmail).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -498,7 +516,7 @@ describe('AuthService', () => {
sessionMock.create.mockResolvedValue(sessionStub.valid);

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.getByEmail).toHaveBeenCalledTimes(2); // second call is for domain check before create
Expand Down Expand Up @@ -546,7 +564,7 @@ describe('AuthService', () => {
userMock.create.mockResolvedValue(userStub.user1);

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
Expand All @@ -560,7 +578,7 @@ describe('AuthService', () => {
oauthMock.getProfile.mockResolvedValue({ sub, email, immich_quota: 'abc' });

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
Expand All @@ -574,7 +592,7 @@ describe('AuthService', () => {
oauthMock.getProfile.mockResolvedValue({ sub, email, immich_quota: -5 });

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
Expand All @@ -588,7 +606,7 @@ describe('AuthService', () => {
oauthMock.getProfile.mockResolvedValue({ sub, email, immich_quota: 0 });

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.create).toHaveBeenCalledWith({
Expand All @@ -608,7 +626,7 @@ describe('AuthService', () => {
oauthMock.getProfile.mockResolvedValue({ sub, email, immich_quota: 5 });

await expect(sut.callback({ url: 'http://immich/auth/login?code=abc123' }, loginDetails)).resolves.toEqual(
loginResponseStub.user1oauth,
oauthResponse,
);

expect(userMock.create).toHaveBeenCalledWith({
Expand Down
4 changes: 0 additions & 4 deletions server/src/services/library.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ describe(LibraryService.name, () => {

describe('handleQueueAssetRefresh', () => {
it('should queue refresh of a new asset', async () => {
assetMock.getWith.mockResolvedValue({ items: [], hasNextPage: false });

libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
storageMock.walk.mockImplementation(mockWalk);

Expand Down Expand Up @@ -179,8 +177,6 @@ describe(LibraryService.name, () => {

storageMock.checkFileExists.mockResolvedValue(true);

assetMock.getWith.mockResolvedValue({ items: [], hasNextPage: false });

libraryMock.get.mockResolvedValue(libraryStub.externalLibraryWithImportPaths1);

await sut.handleQueueSyncFiles({ id: libraryStub.externalLibraryWithImportPaths1.id });
Expand Down
6 changes: 0 additions & 6 deletions server/src/services/person.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ describe(PersonService.name, () => {
'/uploads/user-id/thumbs/path.jpg',
expect.objectContaining({ minScore: 0.7, modelName: 'buffalo_l' }),
);
expect(personMock.createFaces).not.toHaveBeenCalled();
expect(jobMock.queue).not.toHaveBeenCalled();
expect(jobMock.queueAll).not.toHaveBeenCalled();

Expand All @@ -733,7 +732,6 @@ describe(PersonService.name, () => {
});

it('should create a face with no person and queue recognition job', async () => {
personMock.createFaces.mockResolvedValue([faceStub.face1.id]);
machineLearningMock.detectFaces.mockResolvedValue(detectFaceMock);
assetMock.getByIds.mockResolvedValue([assetStub.image]);

Expand Down Expand Up @@ -761,7 +759,6 @@ describe(PersonService.name, () => {
});

it('should add new face and delete an existing face not among the new detected faces', async () => {
personMock.createFaces.mockResolvedValue([faceStub.face1.id]);
machineLearningMock.detectFaces.mockResolvedValue(detectFaceMock);
assetMock.getByIds.mockResolvedValue([{ ...assetStub.image, faces: [faceStub.primaryFace1] }]);

Expand Down Expand Up @@ -816,7 +813,6 @@ describe(PersonService.name, () => {

expect(personMock.reassignFaces).not.toHaveBeenCalled();
expect(personMock.create).not.toHaveBeenCalled();
expect(personMock.createFaces).not.toHaveBeenCalled();
});

it('should fail if face does not have asset', async () => {
Expand All @@ -827,7 +823,6 @@ describe(PersonService.name, () => {

expect(personMock.reassignFaces).not.toHaveBeenCalled();
expect(personMock.create).not.toHaveBeenCalled();
expect(personMock.createFaces).not.toHaveBeenCalled();
});

it('should skip if face already has an assigned person', async () => {
Expand All @@ -837,7 +832,6 @@ describe(PersonService.name, () => {

expect(personMock.reassignFaces).not.toHaveBeenCalled();
expect(personMock.create).not.toHaveBeenCalled();
expect(personMock.createFaces).not.toHaveBeenCalled();
});

it('should match existing person', async () => {
Expand Down
51 changes: 0 additions & 51 deletions server/test/fixtures/album.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,55 +155,4 @@ export const albumStub = {
isActivityEnabled: true,
order: AssetOrder.DESC,
}),
emptyWithInvalidThumbnail: Object.freeze<AlbumEntity>({
id: 'album-5',
albumName: 'Empty album with invalid thumbnail',
description: '',
ownerId: authStub.admin.user.id,
owner: userStub.admin,
assets: [],
albumThumbnailAsset: null,
albumThumbnailAssetId: null,
createdAt: new Date(),
updatedAt: new Date(),
deletedAt: null,
sharedLinks: [],
albumUsers: [],
isActivityEnabled: true,
order: AssetOrder.DESC,
}),
oneAssetInvalidThumbnail: Object.freeze<AlbumEntity>({
id: 'album-6',
albumName: 'Album with one asset and invalid thumbnail',
description: '',
ownerId: authStub.admin.user.id,
owner: userStub.admin,
assets: [assetStub.image],
albumThumbnailAsset: assetStub.livePhotoMotionAsset,
albumThumbnailAssetId: assetStub.livePhotoMotionAsset.id,
createdAt: new Date(),
updatedAt: new Date(),
deletedAt: null,
sharedLinks: [],
albumUsers: [],
isActivityEnabled: true,
order: AssetOrder.DESC,
}),
oneAssetValidThumbnail: Object.freeze<AlbumEntity>({
id: 'album-6',
albumName: 'Album with one asset and invalid thumbnail',
description: '',
ownerId: authStub.admin.user.id,
owner: userStub.admin,
assets: [assetStub.image],
albumThumbnailAsset: assetStub.image,
albumThumbnailAssetId: assetStub.image.id,
createdAt: new Date(),
updatedAt: new Date(),
deletedAt: null,
sharedLinks: [],
albumUsers: [],
isActivityEnabled: true,
order: AssetOrder.DESC,
}),
};
4 changes: 0 additions & 4 deletions server/test/fixtures/api-key.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ export const keyStub = {
user: userStub.admin,
} as APIKeyEntity),
};

export const apiKeyCreateStub = {
name: 'API Key',
};
Loading
Loading