Skip to content

Commit

Permalink
Fix displaying images in preview
Browse files Browse the repository at this point in the history
Resolves: #433
  • Loading branch information
ggodlewski committed Apr 17, 2024
1 parent dd69069 commit 076bc56
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/containers/server/routes/PreviewController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Logger} from 'winston';

import {
Controller,
RouteErrorHandler,
RouteParamPath,
RouteResponse,
RouteUse
} from './Controller';
import {Logger, QueryOptions} from 'winston';
import {extToMime, ShareErrorHandler} from './FolderController';
import {FileContentService} from '../../../utils/FileContentService';
} from './Controller.ts';
import {extToMime, ShareErrorHandler} from './FolderController.ts';
import {FileContentService} from '../../../utils/FileContentService.ts';

export class PreviewController extends Controller {
private fileSystem: FileContentService;
Expand All @@ -21,10 +21,10 @@ export class PreviewController extends Controller {
@RouteUse('/:driveId')
@RouteResponse('stream')
@RouteErrorHandler(new ShareErrorHandler())
async getFolder(@RouteParamPath('driveId') driveId: string) {
let filePath = this.req.originalUrl.replace('/preview', '') || '/';
async getFolder() {
const relativeUrl = this.req.originalUrl || '/';

filePath = filePath.replace(/\?.*$/, '');
let filePath = relativeUrl.replace('/preview', '').replace(/\?.*$/, '');

if (!await this.fileSystem.exists(filePath)) {
this.queryLogger.warn(`Not found: ${filePath}`);
Expand All @@ -33,6 +33,14 @@ export class PreviewController extends Controller {
}

if (await this.fileSystem.isDirectory(filePath)) {
if (!relativeUrl.endsWith('/')) {
this.res
.status(301)
.setHeader('location', relativeUrl + '/')
.send();
return;
}

filePath = filePath + '/index.html';
}

Expand Down

0 comments on commit 076bc56

Please sign in to comment.