78 lines
2.8 KiB
JavaScript
78 lines
2.8 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`)
|
|
// $(".new-swiper .swiper-wrapper .swiper-slide").each(function() {
|
|
// let src = $(this).find("span img").attr("src")
|
|
// console.log("src: ", src);
|
|
// if (src) {
|
|
// result.push({ src })
|
|
// }
|
|
// })
|
|
|
|
res.json({
|
|
status: 200,
|
|
copyright: `bmy ${new Date()}`,
|
|
data: [
|
|
{ src: 'https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://imgsa.baidu.com/forum/pic/item/54e736d12f2eb938b7ce5c2990628535e4dd6f4d.jpg' },
|
|
{ src: 'https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://imgsa.baidu.com/forum/pic/item/b899a9014c086e06d533199047087bf40bd1cb56.jpg' },
|
|
{ src: 'https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://imgsa.baidu.com/forum/pic/item/269759ee3d6d55fb6c5d50fd28224f4a21a4dd56.jpg' },
|
|
]
|
|
})
|
|
})
|
|
|
|
// 获取热门推荐的写真
|
|
// 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 |