增加jump游戏资料缓存的接口
This commit is contained in:
parent
e2be3866ca
commit
ba215923ec
65
src/controllers/gameproxy.controller.ts
Normal file
65
src/controllers/gameproxy.controller.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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'
|
||||||
|
|
||||||
|
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 }, {})
|
||||||
|
if (game.inited) {
|
||||||
|
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.inited = false
|
||||||
|
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 }, {})
|
||||||
|
if (game.inited) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
45
src/models/GameCache.ts
Normal file
45
src/models/GameCache.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { BaseModule } from './Base'
|
||||||
|
import { dbconn } from '../decorators/dbconn'
|
||||||
|
import { getModelForClass, modelOptions, prop, Severity, mongoose, index } from '@typegoose/typegoose'
|
||||||
|
|
||||||
|
const jsonExcludeKeys = ['updatedAt', '__v', '_id', 'createdAt', 'isBot', 'type', 'inited']
|
||||||
|
|
||||||
|
@dbconn()
|
||||||
|
@index({ oldGameId: 1 }, { unique: true })
|
||||||
|
@modelOptions({
|
||||||
|
schemaOptions: { collection: 'jump_game_cache', timestamps: true },
|
||||||
|
options: { allowMixed: Severity.ALLOW },
|
||||||
|
})
|
||||||
|
class GameCacheClass extends BaseModule {
|
||||||
|
@prop()
|
||||||
|
public oldGameId: string
|
||||||
|
|
||||||
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
|
public jumpGame: any
|
||||||
|
|
||||||
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
|
public dlcList: any
|
||||||
|
|
||||||
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
|
public jumpGameExt: any
|
||||||
|
|
||||||
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
|
public otherPlatVersion: any
|
||||||
|
@prop({ default: true })
|
||||||
|
public inited: boolean
|
||||||
|
|
||||||
|
public toJson(): any {
|
||||||
|
let result: any = {}
|
||||||
|
// @ts-ignore
|
||||||
|
for (let key in this._doc) {
|
||||||
|
if (jsonExcludeKeys.indexOf(key) == -1) {
|
||||||
|
result[key] = this[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GameCache = getModelForClass(GameCacheClass, {
|
||||||
|
existingConnection: GameCacheClass.db,
|
||||||
|
})
|
37
src/models/GamePriceCache.ts
Normal file
37
src/models/GamePriceCache.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { BaseModule } from './Base'
|
||||||
|
import { dbconn } from '../decorators/dbconn'
|
||||||
|
import { getModelForClass, modelOptions, prop, Severity, mongoose, index } from '@typegoose/typegoose'
|
||||||
|
|
||||||
|
const jsonExcludeKeys = ['updatedAt', '__v', '_id', 'createdAt', 'isBot', 'type', 'inited']
|
||||||
|
|
||||||
|
@dbconn()
|
||||||
|
@index({ oldGameId: 1 }, { unique: true })
|
||||||
|
@modelOptions({
|
||||||
|
schemaOptions: { collection: 'jump_game_price_cache', timestamps: true },
|
||||||
|
options: { allowMixed: Severity.ALLOW },
|
||||||
|
})
|
||||||
|
class GamePriceCacheClass extends BaseModule {
|
||||||
|
@prop()
|
||||||
|
public oldGameId: string
|
||||||
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
|
countries: any
|
||||||
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
|
public prices: any
|
||||||
|
@prop({ default: true })
|
||||||
|
public inited: boolean
|
||||||
|
|
||||||
|
public toJson(): any {
|
||||||
|
let result: any = {}
|
||||||
|
// @ts-ignore
|
||||||
|
for (let key in this._doc) {
|
||||||
|
if (jsonExcludeKeys.indexOf(key) == -1) {
|
||||||
|
result[key] = this[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GamePriceCache = getModelForClass(GamePriceCacheClass, {
|
||||||
|
existingConnection: GamePriceCacheClass.db,
|
||||||
|
})
|
13
src/services/jump.svr.ts
Normal file
13
src/services/jump.svr.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
export async function getJumpGameInfo(gameId: string) {
|
||||||
|
const link = `https://switch.jumpvg.com/jump/game/detail?clickFrom=-1&id=${gameId}&path=find_discount_gamedetail_switch&platform=1&version=3`
|
||||||
|
const { data } = await axios.get(link)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getJumpGamePrice(gameId: string) {
|
||||||
|
const link = `https://switch.jumpvg.com/jump/price/getAllPriceByGame?id=${gameId}&platform=1`
|
||||||
|
const { data } = await axios.get(link)
|
||||||
|
return data
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user