UNPKG

wkr-util

Version:
25 lines (19 loc) 883 B
import fs from 'fs' import {messageObj, simpleValidationResult} from '@cullylarson/validate' module.exports = (value) => { if(!value) { return Promise.resolve(simpleValidationResult(messageObj('no-file', 'Please upload a file.'))) } if(!value.size) { return Promise.resolve(simpleValidationResult(messageObj('file-empty', 'The file you have provided is empty.'))) } if(!value.path) { return Promise.resolve(simpleValidationResult(messageObj('upload-error', 'Something went wrong and your file was not uploaded.'))) } return new Promise((resolve, reject) => { fs.access(value.path, fs.R_OK, (err) => { if(err) return resolve(simpleValidationResult(messageObj('not-readable', 'Something went wrong and your file could not be read.'))) return resolve(simpleValidationResult()) }) }) }