( viewer: Viewer, inputValidator: TType<T>, input: mixed, source: string, )
| 28 | import { thisKeyserverID } from '../user/identity.js'; |
| 29 | |
| 30 | async function validateInput<T>( |
| 31 | viewer: Viewer, |
| 32 | inputValidator: TType<T>, |
| 33 | input: mixed, |
| 34 | source: string, |
| 35 | ): Promise<T> { |
| 36 | if (!viewer.isSocket) { |
| 37 | await checkClientSupported(viewer, inputValidator, input); |
| 38 | } |
| 39 | const convertedInput = checkInputValidator(inputValidator, input, source); |
| 40 | |
| 41 | const keyserverID = await thisKeyserverID(); |
| 42 | |
| 43 | if ( |
| 44 | hasMinStateVersion(viewer.platformDetails, { |
| 45 | native: 43, |
| 46 | web: 3, |
| 47 | }) |
| 48 | ) { |
| 49 | try { |
| 50 | return convertClientIDsToServerIDs( |
| 51 | keyserverID, |
| 52 | inputValidator, |
| 53 | convertedInput, |
| 54 | ); |
| 55 | } catch (err) { |
| 56 | throw new ServerError(err.message); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return convertedInput; |
| 61 | } |
| 62 | |
| 63 | async function validateOutput<T>( |
| 64 | platformDetails: ?PlatformDetails, |
no test coverage detected