forked from paulhiggs/dvb-i-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall-in-one.js
More file actions
114 lines (105 loc) · 4.67 KB
/
all-in-one.js
File metadata and controls
114 lines (105 loc) · 4.67 KB
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
109
110
111
112
113
114
/**
* all-in-one.js
*
* runner for all three DVB-I V&V tools
*/
import process from "node:process";
import chalk from "chalk";
import commandLineArgs from "command-line-args";
import commandLineUsage from "command-line-usage";
import { xmlRegisterFsInputProviders } from "libxml2-wasm/lib/nodejs.mjs";
xmlRegisterFsInputProviders();
import { CORSlibrary, CORSmanual, CORSnone, CORSoptions, HTTPPort } from "./lib/globals.mjs";
import { Default_SLEPR, MOTD } from "./lib/data_locations.mjs";
import validator from "./lib/validator.mjs";
import { DEFAULT_PROCESSING, SLR_Processing_Modes } from "./lib/slepr.mjs";
// parse command line options
const optionDefinitions = [
{ name: "urls", alias: "u", type: Boolean, defaultValue: false, description: "Load data files from network locations." },
{
name: "port",
alias: "p",
type: Number,
defaultValue: HTTPPort.all_in_one,
typeLabel: "{underline ip-port}",
description: `The HTTP port to listen on. Default: ${HTTPPort.all_in_one}`,
},
{
name: "sport",
alias: "s",
type: Number,
defaultValue: HTTPPort.all_in_one + 1,
typeLabel: "{underline ip-port}",
description: `The HTTPS port to listen on. Default: ${HTTPPort.all_in_one + 1}`,
},
{ name: "nocsr", type: Boolean, defaultValue: false, typeLabel: "{underline flag}", description: "disallow SLR function" },
{ name: "nosl", type: Boolean, defaultValue: false, typeLabel: "{underline flag}", description: "disallow Service List validation" },
{ name: "nocg", type: Boolean, defaultValue: false, typeLabel: "{underline flag}", description: "disallow Content Guide validation" },
{ name: "noslr", type: Boolean, defaultValue: false, typeLabel: "{underline flag}", description: "disallow Service List Registry validation" },
{ name: "CSRfile", alias: "f", type: String, defaultValue: Default_SLEPR.file, typeLabel: "{underline filename}", description: "local file name of SLEPR file" },
{
name: "CORSmode",
alias: "c",
type: String,
defaultValue: CORSlibrary,
typeLabel: "{underline mode}",
description: `type of CORS handling "${CORSlibrary}" (default), "${CORSmanual}" or "${CORSnone}"`,
},
{ name: "motd", alias: "m", type: String, defaultValue: MOTD.file, typeLabel: "{underline filename}", description: "local file name containing HTML for Message Of The Day" },
{
name: "SLRmode",
type: String,
defaultValue: DEFAULT_PROCESSING,
typeLabel: "{underline mode}",
description: `The type of processing for the SLR response [${SLR_Processing_Modes.join(",")}]`,
},
{ name: "help", alias: "h", type: Boolean, defaultValue: false, description: "This help" },
];
const commandLineHelp = [
{
header: "DVB Service List and Content Guide validator",
content: "Syntax and semantic validation of XML documents defined in DVB Blueblook A177 (DVB-I)",
},
{
header: "Synopsis",
content: "$ node all-in-one <options>",
},
{
header: "Options",
optionList: optionDefinitions,
},
{
header: "SLR Client Query",
content: "{underline <host>}:{underline <port>}/query[?{underline arg}={underline value}(&{underline arg}={underline value})*]",
},
{
content: [
{ header: "{underline arg}" },
{ name: "regulatorListFlag", summary: "Select only service lists that have the @regulatorListFlag set as specified (true|false)" },
{ name: "Delivery[]", summary: "Select only service lists that use the specified delivery system (dvb-t|dvb-dash|dvb-c|dvb-s|dvb-iptv)" },
{ name: "TargetCountry[]", summary: "Select only service lists that apply to the specified countries (form: {underline ISO3166 3-digit code})" },
{ name: "Language[]", summary: "Select only service lists that use the specified language (form: {underline IANA 2 digit language code})" },
{ name: "Genre[]", summary: "Select only service lists that match one of the given Genres" },
{ name: "Provider[]", summary: "Select only service lists that match one of the specified Provider names" },
],
},
{ content: "note that all query values except Provider are checked against constraints. An HTTP 400 response is returned with errors in the response body." },
{
header: "About",
content: "Project home: {underline https://github.com/paulhiggs/dvb-i-tools/}",
},
];
const options = commandLineArgs(optionDefinitions);
if (options.help) {
console.log(commandLineUsage(commandLineHelp));
process.exit(0);
}
if (!CORSoptions.includes(options.CORSmode)) {
console.log(chalk.red(`CORSmode must be "${CORSnone}", "${CORSlibrary}" to use the Express cors() handler, or "${CORSmanual}" to have headers inserted manually`));
process.exit(1);
}
if (!SLR_Processing_Modes.includes(options.SLRmode)) {
console.log(chalk.red(`SLRmode must be one of [${SLR_Processing_Modes.join(", ")}]`));
process.exit(1);
}
validator(options);