-
Notifications
You must be signed in to change notification settings - Fork 4
/
validation.js
108 lines (104 loc) · 2.52 KB
/
validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';
const Ajv = require('ajv');
const ajv = new Ajv();
const schema = {
$id: 'https://just-comments.com/comment-input.json',
type: 'object',
definitions: {},
$schema: 'http://json-schema.org/draft-06/schema#',
properties: {
itemId: {
$id: '/properties/itemId',
type: 'string',
title: 'The Itemid Schema ',
default: '',
examples: ['127.0.0.1/demo.html'],
minLength: 1,
maxLength: 2048,
},
originalItemId: {
$id: '/properties/originalItemId',
type: 'string',
title: 'The Originalitemid Schema ',
default: '',
examples: ['127.0.0.1/demo.html'],
minLength: 1,
maxLength: 2048,
},
itemProtocol: {
$id: '/properties/itemProtocol',
type: 'string',
title: 'The Itemprotocol Schema ',
default: '',
minLength: 1,
maxLength: 32,
examples: ['http:'],
},
itemPort: {
$id: '/properties/itemPort',
type: 'string',
title: 'The Itemport Schema ',
default: '',
minLength: 0,
maxLength: 16,
examples: ['8080'],
},
commentId: {
$id: '/properties/commentId',
type: 'string',
title: 'The Commentid Schema ',
default: '',
minLength: 1,
maxLength: 128,
examples: ['9f6c226d-f754-48e6-a8b0-d957719fd23c'],
},
message: {
$id: '/properties/message',
type: 'string',
title: 'The Message Schema',
default: '',
minLength: 1,
maxLength: 5000,
examples: ['comment message'],
},
website: {
$id: '/properties/website',
type: 'string',
title: 'The Website Schema ',
default: '',
examples: ['https://just-comments.com'],
format: 'uri',
},
captchaResult: {
$id: '/properties/captchaResult',
type: 'string',
title: 'captchaResult schema',
},
pageUrl: {
$id: '/properties/pageUrl',
type: 'string',
title: 'pageUrl schema',
},
pageTitle: {
$id: '/properties/pageTitle',
type: 'string',
title: 'pageTitle schema',
},
locale: {
$id: '/properties/locale',
type: 'string',
title: 'locale schema',
},
timezone: {
$id: '/properties/timezone',
type: 'string',
title: 'timezone schema',
},
},
required: ['itemId', 'originalItemId', 'itemProtocol', 'itemPort', 'message'],
};
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
const validateComment = ajv.compile(schema);
module.exports = {
validateComment,
};