1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

fixing random photo bug

This commit is contained in:
Patrik J. Braun 2018-12-01 23:53:58 +01:00
parent b0077708ae
commit 4cf1536d5f
3 changed files with 19 additions and 14 deletions

View File

@ -145,17 +145,17 @@ export class GalleryMWs {
} }
req.params.mediaPath = path.join(photo.directory.path, photo.directory.name, photo.name); req.params.mediaPath = path.join(photo.directory.path, photo.directory.name, photo.name);
return next();
} catch (e) { } catch (e) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Can\'t get random photo: ' + e.toString())); return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Can\'t get random photo: ' + e.toString()));
} }
return next();
} }
public static loadFile(req: Request, res: Response, next: NextFunction) { public static loadFile(req: Request, res: Response, next: NextFunction) {
if (!(req.params.filePath)) { if (!(req.params.mediaPath)) {
return next(); return next();
} }
const fullMediaPath = path.join(ProjectPath.ImageFolder, req.params.filePath); const fullMediaPath = path.join(ProjectPath.ImageFolder, req.params.mediaPath);
// check if thumbnail already exist // check if thumbnail already exist
if (fs.existsSync(fullMediaPath) === false) { if (fs.existsSync(fullMediaPath) === false) {

View File

@ -19,11 +19,12 @@ import {MediaDTO} from '../../../common/entities/MediaDTO';
import {VideoEntity} from './enitites/VideoEntity'; import {VideoEntity} from './enitites/VideoEntity';
import {FileEntity} from './enitites/FileEntity'; import {FileEntity} from './enitites/FileEntity';
import {FileDTO} from '../../../common/entities/FileDTO'; import {FileDTO} from '../../../common/entities/FileDTO';
import {NotificationManager} from '../NotifocationManager';
export class GalleryManager implements IGalleryManager, ISQLGalleryManager { export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
protected async selectParentDir(connection: Connection, directoryName: string, directoryParent: string): Promise<DirectoryEntity> { protected async selectParentDir(connection: Connection, directoryName: string, directoryParent: string): Promise<DirectoryEntity> {
return await connection const query = connection
.getRepository(DirectoryEntity) .getRepository(DirectoryEntity)
.createQueryBuilder('directory') .createQueryBuilder('directory')
.where('directory.name = :name AND directory.path = :path', { .where('directory.name = :name AND directory.path = :path', {
@ -31,9 +32,13 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
path: directoryParent path: directoryParent
}) })
.leftJoinAndSelect('directory.directories', 'directories') .leftJoinAndSelect('directory.directories', 'directories')
.leftJoinAndSelect('directory.media', 'media') .leftJoinAndSelect('directory.media', 'media');
.leftJoinAndSelect('directory.metaFile', 'metaFile')
.getOne(); if (Config.Client.MetaFile.enabled == true) {
query.leftJoinAndSelect('directory.metaFile', 'metaFile');
}
return await query.getOne();
} }
protected async fillParentDir(connection: Connection, dir: DirectoryEntity): Promise<void> { protected async fillParentDir(connection: Connection, dir: DirectoryEntity): Promise<void> {
@ -133,6 +138,7 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
await this.saveToDB(scannedDirectory); await this.saveToDB(scannedDirectory);
} catch (error) { } catch (error) {
NotificationManager.warning('Unknown indexing error', error.toString());
console.error(error); console.error(error);
return reject(error); return reject(error);
} }

View File

@ -36,7 +36,7 @@ export class GalleryRouter {
private static addGetImage(app: Express) { private static addGetImage(app: Express) {
app.get(['/api/gallery/content/:filePath(*\.(jpg|bmp|png|gif|jpeg))'], app.get(['/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))'],
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
// TODO: authorize path // TODO: authorize path
GalleryMWs.loadFile, GalleryMWs.loadFile,
@ -45,7 +45,7 @@ export class GalleryRouter {
} }
private static addGetVideo(app: Express) { private static addGetVideo(app: Express) {
app.get(['/api/gallery/content/:filePath(*\.(mp4|ogg|ogv|webm))'], app.get(['/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))'],
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
// TODO: authorize path // TODO: authorize path
GalleryMWs.loadFile, GalleryMWs.loadFile,
@ -54,7 +54,7 @@ export class GalleryRouter {
} }
private static addGetMetaFile(app: Express) { private static addGetMetaFile(app: Express) {
app.get(['/api/gallery/content/:filePath(*\.(gpx))'], app.get(['/api/gallery/content/:mediaPath(*\.(gpx))'],
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
// TODO: authorize path // TODO: authorize path
GalleryMWs.loadFile, GalleryMWs.loadFile,
@ -65,7 +65,6 @@ export class GalleryRouter {
private static addRandom(app: Express) { private static addRandom(app: Express) {
app.get(['/api/gallery/random'], app.get(['/api/gallery/random'],
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Guest),
// TODO: authorize path // TODO: authorize path
GalleryMWs.getRandomImage, GalleryMWs.getRandomImage,
GalleryMWs.loadFile, GalleryMWs.loadFile,
@ -74,7 +73,7 @@ export class GalleryRouter {
} }
private static addGetImageThumbnail(app: Express) { private static addGetImageThumbnail(app: Express) {
app.get('/api/gallery/content/:filePath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?', app.get('/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?',
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
// TODO: authorize path // TODO: authorize path
GalleryMWs.loadFile, GalleryMWs.loadFile,
@ -84,7 +83,7 @@ export class GalleryRouter {
} }
private static addGetVideoThumbnail(app: Express) { private static addGetVideoThumbnail(app: Express) {
app.get('/api/gallery/content/:filePath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?', app.get('/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?',
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
// TODO: authorize path // TODO: authorize path
GalleryMWs.loadFile, GalleryMWs.loadFile,
@ -94,7 +93,7 @@ export class GalleryRouter {
} }
private static addGetImageIcon(app: Express) { private static addGetImageIcon(app: Express) {
app.get('/api/gallery/content/:filePath(*\.(jpg|bmp|png|gif|jpeg))/icon', app.get('/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))/icon',
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
// TODO: authorize path // TODO: authorize path
GalleryMWs.loadFile, GalleryMWs.loadFile,