Skip to content

Commit 07205c6

Browse files
committed
web/middleware/checkVersion.ts
1 parent 593a19c commit 07205c6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/web/middleware/checkVersion.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Application, NextFunction, Request, Response} from "express";
12
import {promisify} from "util";
23

34
import request from "request";
@@ -15,7 +16,7 @@ const rp = promisify(request)
1516
/**
1617
* @param {Express.Application|Express.Request} ctx
1718
*/
18-
export async function checkVersion(ctx) {
19+
export async function checkVersion(ctx: Request | Application):Promise<void> {
1920
if (lastCheckAt && (lastCheckAt + CHECK_TIMEOUT > Date.now())) {
2021
return
2122
}
@@ -36,7 +37,7 @@ export async function checkVersion(ctx) {
3637
return
3738
}
3839

39-
const locals = ctx.locals ? ctx.locals : ctx.app.locals
40+
const locals = ctx.locals ? ctx.locals : (ctx as Request).app.locals
4041

4142
locals.versionInfo.latest = data.latest
4243
locals.versionInfo.versionItem = data.latest ? null : data.versionItem
@@ -53,7 +54,7 @@ export async function checkVersion(ctx) {
5354
}
5455
}
5556

56-
export function versionCheckMiddleware(req, res, next) {
57+
export function versionCheckMiddleware(req: Request, res: Response, next: NextFunction): void {
5758
checkVersion(req)
5859
.then(() => {
5960
next()

typings/passport/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ declare namespace Express {
22
export interface User {
33
id?: string
44
}
5+
6+
export interface Request {
7+
locals?: Record<string, string>
8+
}
59
}

0 commit comments

Comments
 (0)