-
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.
Signed-off-by: Igor Sachivka <juicy.igor@gmail.com>
- Loading branch information
Showing
19 changed files
with
248 additions
and
605 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,12 +1,48 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { endPoints } from '../../helpers/endPoints.ts'; | ||
import { useToken } from '../auth/TokenStorage.tsx'; | ||
|
||
type RowProps = { | ||
telegramId: number; | ||
id: number; | ||
token: string; | ||
comment: string; | ||
users: { userId: number }[]; | ||
removeKey: (id: number) => void; | ||
}; | ||
|
||
export const Row = (props: RowProps) => { | ||
const { storage } = useToken(); | ||
const { token: authToken } = storage; | ||
const { token, comment, users, id, removeKey } = props; | ||
const onClickReject = useCallback(async () => { | ||
try { | ||
const response = await fetch(endPoints.rejectToken, { | ||
method: 'DELETE', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
body: JSON.stringify({ id }), | ||
}); | ||
const json = await response.json(); | ||
removeKey(id); | ||
console.log(json); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, [id]); | ||
|
||
return ( | ||
<tr> | ||
<td>{props.telegramId}</td> | ||
<td>{props.token}</td> | ||
<td> | ||
<button onClick={onClickReject}>reject</button> | ||
</td> | ||
<td> | ||
<pre>{token || '********'}</pre> | ||
</td> | ||
<td>{comment}</td> | ||
<td>{users.map((user) => user.userId).join(', ')}</td> | ||
</tr> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
const baseApi = import.meta.env.VITE_BASE_API | ||
? import.meta.env.VITE_BASE_API | ||
: ""; | ||
: ''; | ||
|
||
export const endPoints = { | ||
health: `${baseApi}/api/v1/health`, | ||
keys: `${baseApi}/api/v1/keys`, | ||
addToken: `${baseApi}/api/v1/addToken`, | ||
rejectToken: `${baseApi}/api/v1/rejectToken`, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "gpt", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
|
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 |
---|---|---|
@@ -1,22 +1,52 @@ | ||
import express from 'express'; | ||
|
||
import type { UsersStorage } from '../bot/user/usersStorage'; | ||
import db from '../db'; | ||
|
||
const routes = express.Router(); | ||
export const getHandlers = (usersStorage: UsersStorage) => { | ||
const routes = express.Router(); | ||
|
||
routes.get('/api/v1/health', (req, res) => { | ||
res.status(200).send({ status: 'OK' }); | ||
}); | ||
routes.get('/api/v1/health', (req, res) => { | ||
res.status(200).send({ status: 'OK' }); | ||
}); | ||
|
||
routes.get('/api/v1/keys', async (req, res) => { | ||
const keys = await db.Key.findAll(); | ||
res.send(keys); | ||
}); | ||
routes.get('/api/v1/keys', async (req, res) => { | ||
const keys = await db.Key.findAll({ include: db.User }); | ||
res.send( | ||
keys.map((key) => ({ | ||
id: key.id, | ||
comment: key.comment, | ||
users: key.users, | ||
})) | ||
); | ||
}); | ||
|
||
routes.post('/api/v1/addToken', async (req, res) => { | ||
const { token, telegramId } = req.body; | ||
const key = await db.Key.create({ token, telegramId }); | ||
res.send(key); | ||
}); | ||
routes.post('/api/v1/addToken', async (req, res) => { | ||
const { token, comment } = req.body; | ||
const key = await db.Key.create({ token, comment }); | ||
res.send({ | ||
id: key.id, | ||
comment: key.comment, | ||
users: key.users, | ||
}); | ||
}); | ||
|
||
export default routes; | ||
routes.delete('/api/v1/rejectToken', async (req, res) => { | ||
const { id } = req.body; | ||
const key = await db.Key.findOne({ where: { id }, include: db.User }); | ||
await Promise.all( | ||
key.users!.map((user) => { | ||
return usersStorage.get(user.id).then((memoryUser) => { | ||
memoryUser.unauthorize(); | ||
return user.update({ auth: false }); | ||
}); | ||
}) | ||
); | ||
await key.destroy(); | ||
res.send({ | ||
ok: true, | ||
}); | ||
}); | ||
|
||
return routes; | ||
}; |
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
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
Oops, something went wrong.