From abf99ba52be3250403147d3d78d1249bce8bcd2c Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Thu, 20 May 2021 23:17:53 +0800 Subject: [PATCH] shared: schema: explicitly use "strictObject" --- shared/schema/Auth.ts | 6 +++--- shared/schema/ClientConnectionSettings.ts | 12 ++++++------ shared/schema/Config.ts | 4 ++-- shared/schema/api/torrents.ts | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/shared/schema/Auth.ts b/shared/schema/Auth.ts index 8f9a99a4..4c3a5f00 100644 --- a/shared/schema/Auth.ts +++ b/shared/schema/Auth.ts @@ -1,4 +1,4 @@ -import {literal, nativeEnum, number, object, string, union} from 'zod'; +import {literal, nativeEnum, number, string, strictObject, union} from 'zod'; import type {infer as zodInfer} from 'zod'; import {AccessLevel} from './constants/Auth'; @@ -8,7 +8,7 @@ export const authMethodSchema = union([literal('default'), literal('none')]); export type AuthMethod = zodInfer; -export const credentialsSchema = object({ +export const credentialsSchema = strictObject({ username: string(), password: string(), client: clientConnectionSettingsSchema, @@ -19,7 +19,7 @@ export type Credentials = zodInfer; export type UserInDatabase = Required & {_id: string; timestamp: number}; -export const authTokenSchema = object({ +export const authTokenSchema = strictObject({ username: string(), // issued at iat: number(), diff --git a/shared/schema/ClientConnectionSettings.ts b/shared/schema/ClientConnectionSettings.ts index 507beaa9..ca2f89d4 100644 --- a/shared/schema/ClientConnectionSettings.ts +++ b/shared/schema/ClientConnectionSettings.ts @@ -1,7 +1,7 @@ -import {literal, number, object, string, union} from 'zod'; +import {literal, number, string, strictObject, union} from 'zod'; import type {infer as zodInfer} from 'zod'; -const delugeConnectionSettingsSchema = object({ +const delugeConnectionSettingsSchema = strictObject({ client: literal('Deluge'), type: literal('rpc'), version: literal(1), @@ -13,7 +13,7 @@ const delugeConnectionSettingsSchema = object({ export type DelugeConnectionSettings = zodInfer; -const qBittorrentConnectionSettingsSchema = object({ +const qBittorrentConnectionSettingsSchema = strictObject({ client: literal('qBittorrent'), type: literal('web'), version: literal(1), @@ -24,7 +24,7 @@ const qBittorrentConnectionSettingsSchema = object({ export type QBittorrentConnectionSettings = zodInfer; -const rTorrentTCPConnectionSettingsSchema = object({ +const rTorrentTCPConnectionSettingsSchema = strictObject({ client: literal('rTorrent'), type: literal('tcp'), version: literal(1), @@ -34,7 +34,7 @@ const rTorrentTCPConnectionSettingsSchema = object({ export type RTorrentTCPConnectionSettings = zodInfer; -const rTorrentSocketConnectionSettingsSchema = object({ +const rTorrentSocketConnectionSettingsSchema = strictObject({ client: literal('rTorrent'), type: literal('socket'), version: literal(1), @@ -50,7 +50,7 @@ const rTorrentConnectionSettingsSchema = union([ export type RTorrentConnectionSettings = zodInfer; -const transmissionConnectionSettingsSchema = object({ +const transmissionConnectionSettingsSchema = strictObject({ client: literal('Transmission'), type: literal('rpc'), version: literal(1), diff --git a/shared/schema/Config.ts b/shared/schema/Config.ts index 56cd8272..38918b7f 100644 --- a/shared/schema/Config.ts +++ b/shared/schema/Config.ts @@ -14,13 +14,13 @@ // env variable FLOOD_OPTION_port=80 is equivalent to argument --port 80. Use ',' to split // for arguments that take multiple inputs such as --allowedpath. -import {array, boolean, number, object, string} from 'zod'; +import {array, boolean, number, strictObject, string} from 'zod'; import type {infer as zodInfer} from 'zod'; import {authMethodSchema} from './Auth'; import {clientConnectionSettingsSchema} from './ClientConnectionSettings'; -export const configSchema = object({ +export const configSchema = strictObject({ // CLI argument: --baseuri // This URI will prefix all of Flood's HTTP requests. // For example, if you intend to serve from http://example.com/flood, set this to diff --git a/shared/schema/api/torrents.ts b/shared/schema/api/torrents.ts index 66982b98..764badc1 100644 --- a/shared/schema/api/torrents.ts +++ b/shared/schema/api/torrents.ts @@ -1,4 +1,4 @@ -import {array, boolean, number, object, record, string} from 'zod'; +import {array, boolean, number, record, strictObject, string} from 'zod'; import {noComma} from '../../util/regEx'; import type {infer as zodInfer} from 'zod'; @@ -8,7 +8,7 @@ const TAG_NO_COMMA_MESSAGE = { }; // POST /api/torrents/add-urls -export const addTorrentByURLSchema = object({ +export const addTorrentByURLSchema = strictObject({ // URLs to download torrents from urls: array(string()).nonempty(), // Cookies to attach to requests, arrays of strings in the format "name=value" with domain as key @@ -32,7 +32,7 @@ export const addTorrentByURLSchema = object({ export type AddTorrentByURLOptions = zodInfer; // POST /api/torrents/add-files -export const addTorrentByFileSchema = object({ +export const addTorrentByFileSchema = strictObject({ // Torrent files in base64 files: array(string()).nonempty(), // Path of destination @@ -54,7 +54,7 @@ export const addTorrentByFileSchema = object({ export type AddTorrentByFileOptions = zodInfer; // PATCH /api/torrents/tags -export const setTorrentsTagsSchema = object({ +export const setTorrentsTagsSchema = strictObject({ // An array of string representing hashes of torrents to operate on hashes: array(string()).nonempty(), // An array of string representing tags @@ -64,7 +64,7 @@ export const setTorrentsTagsSchema = object({ export type SetTorrentsTagsOptions = zodInfer; // POST /api/torrents/reannounce -export const reannounceTorrentsSchema = object({ +export const reannounceTorrentsSchema = strictObject({ // An array of string representing hashes of torrents to be reannounced hashes: array(string()).nonempty(), }); @@ -72,7 +72,7 @@ export const reannounceTorrentsSchema = object({ export type ReannounceTorrentsOptions = zodInfer; // GET /api/torrents/{hash}/contents/{indices}/data -export const contentTokenSchema = object({ +export const contentTokenSchema = strictObject({ username: string(), hash: string(), indices: string(),