You've already forked pigallery2
mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-07-15 01:24:25 +02:00
Adding base url to language redirect. fixes #793
This commit is contained in:
@ -12,6 +12,7 @@ import {ServerTimeEntry} from '../middlewares/ServerTimingMWs';
|
|||||||
import {ClientConfig, TAGS} from '../../common/config/public/ClientConfig';
|
import {ClientConfig, TAGS} from '../../common/config/public/ClientConfig';
|
||||||
import {QueryParams} from '../../common/QueryParams';
|
import {QueryParams} from '../../common/QueryParams';
|
||||||
import {PhotoProcessing} from '../model/fileaccess/fileprocessing/PhotoProcessing';
|
import {PhotoProcessing} from '../model/fileaccess/fileprocessing/PhotoProcessing';
|
||||||
|
import {Utils} from '../../common/Utils';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
@ -35,7 +36,7 @@ export class PublicRouter {
|
|||||||
let selectedLocale = req.locale;
|
let selectedLocale = req.locale;
|
||||||
if (req.cookies && req.cookies[CookieNames.lang]) {
|
if (req.cookies && req.cookies[CookieNames.lang]) {
|
||||||
if (
|
if (
|
||||||
Config.Server.languages.indexOf(req.cookies[CookieNames.lang]) !== -1
|
Config.Server.languages.indexOf(req.cookies[CookieNames.lang]) !== -1
|
||||||
) {
|
) {
|
||||||
selectedLocale = req.cookies[CookieNames.lang];
|
selectedLocale = req.cookies[CookieNames.lang];
|
||||||
}
|
}
|
||||||
@ -48,14 +49,14 @@ export class PublicRouter {
|
|||||||
// index.html should not be cached as it contains template that can change
|
// index.html should not be cached as it contains template that can change
|
||||||
const renderIndex = (req: Request, res: Response, next: NextFunction) => {
|
const renderIndex = (req: Request, res: Response, next: NextFunction) => {
|
||||||
ejs.renderFile(
|
ejs.renderFile(
|
||||||
path.join(ProjectPath.FrontendFolder, req.localePath, 'index.html'),
|
path.join(ProjectPath.FrontendFolder, req.localePath, 'index.html'),
|
||||||
res.tpl,
|
res.tpl,
|
||||||
(err, str) => {
|
(err, str) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, err.message));
|
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, err.message));
|
||||||
}
|
|
||||||
res.send(str);
|
|
||||||
}
|
}
|
||||||
|
res.send(str);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ export class PublicRouter {
|
|||||||
if (Config.Server.languages.indexOf(locale) !== -1) {
|
if (Config.Server.languages.indexOf(locale) !== -1) {
|
||||||
res.cookie(CookieNames.lang, locale);
|
res.cookie(CookieNames.lang, locale);
|
||||||
}
|
}
|
||||||
res.redirect('/?ln=' + locale);
|
res.redirect(Utils.concatUrls('/' + Config.Server.urlBase) + '/?ln=' + locale);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,12 +95,12 @@ export class PublicRouter {
|
|||||||
}) as unknown as ClientConfig;
|
}) as unknown as ClientConfig;
|
||||||
// Escaping html tags, like <script></script>
|
// Escaping html tags, like <script></script>
|
||||||
confCopy.Server.customHTMLHead =
|
confCopy.Server.customHTMLHead =
|
||||||
confCopy.Server.customHTMLHead
|
confCopy.Server.customHTMLHead
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
.replace(/'/g, ''');
|
.replace(/'/g, ''');
|
||||||
res.tpl.Config = confCopy;
|
res.tpl.Config = confCopy;
|
||||||
res.tpl.customHTMLHead = Config.Server.customHTMLHead;
|
res.tpl.customHTMLHead = Config.Server.customHTMLHead;
|
||||||
const selectedTheme = Config.Gallery.Themes.availableThemes.find(th => th.name === Config.Gallery.Themes.selectedTheme)?.theme || '';
|
const selectedTheme = Config.Gallery.Themes.availableThemes.find(th => th.name === Config.Gallery.Themes.selectedTheme)?.theme || '';
|
||||||
@ -140,7 +141,7 @@ export class PublicRouter {
|
|||||||
'photo'
|
'photo'
|
||||||
],
|
],
|
||||||
start_url:
|
start_url:
|
||||||
Config.Server.publicUrl === '' ? '.' : Config.Server.publicUrl,
|
Config.Server.publicUrl === '' ? '.' : Config.Server.publicUrl,
|
||||||
background_color: '#000000',
|
background_color: '#000000',
|
||||||
theme_color: '#000000',
|
theme_color: '#000000',
|
||||||
});
|
});
|
||||||
@ -185,40 +186,40 @@ export class PublicRouter {
|
|||||||
y: vBs[1]
|
y: vBs[1]
|
||||||
};
|
};
|
||||||
return '<svg ' +
|
return '<svg ' +
|
||||||
' xmlns="http://www.w3.org/2000/svg"' +
|
' xmlns="http://www.w3.org/2000/svg"' +
|
||||||
' viewBox="' + vBs.join(' ') + '">' +
|
' viewBox="' + vBs.join(' ') + '">' +
|
||||||
(theme === 'auto' ? ('<style>' +
|
(theme === 'auto' ? ('<style>' +
|
||||||
' path, circle {' +
|
' path, circle {' +
|
||||||
' fill: black;' +
|
' fill: black;' +
|
||||||
' }' +
|
' }' +
|
||||||
' circle.bg,rect.bg {' +
|
' circle.bg,rect.bg {' +
|
||||||
' fill: white;' +
|
' fill: white;' +
|
||||||
' }' +
|
' }' +
|
||||||
' @media (prefers-color-scheme: dark) {' +
|
' @media (prefers-color-scheme: dark) {' +
|
||||||
' path, circle {' +
|
' path, circle {' +
|
||||||
' fill: white;' +
|
' fill: white;' +
|
||||||
' }' +
|
' }' +
|
||||||
' circle.bg,rect.bg {' +
|
' circle.bg,rect.bg {' +
|
||||||
' fill: black;' +
|
' fill: black;' +
|
||||||
' }' +
|
' }' +
|
||||||
' }' +
|
' }' +
|
||||||
' </style>') :
|
' </style>') :
|
||||||
(theme != null ?
|
(theme != null ?
|
||||||
('<style>' +
|
('<style>' +
|
||||||
' path, circle {' +
|
' path, circle {' +
|
||||||
' fill: ' + theme + ';' +
|
' fill: ' + theme + ';' +
|
||||||
' }' +
|
' }' +
|
||||||
' circle.bg {' +
|
' circle.bg {' +
|
||||||
' fill: black;' +
|
' fill: black;' +
|
||||||
' }' +
|
' }' +
|
||||||
' </style>')
|
' </style>')
|
||||||
: '<style>' +
|
: '<style>' +
|
||||||
' circle.bg,rect.bg {' +
|
' circle.bg,rect.bg {' +
|
||||||
' fill: white;' +
|
' fill: white;' +
|
||||||
' }' +
|
' }' +
|
||||||
' </style>')) +
|
' </style>')) +
|
||||||
`<rect class="bg" x="${canvasStart.x}" y="${canvasStart.y}" width="${canvasSize}" height="${canvasSize}" rx="15" />` +
|
`<rect class="bg" x="${canvasStart.x}" y="${canvasStart.y}" width="${canvasSize}" height="${canvasSize}" rx="15" />` +
|
||||||
Config.Server.svgIcon.items + '</svg>';
|
Config.Server.svgIcon.items + '</svg>';
|
||||||
};
|
};
|
||||||
|
|
||||||
app.get('/icon.svg', (req: Request, res: Response) => {
|
app.get('/icon.svg', (req: Request, res: Response) => {
|
||||||
@ -276,44 +277,44 @@ export class PublicRouter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
[
|
[
|
||||||
'/',
|
'/',
|
||||||
'/login',
|
'/login',
|
||||||
'/gallery*',
|
'/gallery*',
|
||||||
'/share/:' + QueryParams.gallery.sharingKey_params,
|
'/share/:' + QueryParams.gallery.sharingKey_params,
|
||||||
'/shareLogin',
|
'/shareLogin',
|
||||||
'/admin',
|
'/admin',
|
||||||
'/duplicates',
|
'/duplicates',
|
||||||
'/faces',
|
'/faces',
|
||||||
'/albums',
|
'/albums',
|
||||||
'/search*',
|
'/search*',
|
||||||
],
|
],
|
||||||
AuthenticationMWs.tryAuthenticate,
|
AuthenticationMWs.tryAuthenticate,
|
||||||
addTPl, // add template after authentication was successful
|
addTPl, // add template after authentication was successful
|
||||||
setLocale,
|
setLocale,
|
||||||
renderIndex
|
renderIndex
|
||||||
);
|
);
|
||||||
Config.Server.languages.forEach((l) => {
|
Config.Server.languages.forEach((l) => {
|
||||||
app.get(
|
app.get(
|
||||||
[
|
[
|
||||||
'/' + l + '/',
|
'/' + l + '/',
|
||||||
'/' + l + '/login',
|
'/' + l + '/login',
|
||||||
'/' + l + '/gallery*',
|
'/' + l + '/gallery*',
|
||||||
'/' + l + '/share*',
|
'/' + l + '/share*',
|
||||||
'/' + l + '/admin',
|
'/' + l + '/admin',
|
||||||
'/' + l + '/search*',
|
'/' + l + '/search*',
|
||||||
],
|
],
|
||||||
redirectToBase(l)
|
redirectToBase(l)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderFile = (subDir = '') => {
|
const renderFile = (subDir = '') => {
|
||||||
return (req: Request, res: Response) => {
|
return (req: Request, res: Response) => {
|
||||||
const file = path.join(
|
const file = path.join(
|
||||||
ProjectPath.FrontendFolder,
|
ProjectPath.FrontendFolder,
|
||||||
req.localePath,
|
req.localePath,
|
||||||
subDir,
|
subDir,
|
||||||
req.params.file
|
req.params.file
|
||||||
);
|
);
|
||||||
if (!fs.existsSync(file)) {
|
if (!fs.existsSync(file)) {
|
||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
@ -326,16 +327,16 @@ export class PublicRouter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
'/assets/:file(*)',
|
'/assets/:file(*)',
|
||||||
setLocale,
|
setLocale,
|
||||||
AuthenticationMWs.normalizePathParam('file'),
|
AuthenticationMWs.normalizePathParam('file'),
|
||||||
renderFile('assets')
|
renderFile('assets')
|
||||||
);
|
);
|
||||||
app.get(
|
app.get(
|
||||||
'/:file',
|
'/:file',
|
||||||
setLocale,
|
setLocale,
|
||||||
AuthenticationMWs.normalizePathParam('file'),
|
AuthenticationMWs.normalizePathParam('file'),
|
||||||
renderFile()
|
renderFile()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@ describe('Utils', () => {
|
|||||||
expect(Utils.concatUrls('abc\\', 'cde')).to.be.equal('abc/cde');
|
expect(Utils.concatUrls('abc\\', 'cde')).to.be.equal('abc/cde');
|
||||||
expect(Utils.concatUrls('abc/', 'cde/')).to.be.equal('abc/cde');
|
expect(Utils.concatUrls('abc/', 'cde/')).to.be.equal('abc/cde');
|
||||||
expect(Utils.concatUrls('./abc\\', 'cde/')).to.be.equal('./abc/cde');
|
expect(Utils.concatUrls('./abc\\', 'cde/')).to.be.equal('./abc/cde');
|
||||||
|
expect(Utils.concatUrls('/abc\\', 'cde/')).to.be.equal('/abc/cde');
|
||||||
expect(Utils.concatUrls('abc/', '\\cde/')).to.be.equal('abc/cde');
|
expect(Utils.concatUrls('abc/', '\\cde/')).to.be.equal('abc/cde');
|
||||||
|
expect(Utils.concatUrls('/abc/', '\\cde/')).to.be.equal('/abc/cde');
|
||||||
expect(Utils.concatUrls('abc\\', '\\cde/')).to.be.equal('abc/cde');
|
expect(Utils.concatUrls('abc\\', '\\cde/')).to.be.equal('abc/cde');
|
||||||
expect(Utils.concatUrls('abc\\', '/cde/')).to.be.equal('abc/cde');
|
expect(Utils.concatUrls('abc\\', '/cde/')).to.be.equal('abc/cde');
|
||||||
expect(Utils.concatUrls('abc/', '/cde/')).to.be.equal('abc/cde');
|
expect(Utils.concatUrls('abc/', '/cde/')).to.be.equal('abc/cde');
|
||||||
|
Reference in New Issue
Block a user