-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (47 loc) · 1.53 KB
/
index.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
// Initialization
const yt = require("youtube-search-without-api-key");
const fs = require("fs");
const express = require("express");
const config = JSON.parse(fs.readFileSync("config.json"));
console.log("[SearchService] Conf loaded: ", config);
const asyncHandler = require("express-async-handler");
var cors = require("cors");
// App
const app = express();
// Routes
const FileFetcher = require("./routes/FileFetcher.js");
const Download = require("./routes/Download.js");
const GetThumbnailProxy = require("./routes/GetThumbnailProxy.js");
// Port Config
const port = config.servicePort;
// Middleware
app.use(cors());
app.use(express.static("frontend"));
//Routes
app.get("/", (req, res) => {
res.send("YouTube Search/Download Microservice.");
});
app.get("/download/:id", asyncHandler(Download.downloadYouTube));
app.get(
"/search/:query",
asyncHandler(async (req, res, next) => {
const queryResult = await yt.search(req.params.query);
res.send(queryResult);
})
);
app.get("/search", (req, res) => {
res.send(
`<b>/search/:query: Endpoint</b><br/>
Searches :query: on YouTube.
<br/>
<b>Returns</b> array of results`
);
});
app.get("/fetch/audio/:id", FileFetcher.GetAudio);
app.get("/test", Download.test);
app.get("/getAlbumArt/:id", asyncHandler(GetThumbnailProxy.GetThumbnailProxy));
app.listen(port, () => {
console.log(`Downable-app started at port ${port}`);
});
// YT REGEX
// var myregexp = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/gi;