mirror of
https://github.com/zoriya/flood.git
synced 2026-05-28 01:21:25 +00:00
API: torrents: schema validate add-urls and add-files endpoints
Those endpoints use extensive amount of user-provided properties and will be frequently used by third party developers. With Node 15, unhandled promise rejections directly crash the server, as such, it is safer to schema validate the request before processing it. This change also prepares the code paths for later change that adds destination fallbacks.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import {array, boolean, object, record, string} from 'zod';
|
||||
|
||||
import type {infer as zodInfer} from 'zod';
|
||||
|
||||
// POST /api/torrents/add-urls
|
||||
export const addTorrentByURLSchema = object({
|
||||
// URLs to download torrents from
|
||||
urls: array(string().url()).nonempty(),
|
||||
// Cookies to attach to requests, arrays of strings in the format "name=value" with domain as key
|
||||
cookies: record(array(string())).optional(),
|
||||
// Path of destination
|
||||
destination: string(),
|
||||
// Tags
|
||||
tags: array(string()).optional(),
|
||||
// Whether destination is the base path [default: false]
|
||||
isBasePath: boolean().optional(),
|
||||
// Whether destination contains completed contents [default: false]
|
||||
isCompleted: boolean().optional(),
|
||||
// Whether to start torrent [default: false]
|
||||
start: boolean().optional(),
|
||||
});
|
||||
|
||||
export type AddTorrentByURLOptions = zodInfer<typeof addTorrentByURLSchema>;
|
||||
|
||||
// POST /api/torrents/add-files
|
||||
export const addTorrentByFileSchema = object({
|
||||
// Torrent files in base64
|
||||
files: array(string()).nonempty(),
|
||||
// Path of destination
|
||||
destination: string(),
|
||||
// Tags
|
||||
tags: array(string()).optional(),
|
||||
// Whether destination is the base path [default: false]
|
||||
isBasePath: boolean().optional(),
|
||||
// Whether destination contains completed contents [default: false]
|
||||
isCompleted: boolean().optional(),
|
||||
// Whether to start torrent [default: false]
|
||||
start: boolean().optional(),
|
||||
});
|
||||
|
||||
export type AddTorrentByFileOptions = zodInfer<typeof addTorrentByFileSchema>;
|
||||
Reference in New Issue
Block a user