更新获取热搜条目

This commit is contained in:
ZtRXR 2023-09-02 00:05:47 +08:00
parent 853916895d
commit 16f4fe82cd
4 changed files with 111 additions and 14 deletions

89
package-lock.json generated
View File

@ -15,6 +15,7 @@
"typeorm": "0.3.17"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/node": "^16.11.10",
"ts-node": "10.7.0",
"typescript": "4.5.2"
@ -81,12 +82,100 @@
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
"devOptional": true
},
"node_modules/@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmmirror.com/@types/body-parser/-/body-parser-1.19.2.tgz",
"integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==",
"dev": true,
"dependencies": {
"@types/connect": "*",
"@types/node": "*"
}
},
"node_modules/@types/connect": {
"version": "3.4.35",
"resolved": "https://registry.npmmirror.com/@types/connect/-/connect-3.4.35.tgz",
"integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/express": {
"version": "4.17.17",
"resolved": "https://registry.npmmirror.com/@types/express/-/express-4.17.17.tgz",
"integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==",
"dev": true,
"dependencies": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "^4.17.33",
"@types/qs": "*",
"@types/serve-static": "*"
}
},
"node_modules/@types/express-serve-static-core": {
"version": "4.17.36",
"resolved": "https://registry.npmmirror.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.36.tgz",
"integrity": "sha512-zbivROJ0ZqLAtMzgzIUC4oNqDG9iF0lSsAqpOD9kbs5xcIM3dTiyuHvBc7R8MtWBp3AAWGaovJa+wzWPjLYW7Q==",
"dev": true,
"dependencies": {
"@types/node": "*",
"@types/qs": "*",
"@types/range-parser": "*",
"@types/send": "*"
}
},
"node_modules/@types/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/@types/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-/K3ds8TRAfBvi5vfjuz8y6+GiAYBZ0x4tXv1Av6CWBWn0IlADc+ZX9pMq7oU0fNQPnBwIZl3rmeLp6SBApbxSQ==",
"dev": true
},
"node_modules/@types/mime": {
"version": "1.3.2",
"resolved": "https://registry.npmmirror.com/@types/mime/-/mime-1.3.2.tgz",
"integrity": "sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==",
"dev": true
},
"node_modules/@types/node": {
"version": "16.18.46",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-16.18.46.tgz",
"integrity": "sha512-Mnq3O9Xz52exs3mlxMcQuA7/9VFe/dXcrgAyfjLkABIqxXKOgBRjyazTxUbjsxDa4BP7hhPliyjVTP9RDP14xg==",
"devOptional": true
},
"node_modules/@types/qs": {
"version": "6.9.8",
"resolved": "https://registry.npmmirror.com/@types/qs/-/qs-6.9.8.tgz",
"integrity": "sha512-u95svzDlTysU5xecFNTgfFG5RUWu1A9P0VzgpcIiGZA9iraHOdSzcxMxQ55DyeRaGCSxQi7LxXDI4rzq/MYfdg==",
"dev": true
},
"node_modules/@types/range-parser": {
"version": "1.2.4",
"resolved": "https://registry.npmmirror.com/@types/range-parser/-/range-parser-1.2.4.tgz",
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==",
"dev": true
},
"node_modules/@types/send": {
"version": "0.17.1",
"resolved": "https://registry.npmmirror.com/@types/send/-/send-0.17.1.tgz",
"integrity": "sha512-Cwo8LE/0rnvX7kIIa3QHCkcuF21c05Ayb0ZfxPiv0W8VRiZiNW/WuRupHKpqqGVGf7SUA44QSOUKaEd9lIrd/Q==",
"dev": true,
"dependencies": {
"@types/mime": "^1",
"@types/node": "*"
}
},
"node_modules/@types/serve-static": {
"version": "1.15.2",
"resolved": "https://registry.npmmirror.com/@types/serve-static/-/serve-static-1.15.2.tgz",
"integrity": "sha512-J2LqtvFYCzaj8pVYKw8klQXrLLk7TBZmQ4ShlcdkELFKGwGMfevMLneMMRkMgZxotOD9wg497LpC7O8PcvAmfw==",
"dev": true,
"dependencies": {
"@types/http-errors": "*",
"@types/mime": "*",
"@types/node": "*"
}
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz",

View File

@ -4,16 +4,17 @@
"description": "Awesome project developed with TypeORM.",
"type": "commonjs",
"devDependencies": {
"ts-node": "10.7.0",
"@types/express": "^4.17.17",
"@types/node": "^16.11.10",
"ts-node": "10.7.0",
"typescript": "4.5.2"
},
"dependencies": {
"typeorm": "0.3.17",
"reflect-metadata": "^0.1.13",
"mysql": "^2.14.1",
"body-parser": "^1.19.1",
"express": "^4.17.2",
"body-parser": "^1.19.1"
"mysql": "^2.14.1",
"reflect-metadata": "^0.1.13",
"typeorm": "0.3.17"
},
"scripts": {
"start": "ts-node src/index.ts",

View File

@ -7,12 +7,19 @@ export class HotTopController{
async all(request: Request, response: Response, next: NextFunction){
const nowDate = new Date()
const yestDay = new Date()
yestDay.setHours(nowDate.getHours()-3)
// console.log(nowDate.toLocaleString())
let num:number
if(request.params.num) num = parseInt(request.params.num)
// console.log(id)
if(isNaN(num) || num>50) num = 15
let hours = 1
let rawHours = parseInt(request.query.hours as unknown as string)
if(request.query.hours && !isNaN(rawHours) && rawHours <=24 && rawHours > 0)
hours = parseInt(request.query.hours as unknown as string)
yestDay.setHours(nowDate.getHours() - hours)
// console.log(yestDay.toLocaleString())
let limit:number
if(request.query.limit) limit = parseInt(request.query.limit as unknown as string)
if(isNaN(limit) || limit>50 || limit<1) limit = 10
// console.log(limit,hours)
// return "OK"
return this.TimesRepository
.createQueryBuilder("time")
@ -24,7 +31,7 @@ export class HotTopController{
}
)
.addOrderBy('time.times',"DESC")
.limit(num)
.limit(limit)
.getMany()
}
}

View File

@ -5,7 +5,7 @@ import { HotTopController } from "./controller/HotTopController";
export const Routes = [
{
method: "get",
route: "/hot/top/:num",
route: "/hot/top/all",
controller: HotTopController,
action: "all"
},