-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from TaloDev/develop
Release 0.55.0
- Loading branch information
Showing
29 changed files
with
549 additions
and
612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import SocketTicketAPIService from '../services/api/socket-ticket-api.service' | ||
import APIDocs from './api-docs' | ||
|
||
const SocketTicketAPIDocs: APIDocs<SocketTicketAPIService> = { | ||
post: { | ||
description: 'Create a socket ticket (expires after 5 minutes)', | ||
samples: [ | ||
{ | ||
title: 'Sample response', | ||
sample: { | ||
ticket: '6c6ef345-0ac3-4edc-a221-b807fbbac4ac' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
export default SocketTicketAPIDocs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Docs, Request, Response } from 'koa-clay' | ||
import APIService from './api-service' | ||
import { createRedisConnection } from '../../config/redis.config' | ||
import { v4 } from 'uuid' | ||
import Redis from 'ioredis' | ||
import APIKey from '../../entities/api-key' | ||
import SocketTicketAPIDocs from '../../docs/socket-tickets-api.docs' | ||
|
||
export async function createSocketTicket(redis: Redis, key: APIKey, devBuild: boolean): Promise<string> { | ||
const ticket = v4() | ||
const payload = `${key.id}:${devBuild ? '1' : '0'}` | ||
await redis.set(`socketTickets.${ticket}`, payload, 'EX', 300) | ||
|
||
return ticket | ||
} | ||
|
||
export default class SocketTicketAPIService extends APIService { | ||
@Docs(SocketTicketAPIDocs.post) | ||
async post(req: Request): Promise<Response> { | ||
const redis = createRedisConnection(req.ctx) | ||
|
||
const ticket = await createSocketTicket(redis, req.ctx.state.key, req.headers['x-talo-dev-build'] === '1') | ||
|
||
return { | ||
status: 200, | ||
body: { | ||
ticket | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Redis } from 'ioredis' | ||
import APIKey from '../entities/api-key' | ||
import { RequestContext } from '@mikro-orm/mysql' | ||
|
||
export default class SocketTicket { | ||
apiKey: APIKey | ||
devBuild: boolean | ||
|
||
constructor(private readonly ticket: string) { } | ||
|
||
async validate(redis: Redis): Promise<boolean> { | ||
const ticketValue = await redis.get(`socketTickets.${this.ticket}`) | ||
if (ticketValue) { | ||
await redis.del(`socketTickets.${this.ticket}`) | ||
const [keyId, devBuild] = ticketValue.split(':') | ||
|
||
try { | ||
this.devBuild = devBuild === '1' | ||
|
||
const em = RequestContext.getEntityManager() | ||
this.apiKey = await em.getRepository(APIKey).findOneOrFail({ | ||
id: Number(keyId), | ||
revokedAt: null | ||
}, { | ||
populate: ['game'] | ||
}) | ||
|
||
return true | ||
} catch (error) { | ||
return false | ||
} | ||
} | ||
return false | ||
} | ||
} |
Oops, something went wrong.