1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

making file reading issues only a warning #731

This commit is contained in:
Patrik J. Braun 2023-10-14 19:06:12 +02:00
parent 81e7e7a629
commit 237e61c350
2 changed files with 136 additions and 97 deletions

View File

@ -14,9 +14,9 @@ const forcedDebug = process.env['NODE_ENV'] === 'debug';
export class RenderingMWs {
public static renderResult(
req: Request,
res: Response,
next: NextFunction
req: Request,
res: Response,
next: NextFunction
): void {
if (typeof req.resultPipe === 'undefined') {
return next();
@ -26,9 +26,9 @@ export class RenderingMWs {
}
public static renderSessionUser(
req: Request,
res: Response,
next: NextFunction
req: Request,
res: Response,
next: NextFunction
): void {
if (!req.session['user']) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'User not exists'));
@ -51,9 +51,9 @@ export class RenderingMWs {
}
public static renderSharing(
req: Request,
res: Response,
next: NextFunction
req: Request,
res: Response,
next: NextFunction
): void {
if (!req.resultPipe) {
return next();
@ -65,9 +65,9 @@ export class RenderingMWs {
}
public static renderSharingList(
req: Request,
res: Response,
next: NextFunction
req: Request,
res: Response,
next: NextFunction
): void {
if (!req.resultPipe) {
return next();
@ -82,9 +82,9 @@ export class RenderingMWs {
}
public static renderFile(
req: Request,
res: Response,
next: NextFunction
req: Request,
res: Response,
next: NextFunction
): void {
if (!req.resultPipe) {
return next();
@ -96,52 +96,63 @@ export class RenderingMWs {
}
public static renderOK(
req: Request,
res: Response
req: Request,
res: Response
): void {
const message = new Message<string>(null, 'ok');
res.json(message);
}
public static async renderConfig(
req: Request,
res: Response
req: Request,
res: Response
): Promise<void> {
const originalConf = await Config.original();
// These are sensitive information, do not send to the client side
originalConf.Server.sessionSecret = null;
const message = new Message<PrivateConfigClass>(
null,
originalConf.toJSON({
attachState: true,
attachVolatile: true,
skipTags: {secret: true} as TAGS
}) as PrivateConfigClass
null,
originalConf.toJSON({
attachState: true,
attachVolatile: true,
skipTags: {secret: true} as TAGS
}) as PrivateConfigClass
);
res.json(message);
}
public static renderError(
err: Error,
req: Request,
res: Response,
next: NextFunction
err: Error,
req: Request,
res: Response,
next: NextFunction
): void {
if (err instanceof ErrorDTO) {
if (err.details) {
Logger.warn('Handled error:');
LoggerRouter.log(Logger.warn, req, res);
// use separate rendering for detailsStr
const d = err.detailsStr;
delete err.detailsStr;
console.log(err);
if (err.detailsStr) {
try {
console.log('details:', JSON.stringify(err.detailsStr));
} catch (_) {
console.log(err.detailsStr);
}
}
err.detailsStr = d;
delete err.details; // do not send back error object to the client side
// hide error details for non developers
if (
!(
forcedDebug ||
(req.session &&
req.session['user'] &&
req.session['user'].role >= UserRoles.Developer)
)
!(
forcedDebug ||
(req.session &&
req.session['user'] &&
req.session['user'].role >= UserRoles.Developer)
)
) {
delete err.detailsStr;
}

View File

@ -13,6 +13,7 @@ import {Utils} from '../../../common/Utils';
import {GPXProcessing} from './fileprocessing/GPXProcessing';
import {MDFileDTO} from '../../../common/entities/MDFileDTO';
import {MetadataLoader} from './MetadataLoader';
import {NotificationManager} from '../NotifocationManager';
const LOG_TAG = '[DiskManager]';
@ -148,66 +149,83 @@ export class DiskManager {
path.join(absoluteDirectoryName, file)
);
if ((await fsp.stat(fullFilePath)).isDirectory()) {
if (
settings.noDirectory === true ||
settings.coverOnly === true ||
(await DiskManager.excludeDir(
file,
relativeDirectoryName,
absoluteDirectoryName
))
) {
continue;
}
// create cover directory
const d = (await DiskManager.scanDirectory(
path.join(relativeDirectoryName, file),
{
coverOnly: true,
try {
if (
settings.noDirectory === true ||
settings.coverOnly === true ||
(await DiskManager.excludeDir(
file,
relativeDirectoryName,
absoluteDirectoryName
))
) {
continue;
}
)) as SubDirectoryDTO;
directory.directories.push(d);
// create cover directory
const d = (await DiskManager.scanDirectory(
path.join(relativeDirectoryName, file),
{
coverOnly: true,
}
)) as SubDirectoryDTO;
directory.directories.push(d);
} catch (err) {
NotificationManager.warning(
'Unknown directory reading error, skipping: ' + path.join(relativeDirectoryName, file),
err.toString()
);
console.error(err);
}
} else if (PhotoProcessing.isPhoto(fullFilePath)) {
if (settings.noPhoto === true) {
continue;
}
try {
if (settings.noPhoto === true) {
continue;
}
const photo = {
name: file,
directory: null,
metadata:
settings.noMetadata === true
? null
: await MetadataLoader.loadPhotoMetadata(fullFilePath),
} as PhotoDTO;
const photo = {
name: file,
directory: null,
metadata:
settings.noMetadata === true
? null
: await MetadataLoader.loadPhotoMetadata(fullFilePath),
} as PhotoDTO;
if (!directory.cover) {
directory.cover = Utils.clone(photo);
if (!directory.cover) {
directory.cover = Utils.clone(photo);
directory.cover.directory = {
path: directory.path,
name: directory.name,
};
}
// add the cover photo to the list of media, so it will be saved to the DB
// and can be queried to populate covers,
// otherwise we do not return media list that is only partial
directory.media.push(photo);
directory.cover.directory = {
path: directory.path,
name: directory.name,
};
}
// add the cover photo to the list of media, so it will be saved to the DB
// and can be queried to populate covers,
// otherwise we do not return media list that is only partial
directory.media.push(photo);
if (settings.coverOnly === true) {
break;
if (settings.coverOnly === true) {
break;
}
} catch (err) {
NotificationManager.warning('Media loading error, skipping: ' +
fullFilePath +
', reason: ' +
err.toString()
);
console.error(err);
}
} else if (VideoProcessing.isVideo(fullFilePath)) {
if (
Config.Media.Video.enabled === false ||
settings.noVideo === true ||
settings.coverOnly === true
) {
continue;
}
try {
if (
Config.Media.Video.enabled === false ||
settings.noVideo === true ||
settings.coverOnly === true
) {
continue;
}
directory.media.push({
name: file,
directory: null,
@ -219,24 +237,34 @@ export class DiskManager {
} catch (e) {
Logger.warn(
'Media loading error, skipping: ' +
file +
fullFilePath +
', reason: ' +
e.toString()
);
}
} else if (GPXProcessing.isMetaFile(fullFilePath)) {
if (
!DiskManager.isEnabledMetaFile(fullFilePath) ||
settings.noMetaFile === true ||
settings.coverOnly === true
) {
continue;
}
directory.metaFile.push({
name: file,
directory: null,
} as FileDTO);
try {
if (
!DiskManager.isEnabledMetaFile(fullFilePath) ||
settings.noMetaFile === true ||
settings.coverOnly === true
) {
continue;
}
directory.metaFile.push({
name: file,
directory: null,
} as FileDTO);
} catch (e) {
Logger.warn(
'Metafile loading error, skipping: ' +
fullFilePath +
', reason: ' +
e.toString()
);
}
}
}