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