Files
xiezheng/router/home.js
编码猿 4dd0c5d928
Some checks reported errors
continuous-integration/drone/push Build was killed
增加接口,增加index
2024-12-12 11:10:07 +08:00

75 lines
2.2 KiB
JavaScript

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:9940/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:9940/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:9940/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