-
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.
- Loading branch information
1 parent
0a5bf6c
commit e02b11a
Showing
6 changed files
with
520 additions
and
21 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 |
---|---|---|
@@ -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> |
Oops, something went wrong.