Skip to content

Commit

Permalink
Merge pull request #45 from zakirkun/feat-zakir
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
febryardiansyah authored Aug 10, 2024
2 parents 5b8773c + d8370a5 commit 6b86a4a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 51 deletions.
8 changes: 6 additions & 2 deletions constants/urls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const baseUrl = 'https://komiku.id/'
const baseUrl = process.env.KOMIKU_URL;
const baseApi = process.env.API_KOMIKU_URL;

module.exports = baseUrl
module.exports = {
baseApi,
baseUrl
}
2 changes: 1 addition & 1 deletion helpers/axiosService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const axios = require("axios").default;
const baseUrl = require("../constants/urls");
const {baseUrl} = require("../constants/urls");
const axiosCookieJarSupport = require("axios-cookiejar-support").default;
axiosCookieJarSupport(axios);

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config();
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "MODE=PRODUCTION node index.js",
"dev": "MODE=DEVELOPMENT nodemon index.js"
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
Expand All @@ -16,6 +16,7 @@
"axios-https-proxy-fix": "^0.17.1",
"cheerio": "^1.0.0-rc.3",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.17.1",
"got": "^11.5.2",
"helmet": "^3.23.3",
Expand Down
2 changes: 1 addition & 1 deletion routers/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ router.get("/:slug", async (req, res) => {
obj.chapter_endpoint = slug + "/";
obj.chapter_name = slug.split('-').join(' ').trim()

obj.title = $('#Judul > h1').text().trim()
obj.title = $('#Judul > header > p > a > b').text().trim()
/**
* @Komiku
*/
Expand Down
100 changes: 54 additions & 46 deletions routers/manga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const router = require("express").Router();
const cheerio = require("cheerio");
const baseUrl = require("../constants/urls");
const {baseUrl, baseApi} = require("../constants/urls");
const replaceMangaPage = "https://komiku.id/manga/";
const AxiosService = require("../helpers/axiosService");

Expand All @@ -14,26 +14,28 @@ router.get("/manga/popular", async (req, res) => {
//mangalist pagination -------Done------
router.get("/manga/page/:pagenumber", async (req, res) => {
let pagenumber = req.params.pagenumber;
let url =
let path =
pagenumber === "1"
? "https://data.komiku.id/pustaka/"
: `https://data.komiku.id/pustaka/page/${pagenumber}/`;
? "/manga/"
: `/manga/page/${pagenumber}/`;
let url = baseApi + path;

try {
const response = await AxiosService(url);
console.log(url);
if (response.status === 200) {
const $ = cheerio.load(response.data);
const element = $(".perapih");
const element = $(".bge");
let manga_list = [];
let title, type, updated_on, endpoint, thumb, chapter;

element.find(".daftar > .bge").each((idx, el) => {

element.each((idx, el) => {
console.log(1);
title = $(el).find(".kan > a").find("h3").text().trim();
endpoint = $(el).find("a").attr("href").replace(replaceMangaPage, "");
type = $(el).find(".bgei > a").find(".tpe1_inf > b").text();
updated_on = $(el).find(".kan > span").text().split("• ")[1].trim();
thumb = $(el).find(".bgei > a").find("img").attr("data-src");
thumb = $(el).find(".bgei > a").find("img").attr("src");
chapter = $(el)
.find("div.kan > div:nth-child(5) > a > span:nth-child(2)")
.text();
Expand All @@ -45,6 +47,7 @@ router.get("/manga/page/:pagenumber", async (req, res) => {
endpoint,
chapter,
});

});
return res.status(200).json({
status: true,
Expand All @@ -68,15 +71,9 @@ router.get("/manga/page/:pagenumber", async (req, res) => {
// detail manga ---- Done -----
router.get("/manga/detail/:slug", async (req, res) => {
const slug = req.params.slug;
let endpoint;
console.log(slug);
if(slug === 'tokyo%e5%8d%8drevengers'){
endpoint = 'tokyo卍revengers/';
}else{
endpoint = slug;
}

try {
const response = await AxiosService(`manga/${endpoint}/`);
const response = await AxiosService(`/manga/${slug}`);
const $ = cheerio.load(response.data);
const element = $(".perapih");
let genre_list = [];
Expand Down Expand Up @@ -138,17 +135,17 @@ router.get("/manga/detail/:slug", async (req, res) => {
});

//serach manga ------Done-----------
router.get("/search/:query", async (req, res) => {
const query = req.params.query;
const url = `https://data.komiku.id/cari/?post_type=manga&s=${query}`;
router.get("/search/", async (req, res) => {
const query = req.query.q;
const url = baseApi + `?post_type=manga&s=${query}`;

try {
const response = await AxiosService(url);
const $ = cheerio.load(response.data);
const element = $(".daftar");
const element = $(".bge");
let manga_list = [];
let title, thumb, type, endpoint, updated_on;
element.find(".bge").each((idx, el) => {
element.each((idx, el) => {
endpoint = $(el)
.find("a")
.attr("href")
Expand Down Expand Up @@ -219,21 +216,23 @@ router.get("/genres", async (req, res) => {
router.get("/genres/:slug/:pagenumber", async (req, res) => {
const slug = req.params.slug;
const pagenumber = req.params.pagenumber;
const url =
const path =
pagenumber === "1"
? `https://data.komiku.id/pustaka/?orderby=modified&genre=${slug}&genre2=&status=&category_name=`
: `https://data.komiku.id/pustaka/page/${pagenumber}/?orderby=modified&genre=${slug}&genre2&status&category_name`;
? `genre/${slug}/?orderby=modified&genre2&status&category_name`
: `manga/page/${pagenumber}/?orderby=modified&category_name&genre=${slug}&genre2&status`;
const url = baseApi + path;

try {
const response = await AxiosService(url);
const $ = cheerio.load(response.data);
const element = $(".daftar");
const element = $(".bge");
var thumb, title, endpoint, type;
var manga_list = [];
element.find(".bge").each((idx, el) => {
element.each((idx, el) => {
title = $(el).find(".kan").find("h3").text().trim();
endpoint = $(el).find("a").attr("href").replace(replaceMangaPage, "");
type = $(el).find("div.bgei > a > div").find("b").text();
thumb = $(el).find("div.bgei > a > img").attr("data-src");
thumb = $(el).find("div.bgei > a > img").attr("src");
manga_list.push({
title,
type,
Expand All @@ -258,33 +257,36 @@ router.get("/genres/:slug/:pagenumber", async (req, res) => {
//manga popular pagination ----- Done ------
router.get("/manga/popular/:pagenumber", async (req, res) => {
const pagenumber = req.params.pagenumber;
const url =
const path =
pagenumber === "1"
? `other/rekomendasi/`
: `other/rekomendasi/page/${pagenumber}/`;
const url = baseApi + path;

try {
const response = await AxiosService(url);
const $ = cheerio.load(response.data);
const element = $(".daftar");
let thumb, title, endpoint, type, upload_on;
const element = $(".bge");
let thumb, title, endpoint, type, upload_on, sortDesc;
let manga_list = [];
element.find(".bge").each((idx, el) => {
element.each((idx, el) => {
title = $(el).find(".kan").find("h3").text().trim();
endpoint = $(el)
.find("a")
.attr("href")
.replace(replaceMangaPage, "")
.replace("/manga/", "");
type = $(el).find("div.bgei > a > div.tpe1_inf > b").text();
thumb = $(el).find("div.bgei > a > img").attr("data-src");
upload_on = $(el).find("div.kan > p").text().split(".")[0].trim();
thumb = $(el).find("div.bgei > a > img").attr("src");
sortDesc = $(el).find("div.kan > p").text().trim();
upload_on = $(el).find("div.kan > span.judul2").text().split("•")[1].trim();
manga_list.push({
title,
type,
thumb,
endpoint,
upload_on,
sortDesc
});
});
res.json({
Expand All @@ -302,17 +304,23 @@ router.get("/manga/popular/:pagenumber", async (req, res) => {
});

//recommended ---done---
router.get("/recommended", async (req, res) => {
router.get("/recommended/:pagenumber", async (req, res) => {
const pagenumber = req.params.pagenumber;
const path =
pagenumber === "1"
? `other/hot/`
: `other/hot/page/${pagenumber}/`;
const url = baseApi + path;
try {
const response = await AxiosService("other/hot/");
const response = await AxiosService(url);

const $ = cheerio.load(response.data);
const element = $("div.daftar > .bge");
const element = $(".bge");
let manga_list = [];
let type, title, chapter, update, endpoint, thumb;
element.each((idx, el) => {
title = $(el).find("div.kan > a > h3").text().trim();
thumb = $(el).find("div.bgei > a > img").attr("data-src");
thumb = $(el).find("div.bgei > a > img").attr("src");
endpoint = $(el)
.find("div.kan > a")
.attr("href")
Expand Down Expand Up @@ -340,36 +348,36 @@ router.get("/recommended", async (req, res) => {
});

//manhua ------Done------
router.get("/manhua/:pagenumber", async (req, res) => {
router.get("/manhua/page/:pagenumber", async (req, res) => {
await getManhuaManhwa(req, res, `manhua`);
});

//manhwa
router.get("/manhwa/:pagenumber", async (req, res) => {
router.get("/manhwa/page/:pagenumber", async (req, res) => {
await getManhuaManhwa(req, res, `manhwa`);
});

const getManhuaManhwa = async (req, res, type) => {
let pagenumber = req.params.pagenumber;
let url =
let path =
pagenumber === "1"
? `https://data.komiku.id/pustaka/?orderby=&category_name=${type}&genre=&genre2=&status=`
: `https://data.komiku.id/pustaka/page/${pagenumber}/?orderby&category_name=${type}&genre&genre2&status`;

? `manga/?orderby=&category_name=${type}&genre=&genre2=&status=`
: `manga/page/${pagenumber}/?orderby&category_name=${type}&genre&genre2&status`;
const url = baseApi + path;
try {
console.log(url);
const response = await AxiosService(url);
const $ = cheerio.load(response.data);
const element = $(".perapih");
const element = $(".bge");
var manga_list = [];
var title, type, updated_on, endpoint, thumb, chapter;

element.find(".daftar > .bge").each((idx, el) => {
element.each((idx, el) => {
title = $(el).find(".kan > a").find("h3").text().trim();
endpoint = $(el).find("a").attr("href").replace(replaceMangaPage, "");
type = $(el).find(".bgei > a").find(".tpe1_inf > b").text().trim();
updated_on = $(el).find(".kan > span").text().split("• ")[1].trim();
thumb = $(el).find(".bgei > a").find("img").attr("data-src");
thumb = $(el).find(".bgei > a").find("img").attr("src");
chapter = $(el)
.find("div.kan > div:nth-child(5) > a > span:nth-child(2)")
.text();
Expand Down

0 comments on commit 6b86a4a

Please sign in to comment.