-
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 #1 from Andcool-Systems/Groups-dev
Groups dev
- Loading branch information
Showing
15 changed files
with
1,879 additions
and
378 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
/__pycache__ | ||
/dataBase.db | ||
/.env | ||
/tg | ||
/tg | ||
/out |
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,3 @@ | ||
[submodule "FileUploaderBot"] | ||
path = FileUploaderBot | ||
url = https://github.com/kwixie1/FileUploaderBot.git |
Submodule FileUploaderBot
added at
2c0f5d
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,213 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>File uploader</title> | ||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> | ||
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@800&family=Roboto+Mono&display=swap" rel="stylesheet"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/x-icon" href="https://fu.andcool.ru/favicon.ico"> | ||
</head> | ||
<style> | ||
body{ | ||
font-family: 'Roboto Mono', monospace; | ||
display: flex; | ||
justify-content: center; | ||
background-color: #222222; | ||
color: #eeeeee; | ||
height: 100%; | ||
overflow-x: hidden; | ||
} | ||
|
||
main{ | ||
width: 70%; | ||
text-align: left; | ||
} | ||
|
||
#main_div{ | ||
text-align: center; | ||
} | ||
#second_div{ | ||
display: flex; | ||
justify-content: center; | ||
} | ||
h1{ | ||
font-family: 'Roboto Mono', monospace; | ||
font-weight: 400; | ||
} | ||
|
||
pre{ | ||
font-family: 'Roboto Mono', monospace; | ||
font-weight: 400; | ||
font-size: 80%; | ||
text-align: left; | ||
} | ||
|
||
hr{ | ||
border: 1px solid rgb(105, 105, 105); | ||
} | ||
p{ | ||
font-size: 100%; | ||
} | ||
|
||
|
||
nav a{ | ||
cursor: pointer; | ||
color: white; | ||
text-decoration: none; | ||
} | ||
nav a:hover{ | ||
font-weight: 600; | ||
text-decoration: underline dashed; | ||
} | ||
|
||
#login_mess{ | ||
font-style: italic; | ||
} | ||
#join_butt{ | ||
font-family: 'Roboto Mono', monospace; | ||
background-color: #222222; | ||
border: 2px rgb(105, 105, 105) solid; | ||
border-radius: 10px; | ||
padding: 10px; | ||
color: white; | ||
cursor: pointer; | ||
transition: background-color 0.2s; | ||
font-size: 100%; | ||
} | ||
|
||
#join_butt:hover{ | ||
background-color: rgb(109, 109, 109); | ||
transition: background-color 0.2s; | ||
} | ||
|
||
@media(max-width: 425px){ | ||
main{width: 90%;} | ||
h1{font-size: 130%;} | ||
p{font-size: 90%;} | ||
pre{font-size: 50%;} | ||
} | ||
</style> | ||
<body> | ||
<main> | ||
<h1>File uploader</h1> | ||
<nav> | ||
<a href="https://fu.andcool.ru">Home</a> | ||
<a href="https://fu.andcool.ru/login/" id="login_page_a">Login</a> | ||
<a href="https://fu.andcool.ru/tos/">ToS</a> | ||
<a href="https://github.com/Andcool-Systems/File-uploader" target="_blank">GitHub</a> | ||
</nav> | ||
<hr> | ||
<div id="main_div"> | ||
<h1 id="invited_to" style="font-size: 130%;">Loading...</h1> | ||
<p id="error"></p> | ||
<button id="join_butt" onclick="join()">Join!</button> | ||
</div> | ||
</main> | ||
</body> | ||
|
||
<script> | ||
//let api_url = "http://127.0.0.1:8080"; //!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
let api_url = "https://fu.andcool.ru"; | ||
|
||
function moveToPage(page_url){ | ||
const protocol = window.location.protocol; | ||
const host = window.location.host; | ||
window.location.replace(protocol + "//" + host + page_url); | ||
} | ||
function parseJwt (token) { | ||
var base64Url = token.split('.')[1]; | ||
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); | ||
var jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function(c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}).join('')); | ||
|
||
return JSON.parse(jsonPayload); | ||
} | ||
|
||
function checkAccess(token) { | ||
var secondsSinceEpoch = Date.now() / 1000 | ||
res = parseJwt(token); | ||
|
||
return (parseInt(res["ExpiresAt"]) - 259200) > secondsSinceEpoch; | ||
} | ||
|
||
async function fetch_info(invite_link) { | ||
let accessToken = localStorage.getItem("accessToken"); | ||
if (!accessToken) moveToPage("/login"); | ||
if (!checkAccess(accessToken)) { | ||
let new_access = await get_new_tokens(accessToken); | ||
if (!new_access) { | ||
localStorage.removeItem("accessToken"); | ||
moveToPage("/login"); | ||
} | ||
accessToken = new_access; | ||
localStorage.setItem("accessToken", new_access); | ||
} | ||
try { | ||
let response = await axios.get(api_url + "/api/invite_info/" + invite_link, { | ||
headers: { | ||
'Authorization': 'Bearer ' + accessToken | ||
} | ||
}) | ||
if (!response) moveToPage("/login"); | ||
if (response.status == 200) { | ||
let h1 = document.getElementById("invited_to"); | ||
h1.innerHTML = `You have been invited to a "` + response.data.name + `" group!` | ||
|
||
let logim_page_btn = document.getElementById('login_page_a'); | ||
logim_page_btn.textContent = "Logout"; | ||
logim_page_btn.href = "/"; | ||
} | ||
} catch (e){ | ||
console.log(e); | ||
if (e.response && e.response.status == 401) { | ||
localStorage.removeItem("accessToken"); | ||
moveToPage("/login"); | ||
} | ||
if (e.response){ | ||
document.getElementById("invited_to").innerHTML = e.response.data.message; | ||
} | ||
} | ||
} | ||
|
||
async function join() { | ||
let accessToken = localStorage.getItem("accessToken"); | ||
if (!accessToken) moveToPage("/login"); | ||
if (!checkAccess(accessToken)) { | ||
let new_access = await get_new_tokens(accessToken); | ||
if (!new_access) { | ||
localStorage.removeItem("accessToken"); | ||
moveToPage("/login"); | ||
} | ||
accessToken = new_access; | ||
localStorage.setItem("accessToken", new_access); | ||
} | ||
try { | ||
let response = await axios.post(api_url + "/api/join/" + window.location.pathname.split('/')[2], {}, { | ||
headers: { | ||
'Authorization': 'Bearer ' + accessToken | ||
} | ||
}) | ||
if (!response) moveToPage("/login"); | ||
if (response.status == 200) { | ||
localStorage.setItem('prev_group', response.data.group_id); | ||
moveToPage("/"); | ||
} | ||
} catch (e){ | ||
console.log(e); | ||
if (e.response && e.response.status == 401) { | ||
localStorage.removeItem("accessToken"); | ||
moveToPage("/login"); | ||
} | ||
if (e.response){ | ||
document.getElementById("error").innerHTML = e.response.data.message; | ||
} | ||
} | ||
} | ||
addEventListener("DOMContentLoaded", (event) => { | ||
fetch_info(window.location.pathname.split('/')[2]); | ||
console.log(window.location.pathname.split('/')[2]) | ||
}) | ||
</script> | ||
</html> |
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,23 @@ | ||
from fastapi import FastAPI, UploadFile, Request, Header | ||
from fastapi.responses import JSONResponse, FileResponse, Response | ||
from typing import Annotated, Union | ||
import uvicorn | ||
from config import * | ||
import aiohttp | ||
import utils | ||
from slowapi.errors import RateLimitExceeded | ||
from slowapi import Limiter, _rate_limit_exceeded_handler | ||
from slowapi.util import get_remote_address | ||
from fastapi.middleware.cors import CORSMiddleware | ||
import time | ||
import aiofiles | ||
from prisma import Prisma | ||
import uuid | ||
import os | ||
from datetime import datetime | ||
from dotenv import load_dotenv | ||
import jwt | ||
import bcrypt | ||
import random | ||
|
||
rate_limit_exceeded_handler = _rate_limit_exceeded_handler |
Oops, something went wrong.