-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js.bak
71 lines (59 loc) · 1.99 KB
/
index.js.bak
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
require('dotenv').config();
const path = require("path")
const fastify = require('fastify')({
logger: true
})
const port = process.env.PORT || 3000;
let playlistUrl = ''; // Variable para almacenar la URL
const {
getArtistsImage,
generateMatrix,
getPlaylist,
} = require('./functions');
const { log } = require("console");
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'public'),
prefix: '/'
})
fastify.get('/', (request, reply) => {
reply.sendFile('index.html')
})
fastify.get('/playlist', (request, reply) => {
reply.sendFile('playlist.html')
})
fastify.get('/indexdata', async function (request, reply) {
try {
const { first17Artists, restOfArtists } = await getArtistsImage();
const matriz1 = generateMatrix(7, 5, first17Artists);
const matriz2 = generateMatrix(2, 5, restOfArtists);
reply.send({ matriz1, matriz2 });
} catch (error) {
reply.status(500).send({ error: 'Error obteniendo datos' });
}
})
fastify.post('/submitPlaylist', async function (request, reply) {
try {
playlistUrl = request.body.urlInput;
reply.send({ message: 'Información de la lista de reproducción recibida correctamente.' });
} catch (error) {
reply.status(500).send({ error: 'Error al procesar la información de la lista de reproducción' });
}
});
fastify.get('/playlistdata', async (request, reply) => {
try {
const data = await getPlaylist(playlistUrl);
reply.send({
playlistInfo: data.playlistInfo,
detailedArtistInfo: data.detailedArtistInfo,
});
} catch (error) {
fastify.log.error('Error en la ruta /playlist:', error);
reply.status(500).send({ error: 'Error obteniendo la información de la playlist' });
}
});
fastify.listen({ port }, function (err, address) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
})