69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import BaseController from '../common/base.controller'
|
|
import { role, router } from '../decorators/router'
|
|
import { GameCache } from '../models/GameCache'
|
|
import { getJumpGameInfo, getJumpGamePrice } from '../services/jump.svr'
|
|
import { GamePriceCache } from '../models/GamePriceCache'
|
|
const timeOut = 8 * 3600 * 1000
|
|
|
|
class GameProxyController extends BaseController {
|
|
/**
|
|
* 获取游戏详情
|
|
*/
|
|
@role('anon')
|
|
@router('get /api/svr/getgameinfoext')
|
|
async gameInfo(req: any) {
|
|
let { accountId, oldGameId } = req.params
|
|
oldGameId += ''
|
|
let game = await GameCache.insertOrUpdate({ oldGameId }, {})
|
|
let now = Date.now()
|
|
if (now - game.lastupdate > timeOut) {
|
|
try {
|
|
let res = await getJumpGameInfo(oldGameId)
|
|
if (res.success) {
|
|
const data = res.data
|
|
game.jumpGame = data.jumpGame
|
|
game.dlcList = data.dlcList
|
|
game.jumpGameExt = data.jumpGameExt
|
|
game.otherPlatVersion = data.otherPlatVersion
|
|
game.lastupdate = Date.now()
|
|
await game.save()
|
|
}
|
|
} catch (err) {
|
|
console.log(err)
|
|
}
|
|
}
|
|
return game.toJson()
|
|
}
|
|
|
|
/**
|
|
* 获取游戏详情
|
|
*/
|
|
@role('anon')
|
|
@router('get /api/svr/getgameprice')
|
|
async gamePrice(req: any) {
|
|
let { accountId, oldGameId, nums } = req.params
|
|
nums = nums | 0 || 0
|
|
oldGameId += ''
|
|
let game = await GamePriceCache.insertOrUpdate({ oldGameId }, {})
|
|
let now = Date.now()
|
|
if (now - game.lastupdate > timeOut) {
|
|
try {
|
|
let res = await getJumpGamePrice(oldGameId)
|
|
if (res.success) {
|
|
const data = res.data
|
|
game.countries = data.countries
|
|
game.prices = data.prices
|
|
await game.save()
|
|
}
|
|
} catch (err) {
|
|
console.log(err)
|
|
}
|
|
}
|
|
let result = game.toJson()
|
|
if (nums > 0 && result.prices.length > nums) {
|
|
result.prices.length = nums
|
|
}
|
|
return result
|
|
}
|
|
}
|