thurston
Route-level file type validation for hapi parsed multipart/form-data
stream request payloads. Also works as a standalone module, and most importantly, works in tandem with houdin for a truly magical experience.
Table of Contents
Installation
Install via NPM.
$ npm install thurston
Usage
async validate(payload, options)
Validates all Stream.Readable
values in a payload
given a whitelist
of file types provided in the options
. Throws a joi-like ValidationError
if some file type is not allowed or unknown otherwise it returns the original parsed payload.
Hapi
const Hapi = ;const Thurston = ; const server = routes: validate: options: whitelist: 'image/png' ; server;
Standalone
const Fs = ;const Thurston = ; const options = whitelist: 'image/png' ; Fs;const png = Fs; try const payload = await Thurston; console; // { file: ReadStream { _readableState: { ..., buffer: [ <Buffer 89 50> ], ... }, ... } }catch err // Unreachable code.);
const Fs = ;const Thurston = ; const options = whitelist: 'image/png' ; Fs;const gif = Fs; try await Thurston;catch err console; // [ValidationError: child "file" fails because ["file" type is not allowed]]
Supported File Types
The same as file-type.