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:
parent
b0077708ae
commit
4cf1536d5f
@ -145,17 +145,17 @@ export class GalleryMWs {
|
||||
}
|
||||
|
||||
req.params.mediaPath = path.join(photo.directory.path, photo.directory.name, photo.name);
|
||||
return next();
|
||||
} catch (e) {
|
||||
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) {
|
||||
if (!(req.params.filePath)) {
|
||||
if (!(req.params.mediaPath)) {
|
||||
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
|
||||
if (fs.existsSync(fullMediaPath) === false) {
|
||||
|
@ -19,11 +19,12 @@ import {MediaDTO} from '../../../common/entities/MediaDTO';
|
||||
import {VideoEntity} from './enitites/VideoEntity';
|
||||
import {FileEntity} from './enitites/FileEntity';
|
||||
import {FileDTO} from '../../../common/entities/FileDTO';
|
||||
import {NotificationManager} from '../NotifocationManager';
|
||||
|
||||
export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
||||
|
||||
protected async selectParentDir(connection: Connection, directoryName: string, directoryParent: string): Promise<DirectoryEntity> {
|
||||
return await connection
|
||||
const query = connection
|
||||
.getRepository(DirectoryEntity)
|
||||
.createQueryBuilder('directory')
|
||||
.where('directory.name = :name AND directory.path = :path', {
|
||||
@ -31,9 +32,13 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
||||
path: directoryParent
|
||||
})
|
||||
.leftJoinAndSelect('directory.directories', 'directories')
|
||||
.leftJoinAndSelect('directory.media', 'media')
|
||||
.leftJoinAndSelect('directory.metaFile', 'metaFile')
|
||||
.getOne();
|
||||
.leftJoinAndSelect('directory.media', 'media');
|
||||
|
||||
if (Config.Client.MetaFile.enabled == true) {
|
||||
query.leftJoinAndSelect('directory.metaFile', 'metaFile');
|
||||
}
|
||||
|
||||
return await query.getOne();
|
||||
}
|
||||
|
||||
protected async fillParentDir(connection: Connection, dir: DirectoryEntity): Promise<void> {
|
||||
@ -133,6 +138,7 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
||||
await this.saveToDB(scannedDirectory);
|
||||
|
||||
} catch (error) {
|
||||
NotificationManager.warning('Unknown indexing error', error.toString());
|
||||
console.error(error);
|
||||
return reject(error);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ export class GalleryRouter {
|
||||
|
||||
|
||||
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,
|
||||
// TODO: authorize path
|
||||
GalleryMWs.loadFile,
|
||||
@ -45,7 +45,7 @@ export class GalleryRouter {
|
||||
}
|
||||
|
||||
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,
|
||||
// TODO: authorize path
|
||||
GalleryMWs.loadFile,
|
||||
@ -54,7 +54,7 @@ export class GalleryRouter {
|
||||
}
|
||||
|
||||
private static addGetMetaFile(app: Express) {
|
||||
app.get(['/api/gallery/content/:filePath(*\.(gpx))'],
|
||||
app.get(['/api/gallery/content/:mediaPath(*\.(gpx))'],
|
||||
AuthenticationMWs.authenticate,
|
||||
// TODO: authorize path
|
||||
GalleryMWs.loadFile,
|
||||
@ -65,7 +65,6 @@ export class GalleryRouter {
|
||||
private static addRandom(app: Express) {
|
||||
app.get(['/api/gallery/random'],
|
||||
AuthenticationMWs.authenticate,
|
||||
AuthenticationMWs.authorise(UserRoles.Guest),
|
||||
// TODO: authorize path
|
||||
GalleryMWs.getRandomImage,
|
||||
GalleryMWs.loadFile,
|
||||
@ -74,7 +73,7 @@ export class GalleryRouter {
|
||||
}
|
||||
|
||||
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,
|
||||
// TODO: authorize path
|
||||
GalleryMWs.loadFile,
|
||||
@ -84,7 +83,7 @@ export class GalleryRouter {
|
||||
}
|
||||
|
||||
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,
|
||||
// TODO: authorize path
|
||||
GalleryMWs.loadFile,
|
||||
@ -94,7 +93,7 @@ export class GalleryRouter {
|
||||
}
|
||||
|
||||
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,
|
||||
// TODO: authorize path
|
||||
GalleryMWs.loadFile,
|
||||
|
Loading…
Reference in New Issue
Block a user