node-csfd-api 4.3.4 → 5.0.0-next-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/bin/export-ratings.mjs +62 -58
- package/bin/mcp-server.mjs +274 -182
- package/bin/server.mjs +239 -281
- package/cli.mjs +74 -78
- package/dto/creator.d.mts +1 -1
- package/dto/creator.d.ts +1 -1
- package/dto/global.d.mts +1 -1
- package/dto/global.d.ts +1 -1
- package/dto/movie.d.mts +22 -1
- package/dto/movie.d.ts +22 -1
- package/dto/user-reviews.d.mts +1 -1
- package/dto/user-reviews.d.ts +1 -1
- package/helpers/creator.helper.js +2 -2
- package/helpers/creator.helper.js.map +1 -1
- package/helpers/creator.helper.mjs +3 -3
- package/helpers/creator.helper.mjs.map +1 -1
- package/helpers/global.helper.js +52 -0
- package/helpers/global.helper.js.map +1 -1
- package/helpers/global.helper.mjs +50 -1
- package/helpers/global.helper.mjs.map +1 -1
- package/helpers/movie.helper.js +87 -3
- package/helpers/movie.helper.js.map +1 -1
- package/helpers/movie.helper.mjs +84 -5
- package/helpers/movie.helper.mjs.map +1 -1
- package/helpers/search.helper.js +2 -1
- package/helpers/search.helper.js.map +1 -1
- package/helpers/search.helper.mjs +3 -2
- package/helpers/search.helper.mjs.map +1 -1
- package/helpers/user-ratings.helper.js +1 -1
- package/helpers/user-ratings.helper.js.map +1 -1
- package/helpers/user-ratings.helper.mjs +2 -2
- package/helpers/user-ratings.helper.mjs.map +1 -1
- package/helpers/user-reviews.helper.js +2 -2
- package/helpers/user-reviews.helper.js.map +1 -1
- package/helpers/user-reviews.helper.mjs +3 -3
- package/helpers/user-reviews.helper.mjs.map +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/package.json +2 -4
- package/package.mjs +8 -0
- package/services/movie.service.js +15 -3
- package/services/movie.service.js.map +1 -1
- package/services/movie.service.mjs +16 -4
- package/services/movie.service.mjs.map +1 -1
package/bin/server.mjs
CHANGED
|
@@ -1,72 +1,68 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { csfd } from "../index.mjs";
|
|
3
|
+
import { homepage, name, version } from "../package.mjs";
|
|
2
4
|
import "dotenv/config";
|
|
3
5
|
import express from "express";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
//#region src/server/index.ts
|
|
6
8
|
const LOG_COLORS = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// red
|
|
13
|
-
success: "\x1B[32m",
|
|
14
|
-
// green
|
|
15
|
-
reset: "\x1B[0m"
|
|
9
|
+
info: "\x1B[36m",
|
|
10
|
+
warn: "\x1B[33m",
|
|
11
|
+
error: "\x1B[31m",
|
|
12
|
+
success: "\x1B[32m",
|
|
13
|
+
reset: "\x1B[0m"
|
|
16
14
|
};
|
|
17
15
|
const LOG_SYMBOLS = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
info: "ℹ️",
|
|
17
|
+
warn: "⚠️",
|
|
18
|
+
error: "❌",
|
|
19
|
+
success: "✅"
|
|
22
20
|
};
|
|
23
21
|
const LOG_PADDED_SEVERITY = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
info: "INFO ",
|
|
23
|
+
warn: "WARN ",
|
|
24
|
+
error: "ERROR ",
|
|
25
|
+
success: "SUCCESS"
|
|
28
26
|
};
|
|
29
|
-
var Errors = /* @__PURE__ */ (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
27
|
+
var Errors = /* @__PURE__ */ function(Errors) {
|
|
28
|
+
Errors["API_KEY_MISSING"] = "API_KEY_MISSING";
|
|
29
|
+
Errors["API_KEY_INVALID"] = "API_KEY_INVALID";
|
|
30
|
+
Errors["ID_MISSING"] = "ID_MISSING";
|
|
31
|
+
Errors["MOVIE_FETCH_FAILED"] = "MOVIE_FETCH_FAILED";
|
|
32
|
+
Errors["CREATOR_FETCH_FAILED"] = "CREATOR_FETCH_FAILED";
|
|
33
|
+
Errors["SEARCH_FETCH_FAILED"] = "SEARCH_FETCH_FAILED";
|
|
34
|
+
Errors["USER_RATINGS_FETCH_FAILED"] = "USER_RATINGS_FETCH_FAILED";
|
|
35
|
+
Errors["USER_REVIEWS_FETCH_FAILED"] = "USER_REVIEWS_FETCH_FAILED";
|
|
36
|
+
Errors["CINEMAS_FETCH_FAILED"] = "CINEMAS_FETCH_FAILED";
|
|
37
|
+
Errors["PAGE_NOT_FOUND"] = "PAGE_NOT_FOUND";
|
|
38
|
+
Errors["TOO_MANY_REQUESTS"] = "TOO_MANY_REQUESTS";
|
|
39
|
+
return Errors;
|
|
40
|
+
}(Errors || {});
|
|
41
|
+
/**
|
|
42
|
+
* Optimized logging function.
|
|
43
|
+
* Uses global constants to avoid memory reallocation on every request.
|
|
44
|
+
*/
|
|
43
45
|
function logMessage(severity, log, req) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.error(msg);
|
|
55
|
-
} else if (severity === "warn") {
|
|
56
|
-
console.warn(msg);
|
|
57
|
-
} else {
|
|
58
|
-
console.log(msg);
|
|
59
|
-
}
|
|
46
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
47
|
+
const reqInfo = req ? `${req.method}: ${req.originalUrl}` : "";
|
|
48
|
+
const reqIp = req ? req.headers["x-forwarded-for"] || req.socket.remoteAddress || req.ip || req.ips : "";
|
|
49
|
+
const msg = `${LOG_COLORS[severity]}[${LOG_PADDED_SEVERITY[severity]}]${LOG_COLORS.reset} ${time} | IP: ${reqIp} ${LOG_SYMBOLS[severity]} ${log.error ? log.error + ":" : ""} ${log.message} 🔗 ${reqInfo}`;
|
|
50
|
+
const logSuccessEnabled = process.env.VERBOSE === "true";
|
|
51
|
+
if (severity === "success") {
|
|
52
|
+
if (logSuccessEnabled) console.log(msg);
|
|
53
|
+
} else if (severity === "error") console.error(msg);
|
|
54
|
+
else if (severity === "warn") console.warn(msg);
|
|
55
|
+
else console.log(msg);
|
|
60
56
|
}
|
|
61
|
-
var Endpoint = /* @__PURE__ */ (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
57
|
+
var Endpoint = /* @__PURE__ */ function(Endpoint) {
|
|
58
|
+
Endpoint["MOVIE"] = "/movie/:id";
|
|
59
|
+
Endpoint["CREATOR"] = "/creator/:id";
|
|
60
|
+
Endpoint["SEARCH"] = "/search/:query";
|
|
61
|
+
Endpoint["USER_RATINGS"] = "/user-ratings/:id";
|
|
62
|
+
Endpoint["USER_REVIEWS"] = "/user-reviews/:id";
|
|
63
|
+
Endpoint["CINEMAS"] = "/cinemas";
|
|
64
|
+
return Endpoint;
|
|
65
|
+
}(Endpoint || {});
|
|
70
66
|
const app = express();
|
|
71
67
|
const port = process.env.PORT || 3e3;
|
|
72
68
|
const API_KEY_NAME = process.env.API_KEY_NAME || "x-api-key";
|
|
@@ -75,221 +71,195 @@ const RAW_LANGUAGE = process.env.LANGUAGE;
|
|
|
75
71
|
const isSupportedLanguage = (value) => value === "cs" || value === "en" || value === "sk";
|
|
76
72
|
const BASE_LANGUAGE = isSupportedLanguage(RAW_LANGUAGE) ? RAW_LANGUAGE : void 0;
|
|
77
73
|
const API_KEYS_LIST = API_KEY ? API_KEY.split(/[,;\s]+/).map((k) => k.trim()).filter(Boolean) : [];
|
|
78
|
-
if (BASE_LANGUAGE) {
|
|
79
|
-
csfd.setOptions({ language: BASE_LANGUAGE });
|
|
80
|
-
}
|
|
74
|
+
if (BASE_LANGUAGE) csfd.setOptions({ language: BASE_LANGUAGE });
|
|
81
75
|
app.use((req, res, next) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
76
|
+
if (API_KEY) {
|
|
77
|
+
const apiKey = req.get(API_KEY_NAME)?.trim();
|
|
78
|
+
if (!apiKey) {
|
|
79
|
+
const log = {
|
|
80
|
+
error: Errors.API_KEY_MISSING,
|
|
81
|
+
message: `Missing API key in request header: ${API_KEY_NAME}`
|
|
82
|
+
};
|
|
83
|
+
logMessage("error", log, req);
|
|
84
|
+
res.status(401).json(log);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!API_KEYS_LIST.includes(apiKey)) {
|
|
88
|
+
const log = {
|
|
89
|
+
error: Errors.API_KEY_INVALID,
|
|
90
|
+
message: `Invalid API key in request header: ${API_KEY_NAME}`
|
|
91
|
+
};
|
|
92
|
+
logMessage("error", log, req);
|
|
93
|
+
res.status(401).json(log);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
next();
|
|
104
98
|
});
|
|
105
99
|
app.get("/", (_, res) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
logMessage("info", {
|
|
101
|
+
error: null,
|
|
102
|
+
message: "/"
|
|
103
|
+
});
|
|
104
|
+
res.json({
|
|
105
|
+
name,
|
|
106
|
+
version,
|
|
107
|
+
docs: homepage,
|
|
108
|
+
links: Object.values(Endpoint)
|
|
109
|
+
});
|
|
113
110
|
});
|
|
114
|
-
app.get([
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
app.get([
|
|
112
|
+
"/movie/",
|
|
113
|
+
"/creator/",
|
|
114
|
+
"/search/",
|
|
115
|
+
"/user-ratings/",
|
|
116
|
+
"/user-reviews/"
|
|
117
|
+
], (req, res) => {
|
|
118
|
+
const log = {
|
|
119
|
+
error: Errors.ID_MISSING,
|
|
120
|
+
message: `ID is missing. Provide ID like this: ${req.url}${req.url.endsWith("/") ? "" : "/"}1234`
|
|
121
|
+
};
|
|
122
|
+
logMessage("warn", log, req);
|
|
123
|
+
res.status(404).json(log);
|
|
121
124
|
});
|
|
122
|
-
app.get(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
logMessage("error", log, req);
|
|
142
|
-
res.status(500).json(log);
|
|
143
|
-
}
|
|
125
|
+
app.get(Endpoint.MOVIE, async (req, res) => {
|
|
126
|
+
const rawLanguage = req.query.language;
|
|
127
|
+
const language = isSupportedLanguage(rawLanguage) ? rawLanguage : void 0;
|
|
128
|
+
try {
|
|
129
|
+
const movie = await csfd.movie(+req.params.id, { language });
|
|
130
|
+
res.json(movie);
|
|
131
|
+
logMessage("success", {
|
|
132
|
+
error: null,
|
|
133
|
+
message: `${Endpoint.MOVIE}: ${req.params.id}${language ? ` [${language}]` : ""}`
|
|
134
|
+
}, req);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
const log = {
|
|
137
|
+
error: Errors.MOVIE_FETCH_FAILED,
|
|
138
|
+
message: "Failed to fetch movie data: " + error
|
|
139
|
+
};
|
|
140
|
+
logMessage("error", log, req);
|
|
141
|
+
res.status(500).json(log);
|
|
142
|
+
}
|
|
144
143
|
});
|
|
145
|
-
app.get(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
};
|
|
164
|
-
logMessage("error", log, req);
|
|
165
|
-
res.status(500).json(log);
|
|
166
|
-
}
|
|
144
|
+
app.get(Endpoint.CREATOR, async (req, res) => {
|
|
145
|
+
const rawLanguage = req.query.language;
|
|
146
|
+
const language = isSupportedLanguage(rawLanguage) ? rawLanguage : void 0;
|
|
147
|
+
try {
|
|
148
|
+
const result = await csfd.creator(+req.params.id, { language });
|
|
149
|
+
res.json(result);
|
|
150
|
+
logMessage("success", {
|
|
151
|
+
error: null,
|
|
152
|
+
message: `${Endpoint.CREATOR}: ${req.params.id}${language ? ` [${language}]` : ""}`
|
|
153
|
+
}, req);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const log = {
|
|
156
|
+
error: Errors.CREATOR_FETCH_FAILED,
|
|
157
|
+
message: "Failed to fetch creator data: " + error
|
|
158
|
+
};
|
|
159
|
+
logMessage("error", log, req);
|
|
160
|
+
res.status(500).json(log);
|
|
161
|
+
}
|
|
167
162
|
});
|
|
168
|
-
app.get(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
logMessage("error", log, req);
|
|
188
|
-
res.status(500).json(log);
|
|
189
|
-
}
|
|
163
|
+
app.get(Endpoint.SEARCH, async (req, res) => {
|
|
164
|
+
const rawLanguage = req.query.language;
|
|
165
|
+
const language = isSupportedLanguage(rawLanguage) ? rawLanguage : void 0;
|
|
166
|
+
try {
|
|
167
|
+
const result = await csfd.search(req.params.query, { language });
|
|
168
|
+
res.json(result);
|
|
169
|
+
logMessage("success", {
|
|
170
|
+
error: null,
|
|
171
|
+
message: `${Endpoint.SEARCH}: ${req.params.query}${language ? ` [${language}]` : ""}`
|
|
172
|
+
}, req);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
const log = {
|
|
175
|
+
error: Errors.SEARCH_FETCH_FAILED,
|
|
176
|
+
message: "Failed to fetch search data: " + error
|
|
177
|
+
};
|
|
178
|
+
logMessage("error", log, req);
|
|
179
|
+
res.status(500).json(log);
|
|
180
|
+
}
|
|
190
181
|
});
|
|
191
|
-
app.get(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
req
|
|
217
|
-
);
|
|
218
|
-
} catch (error) {
|
|
219
|
-
const log = {
|
|
220
|
-
error: "USER_RATINGS_FETCH_FAILED" /* USER_RATINGS_FETCH_FAILED */,
|
|
221
|
-
message: "Failed to fetch user-ratings data: " + error
|
|
222
|
-
};
|
|
223
|
-
logMessage("error", log, req);
|
|
224
|
-
res.status(500).json(log);
|
|
225
|
-
}
|
|
182
|
+
app.get(Endpoint.USER_RATINGS, async (req, res) => {
|
|
183
|
+
const { allPages, allPagesDelay, excludes, includesOnly, page } = req.query;
|
|
184
|
+
const rawLanguage = req.query.language;
|
|
185
|
+
const language = isSupportedLanguage(rawLanguage) ? rawLanguage : void 0;
|
|
186
|
+
try {
|
|
187
|
+
const result = await csfd.userRatings(req.params.id, {
|
|
188
|
+
allPages: allPages === "true",
|
|
189
|
+
allPagesDelay: allPagesDelay ? +allPagesDelay : void 0,
|
|
190
|
+
excludes: excludes ? excludes.split(",") : void 0,
|
|
191
|
+
includesOnly: includesOnly ? includesOnly.split(",") : void 0,
|
|
192
|
+
page: page ? +page : void 0
|
|
193
|
+
}, { language });
|
|
194
|
+
res.json(result);
|
|
195
|
+
logMessage("success", {
|
|
196
|
+
error: null,
|
|
197
|
+
message: `${Endpoint.USER_RATINGS}: ${req.params.id}${language ? ` [${language}]` : ""}`
|
|
198
|
+
}, req);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const log = {
|
|
201
|
+
error: Errors.USER_RATINGS_FETCH_FAILED,
|
|
202
|
+
message: "Failed to fetch user-ratings data: " + error
|
|
203
|
+
};
|
|
204
|
+
logMessage("error", log, req);
|
|
205
|
+
res.status(500).json(log);
|
|
206
|
+
}
|
|
226
207
|
});
|
|
227
|
-
app.get(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
req
|
|
253
|
-
);
|
|
254
|
-
} catch (error) {
|
|
255
|
-
const log = {
|
|
256
|
-
error: "USER_REVIEWS_FETCH_FAILED" /* USER_REVIEWS_FETCH_FAILED */,
|
|
257
|
-
message: "Failed to fetch user-reviews data: " + error
|
|
258
|
-
};
|
|
259
|
-
logMessage("error", log, req);
|
|
260
|
-
res.status(500).json(log);
|
|
261
|
-
}
|
|
208
|
+
app.get(Endpoint.USER_REVIEWS, async (req, res) => {
|
|
209
|
+
const { allPages, allPagesDelay, excludes, includesOnly, page } = req.query;
|
|
210
|
+
const rawLanguage = req.query.language;
|
|
211
|
+
const language = isSupportedLanguage(rawLanguage) ? rawLanguage : void 0;
|
|
212
|
+
try {
|
|
213
|
+
const result = await csfd.userReviews(req.params.id, {
|
|
214
|
+
allPages: allPages === "true",
|
|
215
|
+
allPagesDelay: allPagesDelay ? +allPagesDelay : void 0,
|
|
216
|
+
excludes: excludes ? excludes.split(",") : void 0,
|
|
217
|
+
includesOnly: includesOnly ? includesOnly.split(",") : void 0,
|
|
218
|
+
page: page ? +page : void 0
|
|
219
|
+
}, { language });
|
|
220
|
+
res.json(result);
|
|
221
|
+
logMessage("success", {
|
|
222
|
+
error: null,
|
|
223
|
+
message: `${Endpoint.USER_REVIEWS}: ${req.params.id}${language ? ` [${language}]` : ""}`
|
|
224
|
+
}, req);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
const log = {
|
|
227
|
+
error: Errors.USER_REVIEWS_FETCH_FAILED,
|
|
228
|
+
message: "Failed to fetch user-reviews data: " + error
|
|
229
|
+
};
|
|
230
|
+
logMessage("error", log, req);
|
|
231
|
+
res.status(500).json(log);
|
|
232
|
+
}
|
|
262
233
|
});
|
|
263
|
-
app.get(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
234
|
+
app.get(Endpoint.CINEMAS, async (req, res) => {
|
|
235
|
+
const rawLanguage = req.query.language;
|
|
236
|
+
const language = isSupportedLanguage(rawLanguage) ? rawLanguage : void 0;
|
|
237
|
+
try {
|
|
238
|
+
const result = await csfd.cinema(1, "today", { language });
|
|
239
|
+
logMessage("success", {
|
|
240
|
+
error: null,
|
|
241
|
+
message: `${Endpoint.CINEMAS}${language ? ` [${language}]` : ""}`
|
|
242
|
+
}, req);
|
|
243
|
+
res.json(result);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
const log = {
|
|
246
|
+
error: Errors.CINEMAS_FETCH_FAILED,
|
|
247
|
+
message: "Failed to fetch cinemas data: " + error
|
|
248
|
+
};
|
|
249
|
+
logMessage("error", log, req);
|
|
250
|
+
res.status(500).json(log);
|
|
251
|
+
}
|
|
282
252
|
});
|
|
283
253
|
app.use((req, res) => {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
254
|
+
const log = {
|
|
255
|
+
error: Errors.PAGE_NOT_FOUND,
|
|
256
|
+
message: "The requested endpoint could not be found."
|
|
257
|
+
};
|
|
258
|
+
logMessage("warn", log, req);
|
|
259
|
+
res.status(404).json(log);
|
|
290
260
|
});
|
|
291
261
|
app.listen(port, () => {
|
|
292
|
-
|
|
262
|
+
console.log(`
|
|
293
263
|
_ __ _ _
|
|
294
264
|
| | / _| | | (_)
|
|
295
265
|
_ __ ___ __| | ___ ___ ___| |_ __| | __ _ _ __ _
|
|
@@ -299,26 +269,14 @@ app.listen(port, () => {
|
|
|
299
269
|
| |
|
|
300
270
|
|_|
|
|
301
271
|
`);
|
|
302
|
-
|
|
303
|
-
`);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
`);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
console.log(`Base language configured: ${BASE_LANGUAGE}
|
|
310
|
-
`);
|
|
311
|
-
}
|
|
312
|
-
if (API_KEYS_LIST.length === 0) {
|
|
313
|
-
console.log(
|
|
314
|
-
"\x1B[31m%s\x1B[0m",
|
|
315
|
-
"\u26A0\uFE0F Server is OPEN!\n- Your server will be open to the world and potentially everyone can use it without any restriction.\n- To enable some basic protection, set API_KEY environment variable (single value or comma-separated list) and provide the same value in request header: " + API_KEY_NAME
|
|
316
|
-
);
|
|
317
|
-
} else {
|
|
318
|
-
console.log(
|
|
319
|
-
"\x1B[32m%s\x1B[0m",
|
|
320
|
-
`\u2714\uFE0F Server is protected (somehow).
|
|
321
|
-
- ${API_KEYS_LIST.length} API key(s) are configured and will be checked for each request header: ${API_KEY_NAME}`
|
|
322
|
-
);
|
|
323
|
-
}
|
|
272
|
+
console.log(`node-csfd-api@${version}\n`);
|
|
273
|
+
console.log(`Docs: ${homepage}`);
|
|
274
|
+
console.log(`Endpoints: ${Object.values(Endpoint).join(", ")}\n`);
|
|
275
|
+
console.log(`API is running on: http://localhost:${port}`);
|
|
276
|
+
if (BASE_LANGUAGE) console.log(`Base language configured: ${BASE_LANGUAGE}\n`);
|
|
277
|
+
if (API_KEYS_LIST.length === 0) console.log("\x1B[31m%s\x1B[0m", "⚠️ Server is OPEN!\n- Your server will be open to the world and potentially everyone can use it without any restriction.\n- To enable some basic protection, set API_KEY environment variable (single value or comma-separated list) and provide the same value in request header: " + API_KEY_NAME);
|
|
278
|
+
else console.log("\x1B[32m%s\x1B[0m", `✔️ Server is protected (somehow).\n- ${API_KEYS_LIST.length} API key(s) are configured and will be checked for each request header: ${API_KEY_NAME}`);
|
|
324
279
|
});
|
|
280
|
+
|
|
281
|
+
//#endregion
|
|
282
|
+
export { };
|