mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-24 02:39:18 -05:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
@@ -126,25 +126,31 @@ class JellyfinAPI extends ExternalAPI {
|
||||
Password?: string,
|
||||
ClientIP?: string
|
||||
): Promise<JellyfinLoginResponse> {
|
||||
try {
|
||||
const headers = ClientIP
|
||||
? {
|
||||
'X-Forwarded-For': ClientIP,
|
||||
}
|
||||
: {};
|
||||
const authenticate = async (useHeaders: boolean) => {
|
||||
const headers =
|
||||
useHeaders && ClientIP ? { 'X-Forwarded-For': ClientIP } : {};
|
||||
|
||||
const authResponse = await this.post<JellyfinLoginResponse>(
|
||||
return this.post<JellyfinLoginResponse>(
|
||||
'/Users/AuthenticateByName',
|
||||
{
|
||||
Username: Username,
|
||||
Username,
|
||||
Pw: Password,
|
||||
},
|
||||
{
|
||||
headers: headers,
|
||||
}
|
||||
{ headers }
|
||||
);
|
||||
};
|
||||
|
||||
return authResponse;
|
||||
try {
|
||||
return await authenticate(true);
|
||||
} catch (e) {
|
||||
logger.debug(`Failed to authenticate with headers: ${e.message}`, {
|
||||
label: 'Jellyfin API',
|
||||
ip: ClientIP,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
return await authenticate(false);
|
||||
} catch (e) {
|
||||
const status = e.response?.status;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import type CacheableLookupType from 'cacheable-lookup';
|
||||
import { TypeormStore } from 'connect-typeorm/out';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import csurf from 'csurf';
|
||||
import { lookup } from 'dns';
|
||||
import type { NextFunction, Request, Response } from 'express';
|
||||
import express from 'express';
|
||||
import * as OpenApiValidator from 'express-openapi-validator';
|
||||
@@ -54,6 +55,19 @@ app
|
||||
const CacheableLookup = (await _importDynamic('cacheable-lookup'))
|
||||
.default as typeof CacheableLookupType;
|
||||
const cacheable = new CacheableLookup();
|
||||
|
||||
const originalLookup = cacheable.lookup;
|
||||
|
||||
// if hostname is localhost use dns.lookup instead of cacheable-lookup
|
||||
cacheable.lookup = (...args: any) => {
|
||||
const [hostname] = args;
|
||||
if (hostname === 'localhost') {
|
||||
lookup(...(args as Parameters<typeof lookup>));
|
||||
} else {
|
||||
originalLookup(...(args as Parameters<typeof originalLookup>));
|
||||
}
|
||||
};
|
||||
|
||||
cacheable.install(http.globalAgent);
|
||||
cacheable.install(https.globalAgent);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import { ApiError } from '@server/types/error';
|
||||
import * as EmailValidator from 'email-validator';
|
||||
import { Router } from 'express';
|
||||
import gravatarUrl from 'gravatar-url';
|
||||
import net from 'net';
|
||||
|
||||
const authRoutes = Router();
|
||||
|
||||
@@ -271,11 +272,21 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
|
||||
? jellyfinHost.slice(0, -1)
|
||||
: jellyfinHost;
|
||||
|
||||
const ip = req.ip ? req.ip.split(':').reverse()[0] : undefined;
|
||||
const ip = req.ip;
|
||||
let clientIp;
|
||||
|
||||
if (ip) {
|
||||
if (net.isIPv4(ip)) {
|
||||
clientIp = ip;
|
||||
} else if (net.isIPv6(ip)) {
|
||||
clientIp = ip.startsWith('::ffff:') ? ip.substring(7) : ip;
|
||||
}
|
||||
}
|
||||
|
||||
const account = await jellyfinserver.login(
|
||||
body.username,
|
||||
body.password,
|
||||
ip
|
||||
clientIp
|
||||
);
|
||||
|
||||
// Next let's see if the user already exists
|
||||
|
||||
Reference in New Issue
Block a user