Skip to content

Commit

Permalink
fix(manga | movies): Add missing mangaId in fetchChapterPages, new sf…
Browse files Browse the repository at this point in the history
…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
2004durgesh authored Dec 3, 2024
1 parent 3e7565d commit 0522c2b
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [ "14.x" ]
node-version: [ "18.x" ]

steps:
- uses: actions/checkout@v3
Expand All @@ -24,4 +24,4 @@ jobs:
- name: Install dependencies & build
run: |
npm install
tsc
npx tsc
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@
"homepage": "https://github.com/consumet/consumet.ts#readme",
"dependencies": {
"@consumet/extensions": "github:consumet/consumet.ts",
"@fastify/cors": "^8.2.0",
"@types/fastify-cors": "^2.1.0",
"@fastify/cors": "^8.5.0",
"@types/node": "^18.11.17",
"@types/ws": "^8.5.3",
"axios": "^1.0.0",
"chalk": "4.1.2",
"cheerio": "1.0.0-rc.12",
"dotenv": "^16.0.3",
"fastify": "^4.10.2",
"fastify-cors": "^6.1.0",
"ioredis": "^5.2.4",
"reconnecting-websocket": "^4.4.0",
"ts-node": "^10.9.1",
"typescript": "5.3.3",
"ws": "^8.8.1"
},
"devDependencies": {
"nodemon": "3.0.1",
"prettier": "^3.0.0"
"prettier": "^3.0.0",
"typescript": "5.3.3"
}
}
6 changes: 5 additions & 1 deletion src/routes/manga/mangakakalot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {

fastify.get('/read', async (request: FastifyRequest, reply: FastifyReply) => {
const chapterId = (request.query as { chapterId: string }).chapterId;
const mangaId = (request.query as { mangaId: string }).mangaId;

if (typeof chapterId === 'undefined')
return reply.status(400).send({ message: 'chapterId is required' });

if (typeof mangaId === 'undefined')
return reply.status(400).send({ message: 'mangaId is required' });

try {
const res = await mangakakalot
.fetchChapterPages(chapterId)
.fetchChapterPages(chapterId,mangaId)
.catch((err: Error) => reply.status(404).send({ message: err.message }));

reply.status(200).send(res);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/movies/dramacool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
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;
const server = (request.query as { server: StreamingServers }).server;

if (typeof episodeId === 'undefined')
return reply.status(400).send({ message: 'episodeId is required' });
try {
const res = await dramacool
.fetchEpisodeSources(episodeId)
.fetchEpisodeSources(episodeId,server)
.catch((err) => reply.status(404).send({ message: 'Media Not found.' }));

reply.status(200).send(res);
Expand Down
6 changes: 6 additions & 0 deletions src/routes/movies/flixhq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
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(
Expand Down
6 changes: 6 additions & 0 deletions src/routes/movies/goku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
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(
Expand Down
2 changes: 2 additions & 0 deletions src/routes/movies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import dramacool from './dramacool';
import fmovies from './fmovies';
import goku from './goku';
import movieshd from './movieshd';
import sflix from './sflix';
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
await fastify.register(flixhq, { prefix: '/flixhq' });
await fastify.register(viewasian, { prefix: '/viewasian' });
await fastify.register(dramacool, { prefix: '/dramacool' });
await fastify.register(fmovies, { prefix: '/fmovies' });
await fastify.register(goku, { prefix: '/goku' });
await fastify.register(movieshd, { prefix: '/movieshd' });
await fastify.register(sflix, { prefix: '/sflix' });
fastify.get('/', async (request: any, reply: any) => {
reply.status(200).send('Welcome to Consumet Movies and TV Shows');
});
Expand Down
6 changes: 6 additions & 0 deletions src/routes/movies/movieshd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
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(
Expand Down
231 changes: 231 additions & 0 deletions src/routes/movies/sflix.ts
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;

0 comments on commit 0522c2b

Please sign in to comment.