Skip to content

Commit

Permalink
Merge pull request #8 from MrLivixx/MrLivixx-patch-1
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Nikita committed Aug 15, 2021
2 parents 70baa98 + 6794011 commit 651c915
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: ['https://donate.mrlivixx.me']
25 changes: 25 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Backend tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
run-tests:
name: tests
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 13
- name: Install dependencies for backend
run: cd backend && npm i
- name: Run test
run: cd backend && npm run build
27 changes: 27 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Frontend tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
run-tests:
name: tests
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 13
- name: Install dependencies for frontend
run: cd frontend && npm i
- name: Run list
run: cd frontend && npm run lint
- name: Run build
run: cd frontend && npm run build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<br>`socket.io` - Обмен данными между Front-end и Back-end частями сайта.
<br>`fastify` - Используется в качестве веб-сервера в Back-end части.
<br>`mongoose` - Для использования базы данных MongoBD, хранения донатов и сессий
<br>`jsonwebtoken` - Используется для подписания токенов, [подробнее](https://jwt.io)
<br>`jsonwebtoken` - Используется для подписи токенов, [подробнее](https://jwt.io)
# Contributing
Мы приветствуем всех желающих которые хотят внести вклад в данный проект.
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ QIWI_SECRET_KEY=******
#QIWI THEME
QIWI_THEME=Nykyta-S0FqLeU_kv
```
###Коротко о том что за значения надо внести в .env
### Коротко о том что за значения надо внести в .env

- `DB_URL` - Ссылка на базу данных mongodb. Как создать базу данных можете прочитать в моём другом гайде [здесь](https://github.com/sqdsh/simple-discord-bot/blob/gh-pages/index.md#прочее)
- `PORT` - Порт веб сервера, для работы на своей VPS/VDS машине, использовать прокси как nginx и apache2. Если heroku/glitch оставить пустым
Expand Down
7 changes: 4 additions & 3 deletions backend/src/Servies/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import axios, {AxiosResponse} from "axios";
const hashes = new Map()
class DonationAlertsWatcher {
private io: Socket;
private db: Model<Donations>;
private tokens: Model<Tokens>
private db: Model<Donations | unknown>;
private tokens: Model<Tokens | unknown>

constructor(db: Model<Donations>, tokens: Model<Tokens>) {
constructor(db: Model<Donations | unknown>, tokens: Model<Tokens | unknown>) {
this.db = db;
this.tokens = tokens;
//@ts-ignore
Expand Down Expand Up @@ -47,6 +47,7 @@ class DonationAlertsWatcher {
}).then(x => x)
const response: AxiosResponse | null = await axios.get('https://discord.com/api/users/@me', {
headers: {
// @ts-ignore
authorization: `Bearer ${tokendata?.accessToken}`
}
}).catch(() => {
Expand Down
16 changes: 10 additions & 6 deletions backend/src/Servies/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import axios, {AxiosResponse} from "axios";
import { URLSearchParams } from "url";

class Oauth2 {
private db: Model<Tokens>;
constructor(db: Model<Tokens>) {
private db: Model<Tokens | unknown>;
constructor(db: Model<Tokens | unknown>) {
this.db = db;
}
async Discordlogin(req: FastifyRequest,res: FastifyReply) : Promise<void> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const code = req.query?.code;
const { code, error } = req.query;
if(error == "access_denied") return res.view('index.ejs', {
token: null
});
if(!code) return res.redirect('/oauth2/discord/authorize');
const response: AxiosResponse = await axios.post('https://discord.com/api/oauth2/token',
new URLSearchParams({
Expand Down Expand Up @@ -89,10 +92,11 @@ class Oauth2 {
const tokendata = await this.db.findOne({userid: data?.id.toString(),exp: data?.exp})
const response: AxiosResponse = await axios.get('https://discord.com/api/users/@me', {
headers: {
//@ts-ignore
authorization: `Bearer ${tokendata?.accessToken}`
}
})
if(!response.data.id) return res.send({code:404, message: "Not found"})
}).catch(() => {return res.status(500).send({code: 500, message: 'Internal server error'})});
if(!response.data?.id) return res.send({code:404, message: "Not found"})
res.status(200).send({type: 'discord', data: response.data})
}

Expand All @@ -101,4 +105,4 @@ class Oauth2 {
});
}
}
export default Oauth2;
export default Oauth2;
9 changes: 5 additions & 4 deletions backend/src/Servies/qiwi.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import QiwiBillPaymentsAPI from "@qiwi/bill-payments-node-js-sdk";
import { FastifyRequest, FastifyReply } from "fastify";
import axios, {AxiosError, AxiosResponse} from "axios";
import axios, { AxiosResponse } from "axios";
import { Model } from "mongoose";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import jwt from "jsonwebtoken";

class Qiwi {
private qiwi: QiwiBillPaymentsAPI;
private db: Model<Donations>;
private tokens: Model<Tokens>;
constructor(db: Model<Donations>, tokens: Model<Tokens>) {
private db: Model<Donations | unknown>;
private tokens: Model<Tokens | unknown>;
constructor(db: Model<Donations | unknown>, tokens: Model<Tokens | unknown>) {
this.qiwi = new QiwiBillPaymentsAPI(process.env.QIWI_SECRET_KEY!);
this.db = db;
this.tokens = tokens;
Expand Down Expand Up @@ -70,6 +70,7 @@ class Qiwi {
const tokendata = await this.tokens.findOne({userid: data?.id.toString(), exp: data?.exp})
const response: AxiosResponse = await axios.get('https://discord.com/api/users/@me',{
headers: {
//@ts-ignore
authorization: `Bearer ${tokendata?.accessToken}`
}
}).catch(() => {return res.status(403).send({code: 403, message: 'Forbidden'})});
Expand Down
5 changes: 4 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ class ApiWorker {
});

//DONATIONALERTS
if(process.env.DA_SECRET) await new DonationAlertsWatcher(donations, tokens).init()
if(process.env.DA_SECRET) { // @ts-ignore
await new DonationAlertsWatcher(donations, tokens).init()
}
//SOCKET.IO
this.io.on('connection', async (socket: Socket) => {
socket.send('Connected!');
console.log('Site connected!');
socket.on('donations',async () => {
//@ts-ignore
socket.emit('donations', await donations.find().sort({'time': 'desc'}).then((x: Model<Donations>) => x));
});
});
Expand Down
44 changes: 30 additions & 14 deletions frontend/public/aem_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/components/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a class="footer-sublink" href="tg://resolve?domain=livixx"><svg viewBox="0 0 448 512" class="svg-inline--fa fa-telegram-plane fa-w-14 fa-3x"><path fill="currentColor" d="M446.7 98.6l-67.6 318.8c-5.1 22.5-18.4 28.1-37.3 17.5l-103-75.9-49.7 47.8c-5.5 5.5-10.1 10.1-20.7 10.1l7.4-104.9 190.9-172.5c8.3-7.4-1.8-11.5-12.9-4.1L117.8 284 16.2 252.2c-22.1-6.9-22.5-22.1 4.6-32.7L418.2 66.4c18.4-6.9 34.5 4.1 28.5 32.2z"></path></svg> Telegram</a>
</div>
<div class="footer-link-last">
<div class="footer-text">Проект (soon): </div>
<div class="footer-text">Проект: </div>
<a class="footer-sublink" href="https://github.com/mrlivixx/donate-page"><svg viewBox="0 0 496 512" class="svg-inline--fa fa-github fa-w-16 fa-3x"><path fill="currentColor" d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z" class=""></path></svg> GitHub</a>
</div>
<div class="author">Designed by</div>
Expand Down Expand Up @@ -95,4 +95,4 @@

<script>
export default {}
</script>
</script>
13 changes: 8 additions & 5 deletions frontend/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ export default {
},
async CreateBill() {
if (!this.sum) return alert('Вы не указали сумму!');
if (!this.comment) return alert('Вы не указали комментарий!')
if (this.sum < 10) return alert('Минимальная сумма пополнения 10 руб.')
if (this.sum >= 15000) return alert('Максимальная сумма пополнения 10 руб.')
if (!this.comment) return alert('Вы не указали комментарий!');
if (this.sum < 10) return alert('Минимальная сумма пополнения 10 руб.');
if (this.sum >= 15000) return alert('Максимальная сумма пополнения 10 руб.');
if (this.comment.length >= 150) return alert('Максимальная длина коментария 150 символов.');
const data = await (await fetch(`https://${url}/qiwi/create`, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -245,7 +246,8 @@ export default {
if (typeof message !== 'object') return;
if (!message['data']) return;
if (!message.data['token']) return;
localStorage.setItem('token', JSON.parse(message.data.token));
if (JSON.parse(message.data.token)) localStorage.setItem('token', JSON.parse(message.data.token));
else return;
},
async getUserData() {
const info = await fetch('https://'+ url + '/oauth2/user', {
Expand All @@ -254,6 +256,7 @@ export default {
'Authorization': localStorage.getItem('token')
}
});
if(info.status !== 200) return this.logout();
const { data, type } = await info?.json();
if (!type) return;
this.user = data;
Expand All @@ -271,4 +274,4 @@ export default {
}
}
}
</script>
</script>

0 comments on commit 651c915

Please sign in to comment.