Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/server/src/middlewares/userData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ const VALID_RESOURCES = [
'streams',
];

interface UserDataParams {
uuid?: string;
encryptedPassword?: string;
// match Express.Request<ParamsDictionary> to keep middleware flexible
[key: string]: string | string[] | undefined;
}

export const userDataMiddleware = async (
req: Request,
req: Request<UserDataParams>,
res: Response,
next: NextFunction
) => {
Expand Down Expand Up @@ -82,7 +89,7 @@ export const userDataMiddleware = async (

// decrypt the encrypted password
const { success: successfulDecryption, data: decryptedPassword } =
decryptString(encryptedPassword!);
decryptString(encryptedPassword);
if (!successfulDecryption) {
if (constants.RESOURCES.includes(resource as Resource)) {
res.status(200).json(
Expand Down
16 changes: 8 additions & 8 deletions packages/server/src/routes/api/debrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ router.use((req: Request, res: Response, next: NextFunction) => {
}
});

interface PlaybackParams {
encryptedStoreAuth: string;
fileInfo: string;
metadataId: string;
filename: string;
}

router.get(
'/playback/:encryptedStoreAuth/:fileInfo/:metadataId/:filename',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<PlaybackParams>, res: Response, next: NextFunction) => {
try {
const {
encryptedStoreAuth,
fileInfo: encodedFileInfo,
metadataId,
filename,
} = req.params;
if (!encodedFileInfo || !metadataId || !filename) {
throw new APIError(
constants.ErrorCode.BAD_REQUEST,
undefined,
'Encrypted store auth, file info, metadata id and filename are required'
);
}

let fileInfo: FileInfo | undefined;

Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/routes/api/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ router.get(
}
);

interface ProxyParams {
encryptedAuthAndData: string;
filename?: string; // optional
}

router.all(
'/:encryptedAuthAndData{/:filename}',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<ProxyParams>, res: Response, next: NextFunction) => {
const startTime = Date.now();
const requestId = Math.random().toString(36).substring(7);
let upstreamResponse: Dispatcher.ResponseData | undefined;
Expand Down
26 changes: 23 additions & 3 deletions packages/server/src/routes/builtins/easynews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import { createResponse } from '../../utils/responses.js';
const router: Router = Router();
const logger = createLogger('server');

interface EasynewsManifestParams {
encodedConfig?: string; // optional
}

router.get(
'/:encodedConfig/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<EasynewsManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;

try {
Expand All @@ -37,9 +41,15 @@ router.get(
}
);

interface EasynewsStreamParams {
encodedConfig?: string; // optional
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<EasynewsStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;

try {
Expand All @@ -63,6 +73,15 @@ router.get(
* NZB endpoint - fetches NZB from Easynews and serves it
* This endpoint is needed because Easynews requires a POST request to fetch NZBs
*/
interface EasynewsNzbParams {
encodedAuth: string;
encodedParams: string;
aiostreamsAuth?: string; // optional
filename: string;
// match Express.Request<ParamsDictionary> to allow chaining of easynewsNzbRateLimiter middleware
[key: string]: string | string[] | undefined;
}

router.get(
'/nzb/:encodedAuth/:encodedParams{/:aiostreamsAuth}/:filename.nzb',
easynewsNzbRateLimiter,
Expand All @@ -71,7 +90,8 @@ router.get(
encodedAuth,
encodedParams,
aiostreamsAuth: encodedAiostreamsAuth,
} = req.params;
filename,
} = req.params as EasynewsNzbParams;

try {
// Decode and validate auth credentials
Expand Down
16 changes: 13 additions & 3 deletions packages/server/src/routes/builtins/eztv.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Router, Request, Response, NextFunction } from 'express';
import { EztvAddon, fromUrlSafeBase64 } from '@aiostreams/core';
import { EztvAddon, fromUrlSafeBase64, APIError, constants } from '@aiostreams/core';

const router: Router = Router();

interface EztvManifestParams {
encodedConfig?: string; // optional
}

router.get(
'/:encodedConfig/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<EztvManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;
try {
const manifest = new EztvAddon(
Expand All @@ -21,9 +25,15 @@ router.get(
}
);

interface EztvStreamParams {
encodedConfig?: string; // optional
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<EztvStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;

try {
Expand Down
33 changes: 28 additions & 5 deletions packages/server/src/routes/builtins/gdrive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Router, Request, Response, NextFunction } from 'express';
import { createLogger, fromUrlSafeBase64, GDriveAddon } from '@aiostreams/core';
import { createLogger, fromUrlSafeBase64, GDriveAddon, APIError, constants } from '@aiostreams/core';
const router: Router = Router();

const logger = createLogger('server');

interface GDriveManifestParams {
encodedConfig?: string; // optional
}

router.get(
'{/:encodedConfig}/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<GDriveManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;
const config = encodedConfig
? JSON.parse(fromUrlSafeBase64(encodedConfig))
Expand All @@ -23,9 +27,15 @@ router.get(
}
);

interface GDriveMetaParams {
encodedConfig: string;
type: string;
id: string;
}

router.get(
'/:encodedConfig/meta/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<GDriveMetaParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;
const config = JSON.parse(fromUrlSafeBase64(encodedConfig));

Expand All @@ -41,9 +51,16 @@ router.get(
}
);

interface GDriveCatalogParams {
encodedConfig: string;
type: string;
id: string;
extras?: string; // optional
}

router.get(
'/:encodedConfig/catalog/:type/:id{/:extras}.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<GDriveCatalogParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id, extras } = req.params;
const config = JSON.parse(fromUrlSafeBase64(encodedConfig));

Expand All @@ -59,9 +76,15 @@ router.get(
}
);

interface GDriveStreamParams {
encodedConfig: string;
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<GDriveStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;
const config = JSON.parse(fromUrlSafeBase64(encodedConfig));

Expand Down
17 changes: 13 additions & 4 deletions packages/server/src/routes/builtins/knaben.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Router, Request, Response, NextFunction } from 'express';
import { KnabenAddon, fromUrlSafeBase64 } from '@aiostreams/core';
import { createLogger } from '@aiostreams/core';
import { KnabenAddon, fromUrlSafeBase64, createLogger, APIError, constants } from '@aiostreams/core';
const router: Router = Router();

const logger = createLogger('server');

interface KnabenManifestParams {
encodedConfig?: string; // optional
}

router.get(
'/:encodedConfig/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<KnabenManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;
try {
const manifest = new KnabenAddon(
Expand All @@ -23,9 +26,15 @@ router.get(
}
);

interface KnabenStreamParams {
encodedConfig?: string; // optional
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<KnabenStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;

try {
Expand Down
16 changes: 14 additions & 2 deletions packages/server/src/routes/builtins/newznab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import {
NewznabAddon,
createLogger,
fromUrlSafeBase64,
APIError,
constants,
} from '@aiostreams/core';
const router: Router = Router();

const logger = createLogger('server');

interface NewznabManifestParams {
encodedConfig?: string; // optional
}

router.get(
'/:encodedConfig/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<NewznabManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;

try {
Expand All @@ -27,9 +33,15 @@ router.get(
}
);

interface NewznabStreamParams {
encodedConfig?: string; // optional
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<NewznabStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;

try {
Expand Down
17 changes: 13 additions & 4 deletions packages/server/src/routes/builtins/prowlarr.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Router, Request, Response, NextFunction } from 'express';
import { ProwlarrAddon, fromUrlSafeBase64 } from '@aiostreams/core';
import { createLogger } from '@aiostreams/core';
import { ProwlarrAddon, fromUrlSafeBase64, createLogger, APIError, constants } from '@aiostreams/core';
const router: Router = Router();

const logger = createLogger('server');

interface ProwlarrManifestParams {
encodedConfig?: string; // optional
}

router.get(
'/:encodedConfig/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<ProwlarrManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;

try {
Expand All @@ -24,9 +27,15 @@ router.get(
}
);

interface ProwlarrStreamParams {
encodedConfig?: string; // optional
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<ProwlarrStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;

try {
Expand Down
17 changes: 13 additions & 4 deletions packages/server/src/routes/builtins/seadex.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Router, Request, Response, NextFunction } from 'express';
import { SeaDexAddon, fromUrlSafeBase64 } from '@aiostreams/core';
import { createLogger } from '@aiostreams/core';
import { SeaDexAddon, fromUrlSafeBase64, createLogger, APIError, constants } from '@aiostreams/core';
const router: Router = Router();

const logger = createLogger('server');

interface SeaDexManifestParams {
encodedConfig?: string; // optional
}

router.get(
'/:encodedConfig/manifest.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<SeaDexManifestParams>, res: Response, next: NextFunction) => {
const { encodedConfig } = req.params;
try {
const manifest = new SeaDexAddon(
Expand All @@ -24,9 +27,15 @@ router.get(
}
);

interface SeaDexStreamParams {
encodedConfig?: string; // optional
type: string;
id: string;
}

router.get(
'/:encodedConfig/stream/:type/:id.json',
async (req: Request, res: Response, next: NextFunction) => {
async (req: Request<SeaDexStreamParams>, res: Response, next: NextFunction) => {
const { encodedConfig, type, id } = req.params;
try {
const streams = await new SeaDexAddon(
Expand Down
Loading