Skip to content

Commit

Permalink
Add smartglass api's to server component
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownskl committed Sep 23, 2024
1 parent 7b93ff7 commit 4d1b886
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"@greenlight/logger": "workspace:^",
"@greenlight/storeapi": "workspace:^",
"@greenlight/xcloudapi": "workspace:^",
"@greenlight/webapi": "workspace:^",
"fastify": "^5.0.0"
},
"license": "MIT",
"main": "dist/index",
"scripts": {
"start": "yarn build:deps && yarn build && DEBUG='*' node dist/bin/server.js",
"build": "tsc --build",
"build:deps": "yarn workspace @greenlight/logger build && yarn workspace @greenlight/authentication build && yarn workspace @greenlight/storeapi build && yarn workspace @greenlight/xcloudapi build",
"build:deps": "yarn workspace @greenlight/logger build && yarn workspace @greenlight/authentication build && yarn workspace @greenlight/storeapi build && yarn workspace @greenlight/xcloudapi build && yarn workspace @greenlight/webapi build",
"clean": "rm -rf dist/ && rm -rf *.tsbuildinfo",
"test": "yarn build && mocha -r ../node_modules/ts-node/register tests/**.ts tests/**/*.ts"
},
Expand Down
5 changes: 5 additions & 0 deletions server/src/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class GreenlightServer {
return retItems
})

// Smartglass API
this._apiServer.getServer().get('/smartglass/consoles', async (request, reply) => {
return await this._server.controllers.Smartglass.getConsoles()
})

}


Expand Down
4 changes: 3 additions & 1 deletion server/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import UsersController from './users'
import GamepassController from './gamepass'
import SmartglassController from './smartglass'

export default {
Users: UsersController,
Gamepass: GamepassController
Gamepass: GamepassController,
Smartglass: SmartglassController,
}
28 changes: 28 additions & 0 deletions server/src/controllers/smartglass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Controller from './controller'
import WebApi from '@greenlight/webapi'

export default class SmartglassController extends Controller {

private _webApi:WebApi|undefined

async loadApis() {
if(this._webApi === undefined){
const token = await this.getServer().controllers.Users.getWebtoken()

this._webApi = new WebApi({
token: {
Token: token.data.Token,
NotAfter: token.data.NotAfter
},
uhs: this.getServer().controllers.Users.getUserHash()
})
}
}

async getConsoles() {
await this.loadApis()

return await this._webApi?.provider.smartglass.getConsolesList()
}

}
4 changes: 4 additions & 0 deletions server/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ export default class UsersController extends Controller {
async getxCloudtoken() {
return await this._auth.user.getxCloudToken()
}

getUserHash() {
return this._auth.user.getUserhash()
}
}
3 changes: 2 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class Server {

public controllers = {
Users: new Controllers.Users(this),
Gamepass: new Controllers.Gamepass(this)
Gamepass: new Controllers.Gamepass(this),
Smartglass: new Controllers.Smartglass(this)
}
}

0 comments on commit 4d1b886

Please sign in to comment.