2019-12-27 04:03:10 +08:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
|
|
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
|
|
|
import * as path from 'path';
|
2023-10-14 23:54:21 +08:00
|
|
|
import {PhotoProcessing} from '../../../../../src/backend/model/fileaccess/fileprocessing/PhotoProcessing';
|
2019-12-27 04:03:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
describe('PhotoProcessing', () => {
|
|
|
|
|
2022-04-05 01:37:31 +08:00
|
|
|
/* eslint-disable no-unused-expressions,@typescript-eslint/no-unused-expressions */
|
2019-12-27 04:03:10 +08:00
|
|
|
it('should generate converted file path', async () => {
|
|
|
|
|
2023-09-21 03:37:33 +08:00
|
|
|
await Config.load();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Media.Thumbnail.thumbnailSizes = [];
|
2023-11-27 05:47:57 +08:00
|
|
|
Config.Media.Thumbnail.animateGif = true;
|
2020-01-08 05:28:59 +08:00
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
|
2019-12-27 04:03:10 +08:00
|
|
|
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath,
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Media.Photo.Converting.resolution)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath + 'noPath',
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Media.Photo.Converting.resolution)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.false;
|
|
|
|
|
|
|
|
{
|
2019-12-29 07:35:41 +08:00
|
|
|
const convertedPath = PhotoProcessing.generateConvertedPath(photoPath,
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Media.Photo.Converting.resolution);
|
|
|
|
Config.Media.Photo.Converting.resolution = (1 as any);
|
2019-12-27 04:03:10 +08:00
|
|
|
expect(await PhotoProcessing.isValidConvertedPath(convertedPath)).to.be.false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-27 05:47:57 +08:00
|
|
|
it('should generate converted gif file path', async () => {
|
|
|
|
|
|
|
|
await Config.load();
|
|
|
|
Config.Media.Thumbnail.thumbnailSizes = [];
|
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
|
|
|
|
const gifPath = path.join(ProjectPath.ImageFolder, 'earth.gif');
|
|
|
|
|
|
|
|
Config.Media.Thumbnail.animateGif = true;
|
|
|
|
expect(await PhotoProcessing
|
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(gifPath,
|
|
|
|
Config.Media.Photo.Converting.resolution)))
|
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
Config.Media.Thumbnail.animateGif = false;
|
|
|
|
expect(await PhotoProcessing
|
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(gifPath,
|
|
|
|
Config.Media.Photo.Converting.resolution)))
|
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-04-05 01:37:31 +08:00
|
|
|
/* eslint-disable no-unused-expressions,@typescript-eslint/no-unused-expressions */
|
2019-12-27 04:03:10 +08:00
|
|
|
it('should generate converted thumbnail path', async () => {
|
|
|
|
|
2023-09-21 03:37:33 +08:00
|
|
|
await Config.load();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Media.Photo.Converting.resolution = (null as any);
|
|
|
|
Config.Media.Thumbnail.thumbnailSizes = [10, 20];
|
2020-01-08 05:28:59 +08:00
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
|
2019-12-27 04:03:10 +08:00
|
|
|
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
|
|
|
|
|
2022-12-29 02:12:18 +08:00
|
|
|
for (const thSize of Config.Media.Thumbnail.thumbnailSizes) {
|
2019-12-27 04:03:10 +08:00
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath, thSize)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath + 'noPath', thSize)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath, 30)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|