-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(manga | movies): Add missing mangaId in fetchChapterPages, new sf…
…lix provider and changes in /servers endpoint error logging in movies routes, add server params in dramacool's episode fetching (#640) * fix(manga | movies): Add missing mangaId in fetchChapterPages, new sflix provider and changes in /servers endpoint error logging in movies routes, add server params in dramacool's episode fetching * fix: chore: update Node.js version to 18.x in CI workflow, remove deprecated fastify-cors and @types/fastify-cors * fix: add typescript to devDependencies for Node.js CI workflow
- Loading branch information
1 parent
3e7565d
commit 0522c2b
Showing
9 changed files
with
263 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify'; | ||
import { MOVIES } from '@consumet/extensions'; | ||
import { StreamingServers } from '@consumet/extensions/dist/models'; | ||
|
||
import cache from '../../utils/cache'; | ||
import { redis } from '../../main'; | ||
import { Redis } from 'ioredis'; | ||
|
||
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { | ||
const sflix = new MOVIES.SFlix(); | ||
|
||
fastify.get('/', (_, rp) => { | ||
rp.status(200).send({ | ||
intro: | ||
"Welcome to the sflix provider: check out the provider's website @ https://sflix.to/", | ||
routes: ['/:query', '/info', '/watch','/recent-shows','/recent-movies','/trending','/servers','/country','/genre'], | ||
documentation: 'https://docs.consumet.org/#tag/sflix', | ||
}); | ||
}); | ||
|
||
fastify.get('/:query', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const query = decodeURIComponent((request.params as { query: string }).query); | ||
|
||
const page = (request.query as { page: number }).page; | ||
|
||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:${query}:${page}`, | ||
async () => await sflix.search(query, page ? page : 1), | ||
60 * 60 * 6, | ||
) | ||
: await sflix.search(query, page ? page : 1); | ||
|
||
reply.status(200).send(res); | ||
}); | ||
|
||
fastify.get('/recent-shows', async (request: FastifyRequest, reply: FastifyReply) => { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:recent-shows`, | ||
async () => await sflix.fetchRecentTvShows(), | ||
60 * 60 * 3, | ||
) | ||
: await sflix.fetchRecentTvShows(); | ||
|
||
reply.status(200).send(res); | ||
}); | ||
|
||
fastify.get('/recent-movies', async (request: FastifyRequest, reply: FastifyReply) => { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:recent-movies`, | ||
async () => await sflix.fetchRecentMovies(), | ||
60 * 60 * 3, | ||
) | ||
: await sflix.fetchRecentMovies(); | ||
|
||
reply.status(200).send(res); | ||
}); | ||
|
||
fastify.get('/trending', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const type = (request.query as { type: string }).type; | ||
try { | ||
if (!type) { | ||
const res = { | ||
results: [ | ||
...(await sflix.fetchTrendingMovies()), | ||
...(await sflix.fetchTrendingTvShows()), | ||
], | ||
}; | ||
return reply.status(200).send(res); | ||
} | ||
|
||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:trending:${type}`, | ||
async () => | ||
type === 'tv' | ||
? await sflix.fetchTrendingTvShows() | ||
: await sflix.fetchTrendingMovies(), | ||
60 * 60 * 3, | ||
) | ||
: type === 'tv' | ||
? await sflix.fetchTrendingTvShows() | ||
: await sflix.fetchTrendingMovies(); | ||
|
||
reply.status(200).send(res); | ||
} catch (error) { | ||
reply.status(500).send({ | ||
message: | ||
'Something went wrong. Please try again later. or contact the developers.', | ||
}); | ||
} | ||
}); | ||
|
||
fastify.get('/info', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const id = (request.query as { id: string }).id; | ||
|
||
if (typeof id === 'undefined') | ||
return reply.status(400).send({ | ||
message: 'id is required', | ||
}); | ||
|
||
try { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:info:${id}`, | ||
async () => await sflix.fetchMediaInfo(id), | ||
60 * 60 * 3, | ||
) | ||
: await sflix.fetchMediaInfo(id); | ||
|
||
reply.status(200).send(res); | ||
} catch (err) { | ||
reply.status(500).send({ | ||
message: | ||
'Something went wrong. Please try again later. or contact the developers.', | ||
}); | ||
} | ||
}); | ||
|
||
fastify.get('/watch', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const episodeId = (request.query as { episodeId: string }).episodeId; | ||
const mediaId = (request.query as { mediaId: string }).mediaId; | ||
const server = (request.query as { server: StreamingServers }).server; | ||
|
||
if (typeof episodeId === 'undefined') | ||
return reply.status(400).send({ message: 'episodeId is required' }); | ||
if (typeof mediaId === 'undefined') | ||
return reply.status(400).send({ message: 'mediaId is required' }); | ||
|
||
if (server && !Object.values(StreamingServers).includes(server)) | ||
return reply.status(400).send({ message: 'Invalid server query' }); | ||
|
||
try { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:watch:${episodeId}:${mediaId}:${server}`, | ||
async () => await sflix.fetchEpisodeSources(episodeId, mediaId, server), | ||
60 * 30, | ||
) | ||
: await sflix.fetchEpisodeSources(episodeId, mediaId, server); | ||
|
||
reply.status(200).send(res); | ||
} catch (err) { | ||
reply | ||
.status(500) | ||
.send({ message: 'Something went wrong. Please try again later.' }); | ||
} | ||
}); | ||
|
||
fastify.get('/servers', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const episodeId = (request.query as { episodeId: string }).episodeId; | ||
const mediaId = (request.query as { mediaId: string }).mediaId; | ||
|
||
if (typeof episodeId === 'undefined') | ||
return reply.status(400).send({ message: 'episodeId is required' }); | ||
if (typeof mediaId === 'undefined') | ||
return reply.status(400).send({ message: 'mediaId is required' }); | ||
|
||
try { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:servers:${episodeId}:${mediaId}`, | ||
async () => await sflix.fetchEpisodeServers(episodeId, mediaId), | ||
60 * 30, | ||
) | ||
: await sflix.fetchEpisodeServers(episodeId, mediaId); | ||
|
||
reply.status(200).send(res); | ||
} catch (error) { | ||
reply.status(500).send({ | ||
message: | ||
'Something went wrong. Please try again later. or contact the developers.', | ||
}); | ||
} | ||
}); | ||
|
||
fastify.get('/country/:country', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const country = (request.params as { country: string }).country; | ||
const page = (request.query as { page: number }).page ?? 1; | ||
try { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:country:${country}:${page}`, | ||
async () => await sflix.fetchByCountry(country, page), | ||
60 * 60 * 3, | ||
) | ||
: await sflix.fetchByCountry(country, page); | ||
|
||
reply.status(200).send(res); | ||
} catch (error) { | ||
reply.status(500).send({ | ||
message: | ||
'Something went wrong. Please try again later. or contact the developers.', | ||
}); | ||
} | ||
}); | ||
|
||
|
||
fastify.get('/genre/:genre', async (request: FastifyRequest, reply: FastifyReply) => { | ||
const genre = (request.params as { genre: string }).genre; | ||
const page = (request.query as { page: number }).page ?? 1; | ||
try { | ||
let res = redis | ||
? await cache.fetch( | ||
redis as Redis, | ||
`sflix:genre:${genre}:${page}`, | ||
async () => await sflix.fetchByGenre(genre, page), | ||
60 * 60 * 3, | ||
) | ||
: await sflix.fetchByGenre(genre, page); | ||
|
||
reply.status(200).send(res); | ||
} catch (error) { | ||
reply.status(500).send({ | ||
message: | ||
'Something went wrong. Please try again later. or contact the developers.', | ||
}); | ||
} | ||
}); | ||
}; | ||
export default routes; |