2018-11-24 18:50:11 +08:00
|
|
|
import * as fs from 'fs';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {SQLConnection} from '../../../../../src/backend/model/database/SQLConnection';
|
|
|
|
import {GalleryManager} from '../../../../../src/backend/model/database/GalleryManager';
|
2021-06-28 01:33:37 +08:00
|
|
|
import {DirectoryBaseDTO, DirectoryDTOUtils, ParentDirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
2022-06-25 00:05:45 +08:00
|
|
|
import {TestHelper} from '../../../../TestHelper';
|
2018-11-24 18:50:11 +08:00
|
|
|
import {Connection} from 'typeorm';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
|
|
|
import {MediaDTO} from '../../../../../src/common/entities/MediaDTO';
|
|
|
|
import {FileDTO} from '../../../../../src/common/entities/FileDTO';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {IndexingManager} from '../../../../../src/backend/model/database/IndexingManager';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
2021-04-02 03:48:38 +08:00
|
|
|
import {DBTestHelper} from '../../../DBTestHelper';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {DiskMangerWorker} from '../../../../../src/backend/model/threading/DiskMangerWorker';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {ReIndexingSensitivity} from '../../../../../src/common/config/private/PrivateConfig';
|
2021-05-30 21:09:47 +08:00
|
|
|
import {SearchQueryTypes, TextSearch, TextSearchQueryMatchTypes} from '../../../../../src/common/entities/SearchQueryDTO';
|
|
|
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
|
|
|
import * as path from 'path';
|
|
|
|
import {DiskManager} from '../../../../../src/backend/model/DiskManger';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {AlbumManager} from '../../../../../src/backend/model/database/AlbumManager';
|
2021-07-07 03:37:19 +08:00
|
|
|
import {SortingMethods} from '../../../../../src/common/entities/SortingMethods';
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2022-05-16 04:07:46 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2021-03-28 05:24:13 +08:00
|
|
|
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
|
2022-05-16 04:07:46 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2021-03-28 05:24:13 +08:00
|
|
|
const chai = require('chai');
|
|
|
|
|
|
|
|
chai.use(deepEqualInAnyOrder);
|
|
|
|
const {expect} = chai;
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
class GalleryManagerTest extends GalleryManager {
|
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
public async getDirIdAndTime(connection: Connection, directoryName: string, directoryParent: string) {
|
|
|
|
return super.getDirIdAndTime(connection, directoryName, directoryParent);
|
2018-11-24 18:50:11 +08:00
|
|
|
}
|
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
public async getParentDirFromId(connection: Connection, dir: number): Promise<ParentDirectoryDTO> {
|
|
|
|
return super.getParentDirFromId(connection, dir);
|
2018-11-24 18:50:11 +08:00
|
|
|
}
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class IndexingManagerTest extends IndexingManager {
|
|
|
|
|
2018-12-09 18:37:12 +08:00
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public async queueForSave(scannedDirectory: ParentDirectoryDTO): Promise<void> {
|
2018-12-09 18:37:12 +08:00
|
|
|
return super.queueForSave(scannedDirectory);
|
|
|
|
}
|
2019-01-14 00:38:39 +08:00
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public async saveToDB(scannedDirectory: ParentDirectoryDTO): Promise<void> {
|
2021-06-01 01:55:27 +08:00
|
|
|
return await super.saveToDB(scannedDirectory);
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
2018-11-24 18:50:11 +08:00
|
|
|
}
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
// to help WebStorm to handle the test cases
|
2022-05-16 04:07:46 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2019-01-28 03:36:42 +08:00
|
|
|
declare let describe: any;
|
|
|
|
declare const after: any;
|
2019-02-07 23:21:23 +08:00
|
|
|
declare const it: any;
|
2022-05-16 04:07:46 +08:00
|
|
|
// eslint-disable-next-line prefer-const
|
2021-04-02 03:48:38 +08:00
|
|
|
describe = DBTestHelper.describe();
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2019-01-28 03:36:42 +08:00
|
|
|
await sqlHelper.initDB();
|
2021-05-30 21:09:47 +08:00
|
|
|
// ObjectManagers.getInstance().PersonManager = new PersonManager();
|
|
|
|
// ObjectManagers.getInstance().VersionManager = new VersionManager();
|
2018-11-24 18:50:11 +08:00
|
|
|
});
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
|
2021-05-30 21:09:47 +08:00
|
|
|
afterEach(async () => {
|
|
|
|
Config.loadSync();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Preview.Sorting = [SortingMethods.descRating];
|
2019-01-28 03:36:42 +08:00
|
|
|
await sqlHelper.clearDB();
|
2018-11-24 18:50:11 +08:00
|
|
|
});
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
const setPartial = (dir: DirectoryBaseDTO) => {
|
2021-03-28 18:43:13 +08:00
|
|
|
if (!dir.preview && dir.media && dir.media.length > 0) {
|
|
|
|
dir.preview = dir.media[0];
|
|
|
|
}
|
2021-03-28 05:24:13 +08:00
|
|
|
dir.isPartial = true;
|
|
|
|
delete dir.directories;
|
|
|
|
delete dir.metaFile;
|
|
|
|
delete dir.media;
|
|
|
|
};
|
|
|
|
|
2021-07-07 03:37:19 +08:00
|
|
|
const makePreview = (m: MediaDTO) => {
|
|
|
|
delete (m.directory as ParentDirectoryDTO).id;
|
|
|
|
delete m.metadata;
|
|
|
|
return m;
|
|
|
|
};
|
|
|
|
|
|
|
|
const indexifyReturn = (dir: DirectoryBaseDTO): DirectoryBaseDTO => {
|
|
|
|
const d = Utils.clone(dir);
|
|
|
|
|
|
|
|
delete d.preview;
|
|
|
|
if (d.directories) {
|
|
|
|
for (const subD of d.directories) {
|
|
|
|
if (subD.preview) {
|
|
|
|
delete subD.preview.metadata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return d;
|
|
|
|
};
|
|
|
|
|
|
|
|
const removeIds = (dir: DirectoryBaseDTO): DirectoryBaseDTO => {
|
2018-11-24 18:50:11 +08:00
|
|
|
delete dir.id;
|
|
|
|
dir.media.forEach((media: MediaDTO) => {
|
|
|
|
delete media.id;
|
|
|
|
});
|
2021-03-28 04:31:19 +08:00
|
|
|
if (dir.preview) {
|
|
|
|
delete dir.preview.id;
|
|
|
|
}
|
2018-11-26 07:26:29 +08:00
|
|
|
if (dir.metaFile) {
|
2018-12-02 19:30:35 +08:00
|
|
|
if (dir.metaFile.length === 0) {
|
|
|
|
delete dir.metaFile;
|
|
|
|
} else {
|
|
|
|
dir.metaFile.forEach((file: FileDTO) => {
|
|
|
|
delete file.id;
|
|
|
|
});
|
|
|
|
}
|
2018-11-26 07:26:29 +08:00
|
|
|
}
|
2018-11-24 18:50:11 +08:00
|
|
|
if (dir.directories) {
|
2021-06-28 01:33:37 +08:00
|
|
|
dir.directories.forEach((directory: DirectoryBaseDTO) => {
|
2018-11-24 18:50:11 +08:00
|
|
|
removeIds(directory);
|
|
|
|
});
|
|
|
|
}
|
2021-07-07 03:37:19 +08:00
|
|
|
|
|
|
|
return dir;
|
2018-11-24 18:50:11 +08:00
|
|
|
};
|
|
|
|
|
2019-02-07 23:21:23 +08:00
|
|
|
it('should support case sensitive file names', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo2');
|
|
|
|
p1.name = 'test.jpg';
|
|
|
|
p2.name = 'Test.jpg';
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2019-02-07 23:21:23 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2019-02-07 23:21:23 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2021-07-07 03:37:19 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(removeIds(selected))))
|
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2019-02-07 23:21:23 +08:00
|
|
|
});
|
|
|
|
|
2019-07-21 15:46:07 +08:00
|
|
|
|
2022-05-16 04:07:46 +08:00
|
|
|
it('should stop indexing on empty folder', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
|
|
|
|
ProjectPath.reset();
|
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
|
|
|
|
Config.Server.Threading.enabled = false;
|
|
|
|
|
|
|
|
await ObjectManagers.getInstance().IndexingManager.indexDirectory('.');
|
|
|
|
if (ObjectManagers.getInstance().IndexingManager.IsSavingInProgress) {
|
|
|
|
await ObjectManagers.getInstance().IndexingManager.SavingReady;
|
|
|
|
}
|
|
|
|
|
|
|
|
const directoryPath = GalleryManager.parseRelativeDirePath(
|
|
|
|
'.'
|
|
|
|
);
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, directoryPath.name, directoryPath.parent)).id);
|
2022-05-16 04:07:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
expect(selected?.media?.length)
|
|
|
|
.to.be.greaterThan(0);
|
2022-12-05 05:23:51 +08:00
|
|
|
if (!fs.existsSync(sqlHelper.tempDir)) {
|
|
|
|
fs.mkdirSync(sqlHelper.tempDir);
|
|
|
|
}
|
|
|
|
const tmpDir = path.join(sqlHelper.tempDir, '/rnd5sdf_emptyDir');
|
2022-05-16 04:07:46 +08:00
|
|
|
fs.mkdirSync(tmpDir);
|
|
|
|
ProjectPath.ImageFolder = tmpDir;
|
|
|
|
let notFailed = false;
|
|
|
|
try {
|
|
|
|
await ObjectManagers.getInstance().IndexingManager.indexDirectory('.');
|
|
|
|
notFailed = true;
|
|
|
|
} catch (e) {
|
|
|
|
// it expected to fail
|
|
|
|
}
|
|
|
|
if (notFailed) {
|
|
|
|
expect(true).to.equal(false, 'indexDirectory is expected to fail');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-07-21 15:46:07 +08:00
|
|
|
it('should support case sensitive directory', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parent');
|
2019-07-21 15:46:07 +08:00
|
|
|
const subDir1 = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(subDir1, 'subPhoto1', 0);
|
|
|
|
const subDir2 = TestHelper.getRandomizedDirectoryEntry(parent, 'SUBDIR');
|
2021-03-28 05:28:01 +08:00
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
|
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2019-07-21 15:46:07 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:24:13 +08:00
|
|
|
setPartial(subDir1);
|
|
|
|
setPartial(subDir2);
|
2019-07-21 15:46:07 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2019-07-21 15:46:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should support case sensitive directory path', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent1 = TestHelper.getRandomizedDirectoryEntry(null, 'parent');
|
|
|
|
const parent2 = TestHelper.getRandomizedDirectoryEntry(null, 'PARENT');
|
|
|
|
const subDir1 = TestHelper.getRandomizedDirectoryEntry(parent1, 'subDir');
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(subDir1, 'subPhoto1', 0);
|
2021-03-28 05:28:01 +08:00
|
|
|
const subDir2 = TestHelper.getRandomizedDirectoryEntry(parent2, 'subDir2');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent1);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent1) as ParentDirectoryDTO);
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent2);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent2) as ParentDirectoryDTO);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
|
|
|
{
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent1.name, parent1.path)).id);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2019-07-21 15:46:07 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:24:13 +08:00
|
|
|
setPartial(subDir1);
|
2019-07-21 15:46:07 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent1)));
|
2019-07-21 15:46:07 +08:00
|
|
|
}
|
|
|
|
{
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent2.name, parent2.path)).id);
|
2019-07-21 15:46:07 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2019-07-21 15:46:07 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:28:01 +08:00
|
|
|
setPartial(subDir2);
|
2019-07-21 15:46:07 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent2)));
|
2019-07-21 15:46:07 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-14 19:14:28 +08:00
|
|
|
it('should support emoji in names', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parent dir 😀');
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
2022-03-13 03:38:08 +08:00
|
|
|
p1.name = 'test 😀.jpg';
|
2022-01-14 19:14:28 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2022-01-14 19:14:28 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
|
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2022-01-14 19:14:28 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2022-01-14 19:14:28 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(removeIds(selected))))
|
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
|
|
|
});
|
|
|
|
|
2019-07-21 15:46:07 +08:00
|
|
|
|
2021-03-28 18:43:13 +08:00
|
|
|
it('should select preview', async () => {
|
2021-06-28 01:33:37 +08:00
|
|
|
const selectDirectory = async (gmTest: GalleryManagerTest, dir: DirectoryBaseDTO): Promise<ParentDirectoryDTO> => {
|
2021-03-28 18:43:13 +08:00
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gmTest.getParentDirFromId(conn,
|
|
|
|
(await gmTest.getDirIdAndTime(conn, dir.name, dir.path)).id);
|
2021-03-28 18:43:13 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2021-03-28 18:43:13 +08:00
|
|
|
removeIds(selected);
|
|
|
|
return selected;
|
|
|
|
};
|
|
|
|
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parent');
|
|
|
|
|
|
|
|
|
|
|
|
const checkParent = async () => {
|
|
|
|
const selected = await selectDirectory(gm, parent);
|
2021-07-07 03:37:19 +08:00
|
|
|
const cloned = Utils.removeNullOrEmptyObj(indexifyReturn(parent));
|
2021-03-28 18:43:13 +08:00
|
|
|
if (cloned.directories) {
|
|
|
|
cloned.directories.forEach(d => setPartial(d));
|
|
|
|
}
|
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
|
|
|
.to.deep.equalInAnyOrder(cloned);
|
|
|
|
};
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
const saveToDBAndCheck = async (dir: DirectoryBaseDTO) => {
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(dir) as ParentDirectoryDTO);
|
2021-03-28 18:43:13 +08:00
|
|
|
await checkParent();
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.addReferences(parent);
|
2021-03-28 18:43:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
await saveToDBAndCheck(parent);
|
|
|
|
|
|
|
|
const subDir1 = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
|
|
|
|
await saveToDBAndCheck(parent);
|
|
|
|
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(subDir1, 'subPhoto1', 0);
|
|
|
|
await saveToDBAndCheck(subDir1);
|
|
|
|
|
|
|
|
const subDir2 = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir2');
|
|
|
|
await saveToDBAndCheck(parent);
|
|
|
|
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0);
|
|
|
|
await saveToDBAndCheck(subDir2);
|
|
|
|
|
|
|
|
const p = TestHelper.getRandomizedPhotoEntry(parent, 'photo', 0);
|
|
|
|
await saveToDBAndCheck(parent);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-07-26 05:36:57 +08:00
|
|
|
it('should save parent after child', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parentDir');
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
|
|
|
|
const subDir = TestHelper.getRandomizedDirectoryEntry(null, 'subDir');
|
|
|
|
subDir.path = DiskMangerWorker.pathFromParent(parent);
|
|
|
|
const sp1 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto1', 0);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp1.metadata.rating = 5;
|
2019-07-26 05:36:57 +08:00
|
|
|
const sp2 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto2', 0);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp2.metadata.rating = 3;
|
|
|
|
subDir.preview = sp1;
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Preview.Sorting = [SortingMethods.descRating];
|
2019-07-26 05:36:57 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(subDir);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(subDir) as ParentDirectoryDTO);
|
2019-07-26 05:36:57 +08:00
|
|
|
|
|
|
|
parent.directories.push(subDir);
|
|
|
|
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2019-07-26 05:36:57 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
|
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2019-07-26 05:36:57 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2019-07-26 05:36:57 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:24:13 +08:00
|
|
|
setPartial(subDir);
|
2019-07-26 05:36:57 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2019-07-26 05:36:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should save root parent after child', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry(null, '.');
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
|
|
|
|
const subDir = TestHelper.getRandomizedDirectoryEntry(null, 'subDir');
|
|
|
|
subDir.path = DiskMangerWorker.pathFromParent(parent);
|
|
|
|
const sp1 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto1', 0);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp1.metadata.rating = 5;
|
2019-07-26 05:36:57 +08:00
|
|
|
const sp2 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto2', 0);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp2.metadata.rating = 3;
|
|
|
|
subDir.preview = sp1;
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Preview.Sorting = [SortingMethods.descRating];
|
2019-07-26 05:36:57 +08:00
|
|
|
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(subDir);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(subDir) as ParentDirectoryDTO);
|
2019-07-26 05:36:57 +08:00
|
|
|
|
|
|
|
parent.directories.push(subDir);
|
|
|
|
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2019-07-26 05:36:57 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2019-07-26 05:36:57 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2019-07-26 05:36:57 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:24:13 +08:00
|
|
|
setPartial(subDir);
|
2019-07-26 05:36:57 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2019-07-26 05:36:57 +08:00
|
|
|
});
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
it('should save parent directory', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
2019-01-14 00:38:39 +08:00
|
|
|
const im = new IndexingManagerTest();
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo2');
|
2018-11-26 07:26:29 +08:00
|
|
|
const gpx = TestHelper.getRandomizedGPXEntry(parent, 'GPX1');
|
2018-11-24 18:50:11 +08:00
|
|
|
const subDir = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
|
2019-01-14 00:38:39 +08:00
|
|
|
const sp1 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto1', 0);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp1.metadata.rating = 5;
|
2019-01-14 00:38:39 +08:00
|
|
|
const sp2 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto2', 0);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp2.metadata.rating = 3;
|
|
|
|
subDir.preview = sp1;
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Preview.Sorting = [SortingMethods.descRating];
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2018-11-24 18:50:11 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:24:13 +08:00
|
|
|
setPartial(subDir);
|
2018-12-06 00:29:33 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2018-11-24 18:50:11 +08:00
|
|
|
});
|
|
|
|
|
2019-02-03 07:18:35 +08:00
|
|
|
|
|
|
|
it('should save photos with extreme parameters', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo2');
|
2022-03-31 05:11:11 +08:00
|
|
|
const minFloat = parseFloat((1.1 * Math.pow(10, -38)).toFixed(10));
|
|
|
|
const maxFloat = parseFloat((3.4 * Math.pow(10, +38)).toFixed(10));
|
2019-02-03 07:18:35 +08:00
|
|
|
p1.metadata.cameraData.fStop = minFloat;
|
|
|
|
p2.metadata.cameraData.fStop = maxFloat;
|
|
|
|
p1.metadata.cameraData.exposure = minFloat;
|
|
|
|
p2.metadata.cameraData.exposure = maxFloat;
|
2019-02-03 11:42:15 +08:00
|
|
|
p1.metadata.cameraData.focalLength = minFloat;
|
|
|
|
p2.metadata.cameraData.focalLength = maxFloat;
|
2019-02-03 07:18:35 +08:00
|
|
|
p1.metadata.positionData.GPSData.latitude = maxFloat;
|
|
|
|
p2.metadata.positionData.GPSData.latitude = minFloat;
|
|
|
|
p1.metadata.positionData.GPSData.longitude = maxFloat;
|
|
|
|
p2.metadata.positionData.GPSData.longitude = minFloat;
|
|
|
|
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2019-02-03 07:18:35 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2019-02-03 07:18:35 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2019-02-03 07:18:35 +08:00
|
|
|
removeIds(selected);
|
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2019-02-03 07:18:35 +08:00
|
|
|
});
|
|
|
|
|
2018-12-02 06:53:35 +08:00
|
|
|
it('should skip meta files', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
2019-01-14 00:38:39 +08:00
|
|
|
const im = new IndexingManagerTest();
|
2018-12-02 06:53:35 +08:00
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo2');
|
|
|
|
const gpx = TestHelper.getRandomizedGPXEntry(parent, 'GPX1');
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.MetaFile.gpx = true;
|
|
|
|
Config.MetaFile.markdown = true;
|
|
|
|
Config.MetaFile.pg2conf = true;
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2018-12-02 06:53:35 +08:00
|
|
|
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.MetaFile.gpx = false;
|
|
|
|
Config.MetaFile.markdown = false;
|
|
|
|
Config.MetaFile.pg2conf = false;
|
2018-12-02 06:53:35 +08:00
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2018-12-02 06:53:35 +08:00
|
|
|
|
|
|
|
delete parent.metaFile;
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2018-12-02 06:53:35 +08:00
|
|
|
removeIds(selected);
|
2018-12-06 00:29:33 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2018-12-02 06:53:35 +08:00
|
|
|
});
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
it('should update sub directory', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
2019-01-14 00:38:39 +08:00
|
|
|
const im = new IndexingManagerTest();
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
parent.name = 'parent';
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent);
|
|
|
|
const subDir = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
|
|
|
|
subDir.name = 'subDir';
|
|
|
|
const sp1 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto1');
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const sp2 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto2');
|
|
|
|
const sp3 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto3');
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(subDir);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(subDir) as ParentDirectoryDTO);
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, subDir.name, subDir.path)).id);
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
// subDir.isPartial = true;
|
|
|
|
// delete subDir.directories;
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2018-11-24 18:50:11 +08:00
|
|
|
delete subDir.parent;
|
2018-12-02 19:30:35 +08:00
|
|
|
delete subDir.metaFile;
|
2018-11-24 18:50:11 +08:00
|
|
|
removeIds(selected);
|
|
|
|
// selected.directories[0].parent = selected;
|
2018-12-06 00:29:33 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(subDir)));
|
2018-12-09 18:37:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should avoid race condition', async () => {
|
|
|
|
const conn = await SQLConnection.getConnection();
|
|
|
|
const gm = new GalleryManagerTest();
|
2019-01-14 00:38:39 +08:00
|
|
|
const im = new IndexingManagerTest();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.MetaFile.gpx = true;
|
|
|
|
Config.MetaFile.markdown = true;
|
|
|
|
Config.MetaFile.pg2conf = true;
|
2018-12-09 18:37:12 +08:00
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo2');
|
|
|
|
const gpx = TestHelper.getRandomizedGPXEntry(parent, 'GPX1');
|
|
|
|
const subDir = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
|
2019-01-14 00:38:39 +08:00
|
|
|
const sp1 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto1', 1);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp1.metadata.rating = 5;
|
2019-01-14 00:38:39 +08:00
|
|
|
const sp2 = TestHelper.getRandomizedPhotoEntry(subDir, 'subPhoto2', 1);
|
2021-07-07 03:37:19 +08:00
|
|
|
sp2.metadata.rating = 3;
|
|
|
|
subDir.preview = sp1;
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Preview.Sorting = [SortingMethods.descRating];
|
2018-12-09 18:37:12 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
const s1 = im.queueForSave(Utils.clone(parent) as ParentDirectoryDTO);
|
|
|
|
const s2 = im.queueForSave(Utils.clone(parent) as ParentDirectoryDTO);
|
|
|
|
const s3 = im.queueForSave(Utils.clone(parent) as ParentDirectoryDTO);
|
2018-12-09 18:37:12 +08:00
|
|
|
|
|
|
|
await Promise.all([s1, s2, s3]);
|
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2018-12-09 18:37:12 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2018-12-09 18:37:12 +08:00
|
|
|
removeIds(selected);
|
2021-03-28 05:24:13 +08:00
|
|
|
setPartial(subDir);
|
2021-04-18 21:48:35 +08:00
|
|
|
parent.directories.forEach(d => delete (d.preview.metadata as any).faces);
|
2019-01-14 00:38:39 +08:00
|
|
|
delete sp1.metadata.faces;
|
|
|
|
delete sp2.metadata.faces;
|
2018-12-09 18:37:12 +08:00
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equalInAnyOrder(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2018-11-24 18:50:11 +08:00
|
|
|
});
|
|
|
|
|
2021-05-24 22:03:53 +08:00
|
|
|
it('should reset DB', async () => {
|
|
|
|
const gm = new GalleryManagerTest();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
const p2 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo2');
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2021-05-24 22:03:53 +08:00
|
|
|
|
|
|
|
const conn = await SQLConnection.getConnection();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, parent.name, parent.path)).id);
|
2021-05-24 22:03:53 +08:00
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(selected);
|
2021-05-24 22:03:53 +08:00
|
|
|
removeIds(selected);
|
|
|
|
expect(Utils.clone(Utils.removeNullOrEmptyObj(selected)))
|
2021-07-07 03:37:19 +08:00
|
|
|
.to.deep.equal(Utils.removeNullOrEmptyObj(indexifyReturn(parent)));
|
2021-05-24 22:03:53 +08:00
|
|
|
|
|
|
|
await im.resetDB();
|
2022-12-05 05:23:51 +08:00
|
|
|
const selectReset = await gm.getDirIdAndTime(conn, parent.name, parent.path);
|
2022-03-31 05:11:11 +08:00
|
|
|
expect(selectReset).to.deep.equal(null);
|
2021-05-24 22:03:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
(it('should save 1500 photos', async () => {
|
2018-12-18 07:05:12 +08:00
|
|
|
const conn = await SQLConnection.getConnection();
|
|
|
|
const gm = new GalleryManagerTest();
|
2019-01-14 00:38:39 +08:00
|
|
|
const im = new IndexingManagerTest();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.MetaFile.gpx = true;
|
|
|
|
Config.MetaFile.markdown = true;
|
|
|
|
Config.MetaFile.pg2conf = true;
|
2018-12-18 07:05:12 +08:00
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(Utils.clone(parent) as ParentDirectoryDTO);
|
2018-12-18 07:05:12 +08:00
|
|
|
const subDir = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
|
|
|
|
for (let i = 0; i < 1500; i++) {
|
|
|
|
TestHelper.getRandomizedPhotoEntry(subDir, 'p' + i);
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
DirectoryDTOUtils.removeReferences(parent);
|
2021-06-28 01:33:37 +08:00
|
|
|
await im.saveToDB(subDir as ParentDirectoryDTO);
|
2018-12-18 07:05:12 +08:00
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
const selected = await gm.getParentDirFromId(conn,
|
|
|
|
(await gm.getDirIdAndTime(conn, subDir.name, subDir.path)).id);
|
2021-03-28 05:24:13 +08:00
|
|
|
expect(selected.media.length).to.equal(subDir.media.length);
|
2019-01-14 00:38:39 +08:00
|
|
|
}) as any).timeout(40000);
|
2018-12-18 07:05:12 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
DBTestHelper.savedDescribe('Test listDirectory', () => {
|
2018-12-22 07:09:07 +08:00
|
|
|
const statSync = fs.statSync;
|
|
|
|
let dirTime = 0;
|
|
|
|
const indexedTime = {
|
|
|
|
lastScanned: 0,
|
|
|
|
lastModified: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
dirTime = 0;
|
2019-01-14 00:38:39 +08:00
|
|
|
|
2019-02-16 00:47:09 +08:00
|
|
|
ObjectManagers.getInstance().IndexingManager = new IndexingManagerTest();
|
2018-12-22 07:09:07 +08:00
|
|
|
indexedTime.lastModified = 0;
|
|
|
|
indexedTime.lastScanned = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2022-05-16 04:07:46 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2018-12-22 07:09:07 +08:00
|
|
|
// @ts-ignore
|
|
|
|
fs.statSync = statSync;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with re indexing severity low', async () => {
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
2018-12-22 07:09:07 +08:00
|
|
|
|
2022-05-16 04:07:46 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2018-12-22 07:09:07 +08:00
|
|
|
// @ts-ignore
|
|
|
|
fs.statSync = () => ({ctime: new Date(dirTime), mtime: new Date(dirTime)});
|
|
|
|
const gm = new GalleryManagerTest();
|
2022-12-05 05:23:51 +08:00
|
|
|
gm.getDirIdAndTime = () => {
|
2021-04-18 21:48:35 +08:00
|
|
|
return Promise.resolve(indexedTime as any);
|
2018-12-22 07:09:07 +08:00
|
|
|
};
|
2023-01-06 06:11:58 +08:00
|
|
|
gm.getParentDirFromId = (): Promise<ParentDirectoryDTO> => {
|
2022-12-05 05:23:51 +08:00
|
|
|
return Promise.resolve(indexedTime) as unknown as Promise<ParentDirectoryDTO>;
|
2018-12-22 07:09:07 +08:00
|
|
|
};
|
|
|
|
|
2019-02-16 00:47:09 +08:00
|
|
|
ObjectManagers.getInstance().IndexingManager.indexDirectory = (...args) => {
|
2021-04-18 21:48:35 +08:00
|
|
|
return Promise.resolve('indexing') as any;
|
2018-12-22 07:09:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
indexedTime.lastScanned = null;
|
|
|
|
expect(await gm.listDirectory('./')).to.be.equal('indexing');
|
|
|
|
indexedTime.lastModified = 0;
|
|
|
|
dirTime = 1;
|
|
|
|
expect(await gm.listDirectory('./')).to.be.equal('indexing');
|
|
|
|
indexedTime.lastScanned = 10;
|
|
|
|
indexedTime.lastModified = 1;
|
|
|
|
dirTime = 1;
|
|
|
|
expect(await gm.listDirectory('./')).to.be.equal(indexedTime);
|
|
|
|
expect(await gm.listDirectory('./', 1, 10))
|
|
|
|
.to.be.equal(null);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-30 21:09:47 +08:00
|
|
|
|
|
|
|
DBTestHelper.savedDescribe('should index .pg2conf', () => {
|
|
|
|
|
|
|
|
|
|
|
|
it('.saved_searches.pg2conf', async () => {
|
|
|
|
Config.Server.Threading.enabled = false;
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Album.enabled = true;
|
|
|
|
Config.Faces.enabled = true;
|
2021-05-30 21:09:47 +08:00
|
|
|
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Media.folder = path.join(__dirname, '/../../../assets');
|
2021-05-30 21:09:47 +08:00
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
const am = new AlbumManager();
|
2021-05-31 00:18:24 +08:00
|
|
|
|
2021-05-30 21:09:47 +08:00
|
|
|
const dir = await DiskManager.scanDirectory('/');
|
2021-06-01 01:55:27 +08:00
|
|
|
|
2021-05-30 21:09:47 +08:00
|
|
|
await im.saveToDB(dir);
|
2021-05-31 00:18:24 +08:00
|
|
|
|
2021-05-30 21:09:47 +08:00
|
|
|
const albums = await am.getAlbums();
|
2021-06-04 03:19:21 +08:00
|
|
|
expect(albums[0].preview).to.be.an('object');
|
2021-05-30 21:09:47 +08:00
|
|
|
delete albums[0].preview;
|
|
|
|
expect(albums).to.be.equalInAnyOrder([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
name: 'Alvin',
|
|
|
|
locked: true,
|
2021-06-04 03:19:21 +08:00
|
|
|
count: 1,
|
2021-05-30 21:09:47 +08:00
|
|
|
searchQuery: {
|
|
|
|
type: SearchQueryTypes.person,
|
|
|
|
text: 'Alvin',
|
|
|
|
matchType: TextSearchQueryMatchTypes.like
|
|
|
|
} as TextSearch
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-11-24 18:50:11 +08:00
|
|
|
});
|