first commit

This commit is contained in:
2024-11-28 22:34:56 +08:00
commit 6e0b8ccc4d
11 changed files with 1578 additions and 0 deletions

75
router/home.js Normal file
View File

@@ -0,0 +1,75 @@
import express from "express";
import Util from '../utils/index.js'
import Config from '../config/config.js'
const router = express.Router();
// 获取首页banner图
// http://192.168.31.101:3030/v1/api/home/banner
router.get('/banner', async (req, res) => {
let $ = await Util.get(`${Config.baseUrl}/?orderby=rand`)
let result = []
$(".new-swiper .swiper-wrapper .swiper-slide").each(function() {
let src = $(this).find("span img").attr("src")
if (src) {
result.push({ src })
}
})
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
})
})
// 获取热门推荐的写真
// http://192.168.31.101:3030/v1/api/home/hot
router.get('/hot', async (req, res) => {
let $ = await Util.get(`${Config.baseUrl}/?orderby=rand`)
let result = []
$(".box-body .tab-content .posts-mini").each(function() {
result.push({
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
title: $(this).find(".item-heading a").text(),
time: $(this).find(".item-meta .icon-circle").text(),
view: $(this).find(".item-meta .meta-right .meta-view").text()
})
})
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
})
})
// 获取首页 默认的随机写真
// http://192.168.31.101:3030/v1/api/home/list
router.get('/list', async (req, res) => {
let $ = await Util.get(`${Config.baseUrl}/?orderby=rand`)
let result = []
$(".tab-content .posts-row .posts-item").each(function() {
result.push({
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
title: $(this).find(".item-heading a").text(),
time: $(this).find(".item-meta .icon-circle").text(),
view: $(this).find(".item-meta .meta-right .meta-view").text()
})
})
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
})
})
export default router

42
router/info.js Normal file
View File

@@ -0,0 +1,42 @@
import express from "express";
import Util from '../utils/index.js'
import Config from '../config/config.js'
const router = express.Router();
// 进入详情的接口
// http://192.168.31.101:3030/v1/api/info/list?id=6808
router.get('/list', async (req, res) => {
let { id } = req.query
let $ = await Util.get(`${Config.baseUrl}/${id}.html`)
let result = {
title: $(".article .article-header .article-title a").text(),
src_list: [],
recommend: [],
}
$(".article-content .wp-posts-content p img").map(function(i, el) {
result.src_list.push($(el).attr("data-src"))
})
$(".swiper-container .swiper-slide a").each(function(i, el) {
result.recommend.push({
id: Util.split($(this).attr("href")).replace(/[^\d]/g, ""),
thumbnail: $(this).find("img").attr("data-src"),
title: $(this).find(".text-ellipsis").text(),
time: $(this).find(".px12 item").eq(0).text(),
view: $(this).find(".px12 item").eq(1).text(),
})
})
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
})
})
export default router

70
router/search.js Normal file
View File

@@ -0,0 +1,70 @@
import express from "express";
import Util from '../utils/index.js'
import Config from '../config/config.js'
const router = express.Router();
// 搜索页面的 热门关键词 & 推荐
// http://192.168.31.101:3030/v1/api/search/hot
router.get('/hot', async (req, res) => {
let $ = await Util.get(`${Config.baseUrl}/wp-admin/admin-ajax.php?action=search_box`)
let result = {
hotKeyword: [],
recommend: []
}
$(".search-input .search-keywords").eq(0).find("div a").each(function() {
result.hotKeyword.push($(this).text())
})
$(".search-input .relates-thumb .swiper-slide a").each(function() {
result.recommend.push({
id: Util.split($(this).attr("href")).replace(/[^\d]/g, ""),
thumbnail: $(this).find("img").attr("data-src"),
title: $(this).find(".text-ellipsis").text(),
time: $(this).find(".px12 item").eq(0).text(),
view: $(this).find(".px12 item").eq(1).text(),
})
})
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
})
})
// 搜索接口
// http://192.168.31.101:3030/v1/api/search/key?keyword=杨晨晨&page=1
router.get('/key', async (req, res) => {
let { keyword, page } = req.query
page = page || 1
let $ = await Util.get(`${Config.baseUrl}/page/${page}?s=${encodeURI(keyword)}&type=post`)
let result = {
currentPage: page,
totalPage: Number($(".pagenav .dots+a").text()),
message: $(".search-content .badg .focus-color").text(),
list: [],
}
$(".search-content .posts-item").each(function() {
result.list.push({
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
title: $(this).find(".item-body .item-heading a").text(),
time: $(this).find(".item-body .item-meta .icon-circle").text(),
view: $(this).find(".item-body .item-meta .meta-right .meta-view").text()
})
})
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
})
})
export default router

76
router/tags.js Normal file
View File

@@ -0,0 +1,76 @@
import express from "express";
import Util from '../utils/index.js'
import Config from '../config/config.js'
const router = express.Router();
// 获取 推荐标签
// http://192.168.31.101:3030/v1/api/tag/recommend
router.get('/recommend', async (req, res) => {
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: [
{ title: '秀人网', count: '9059', url: '/xiuren' },
{ title: 'ROSI写真', count: '6580', url: '/domestic/rosi' },
{ title: '蜜桃社', count: '122', url: '/domestic/miitao' },
{ title: '尤物馆', count: '138', url: '/domestic/youwu' },
]
});
})
// 获取 所有标签
// http://192.168.31.101:3030/v1/api/tag/list
router.get('/list', async (req, res) => {
let $ = await Util.get(Config.hot_tags())
let result = []
$(".categorieslist ul li a").each(function (i) {
result.push({
title: $(this).find("h2").text(),
count: $(this).find("small p").text().replace(/[^\d]/g, ""),
url: Util.split($(this).attr("href")),
});
});
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
});
})
// 进入对应标签的列表页面
// http://192.168.31.101:3030/v1/api/tag/info?url=/xiuren&page=1
router.get('/info', async (req, res) => {
let { url, page } = req.query
page = page || 1
let $ = await Util.get(`${Config.baseUrl}${url}/page/${page}`)
let result = {
count: $(".content-layout .title-h-left .icon-spot").text().replace(/[^\d]/g, ""),
introduce: $(".content-layout .muted-2-color").text(),
totalPage: Number($(".pagenav .dots+a").text()),
currentPage: page,
list: []
}
$(".content-layout .posts-row .posts-item").each(function (i) {
result.list.push({
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
title: $(this).find(".item-body .item-heading a").text(),
time: $(this).find(".item-body .item-meta .icon-circle").text(),
view: $(this).find(".item-body .item-meta .meta-right .meta-view").text()
});
});
res.json({
status: 200,
copyright: `bmy ${new Date()}`,
data: result
});
})
export default router