fix(server): add basic auth support (#16740)

* "add basic auth support"

* "fix format"

* fix: lint

---------

Co-authored-by: Elliot <elliot@elliotbrandwein.com>
Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
Elliot 2025-06-11 22:14:03 -04:00 committed by GitHub
parent e5219f1f31
commit fdc7a154c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -345,6 +345,11 @@ describe(SystemConfigService.name, () => {
{ should: 'with a trailing slash', externalDomain: 'https://demo.immich.app/' }, { should: 'with a trailing slash', externalDomain: 'https://demo.immich.app/' },
{ should: 'without a trailing slash', externalDomain: 'https://demo.immich.app' }, { should: 'without a trailing slash', externalDomain: 'https://demo.immich.app' },
{ should: 'with a port', externalDomain: 'https://demo.immich.app:42', result: 'https://demo.immich.app:42' }, { should: 'with a port', externalDomain: 'https://demo.immich.app:42', result: 'https://demo.immich.app:42' },
{
should: 'with basic auth',
externalDomain: 'https://user:password@example.com:123',
result: 'https://user:password@example.com:123',
},
]; ];
for (const { should, externalDomain, result } of externalDomainTests) { for (const { should, externalDomain, result } of externalDomainTests) {

View File

@ -116,7 +116,14 @@ const buildConfig = async (repos: RepoDeps) => {
const config = instanceToPlain(instance) as SystemConfig; const config = instanceToPlain(instance) as SystemConfig;
if (config.server.externalDomain.length > 0) { if (config.server.externalDomain.length > 0) {
config.server.externalDomain = new URL(config.server.externalDomain).origin; const domain = new URL(config.server.externalDomain);
let externalDomain = domain.origin;
if (domain.password && domain.username) {
externalDomain = `${domain.protocol}//${domain.username}:${domain.password}@${domain.host}`;
}
config.server.externalDomain = externalDomain;
} }
if (!config.ffmpeg.acceptedVideoCodecs.includes(config.ffmpeg.targetVideoCodec)) { if (!config.ffmpeg.acceptedVideoCodecs.includes(config.ffmpeg.targetVideoCodec)) {