fixed env script

+ fixed domain en port variable in svelte
This commit is contained in:
simplonco
2022-12-31 19:22:12 +01:00
parent 22ca9e9467
commit 0060f5daf7
23 changed files with 422 additions and 372 deletions

View File

@@ -1,4 +1,5 @@
<script context="module">
export const Domain = "transcendance";
export const Port = 8080;
export const Port = "8080";
export const PortIo = "8080";
</script>

View File

@@ -3,13 +3,13 @@
import { push } from "svelte-spa-router";
import { onMount } from 'svelte';
import { get } from "svelte/store";
import { Domain } from "../Constantes.svelte";
import { Domain, Port } from "../Constantes.svelte";
let user;
onMount(async () => {
user = await fetch('http://{Domain}:8080/api/v2/user')
user = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then((resp) => resp.json())
// i mean i could do a failed to load user or some shit, maybe with a .catch or something? but atm why bother
@@ -33,14 +33,14 @@
});
const login = async() => {
window.location.href = 'http://{Domain}:8080/api/v2/auth';
window.location.href = `http://${Domain}:${Port}/api/v2/auth`;
console.log('you are now logged in');
}
// i could prolly put this in it's own compoent, i seem to use it in several places... or maybe just some JS? like no need for html
// we could .then( () => replace('/') ) need the func so TS compatible...
const logout = async() => {
await fetch('http://{Domain}:8080/api/v2/auth/logout', {
await fetch(`http://${Domain}:${Port}/api/v2/auth/logout`, {
method: 'POST',
});
user = undefined;

View File

@@ -4,7 +4,7 @@
import { Domain, Port } from "../Constantes.svelte";
// onMount( async() => {
// await fetch("http://{Domain}:{Port}/api/v2/auth/2fa/generate",
// await fetch(`http://${Domain}:${Port}/api/v2/auth/2fa/generate`,
// {
// method: 'POST',
// })
@@ -20,7 +20,7 @@
let qrCode = "";
let wrongCode = "";
const fetchQrCodeImg = (async() => {
await fetch("http://{Domain}:{Port}/api/v2/auth/2fa/generate",
await fetch(`http://${Domain}:${Port}/api/v2/auth/2fa/generate`,
{
method: 'POST',
})
@@ -32,7 +32,7 @@
})()
const submitCode = async() => {
const response = await fetch("http://{Domain}:{Port}/api/v2/auth/2fa/check",
const response = await fetch(`http://${Domain}:${Port}/api/v2/auth/2fa/check`,
{
method : 'POST',
headers : {

View File

@@ -37,9 +37,9 @@
let idOfIntevalCheckTerminationOfTheMatch;
onMount( async() => {
user = await fetch('http://{Domain}:{Port}/api/v2/user')
user = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then( x => x.json() );
allUsers = await fetch('http://{Domain}:{Port}/api/v2/user/all')
allUsers = await fetch(`http://${Domain}:${Port}/api/v2/user/all`)
.then( x => x.json() );
options.playerOneUsername = user.username;
})
@@ -69,7 +69,7 @@
idOfIntevalCheckTerminationOfTheMatch = setInterval(matchTermitation, 1000);
const matchOptions = pong.computeMatchOptions(options);
const responseWhenGrantToken = fetch("http://{Domain}:{Port}/api/v2/game/ticket", {
const responseWhenGrantToken = fetch(`http://${Domain}:${Port}/api/v2/game/ticket`, {
method : "POST",
headers : {'Content-Type': 'application/json'},
body : JSON.stringify({
@@ -174,13 +174,13 @@
const showInvitation = async() => {
showGameOption = false;
showInvitations = true;
invitations = await fetch("http://{Domain}:{Port}/api/v2/game/invitations")
invitations = await fetch(`http://${Domain}:${Port}/api/v2/game/invitations`)
.then(x => x.json())
invitations.length !== 0 ? isThereAnyInvitation = true : isThereAnyInvitation = false
}
const rejectInvitation = async(invitation) => {
await fetch("http://{Domain}:{Port}/api/v2/game/decline",{
await fetch(`http://${Domain}:${Port}/api/v2/game/decline`, {
method: "POST",
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
@@ -193,7 +193,7 @@
}
const acceptInvitation = async(invitation : any) => {
const res = await fetch("http://{Domain}:{Port}/api/v2/game/accept",{
const res = await fetch(`http://${Domain}:${Port}/api/v2/game/accept`, {
method: "POST",
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({

View File

@@ -21,9 +21,9 @@
let hiddenGame = true;
onMount( async() => {
user = await fetch('http://{Domain}:{Port}/api/v2/user')
user = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then( x => x.json() );
allUsers = await fetch('http://{Domain}:{Port}/api/v2/user/all')
allUsers = await fetch(`http://${Domain}:${Port}/api/v2/user/all`)
.then( x => x.json() );
})

View File

@@ -9,9 +9,9 @@
let allUsers = [];
let idInterval;
onMount( async() => {
currentUser = await fetch('http://{Domain}:{Port}/api/v2/user')
currentUser = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then( x => x.json() );
allUsers = await fetch('http://{Domain}:{Port}/api/v2/game/ranking')
allUsers = await fetch(`http://${Domain}:${Port}/api/v2/game/ranking`)
.then( x => x.json() );
idInterval = setInterval(fetchScores, 10000);
})
@@ -21,7 +21,7 @@
})
function fetchScores() {
fetch('http://{Domain}:{Port}/api/v2/game/ranking')
fetch(`http://${Domain}:${Port}/api/v2/game/ranking`)
.then( x => x.json() )
.then( x => allUsers = x );
}

View File

@@ -10,7 +10,7 @@
onMount( async() => {
// console.log('mounting profile display')
user = await fetch('http://{Domain}:{Port}/api/v2/user')
user = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then( (x) => x.json() );
})

View File

@@ -39,7 +39,7 @@ could be a list of friends and if they're active but i can't see that yet
onMount( async() => {
// yea no idea what
// i mean do i fetch user? i will for now
user = await fetch('http://{Domain}:{Port}/api/v2/user')
user = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then( (x) => x.json() );
// userBeingViewed = user;
@@ -47,26 +47,26 @@ could be a list of friends and if they're active but i can't see that yet
// console.log(user)
// console.log(user.username)
myFriends = await fetch("http://{Domain}:{Port}/api/v2/network/myfriends")
myFriends = await fetch(`http://${Domain}:${Port}/api/v2/network/myfriends`)
.then( (x) => x.json() );
// console.log('my friends')
// console.log(myFriends)
requestsMade = await fetch('http://{Domain}:{Port}/api/v2/network/pending')
requestsMade = await fetch(`http://${Domain}:${Port}/api/v2/network/pending`)
.then( x => x.json() );
// console.log('Requests pending ');
// console.log(requestsMade);
requestsRecieved = await fetch('http://{Domain}:{Port}/api/v2/network/received')
requestsRecieved = await fetch(`http://${Domain}:${Port}/api/v2/network/received`)
.then( x => x.json() );
// console.log('Requests received ');
// console.log(requestsRecieved);
allUsers = await fetch('http://{Domain}:{Port}/api/v2/user/all')
allUsers = await fetch(`http://${Domain}:${Port}/api/v2/user/all`)
.then( x => x.json() );
// console.log('got all users ' + allUsers)
@@ -75,20 +75,20 @@ could be a list of friends and if they're active but i can't see that yet
const displayAllUsers = async() => {
allUsers = await fetch('http://{Domain}:{Port}/api/v2/user/all')
allUsers = await fetch(`http://${Domain}:${Port}/api/v2/user/all`)
.then( x => x.json() );
// console.log('got all users ' + allUsers)
};
const displayAllFriends = async() => {
myFriends = await fetch('http://{Domain}:{Port}/api/v2/network/myfriends')
myFriends = await fetch(`http://${Domain}:${Port}/api/v2/network/myfriends`)
.then( x => x.json() );
// console.log('got all friends ' + allFriends)
};
const displayRequestsMade = async() => {
requestsMade = await fetch('http://{Domain}:{Port}/api/v2/network/pending')
requestsMade = await fetch(`http://${Domain}:${Port}/api/v2/network/pending`)
.then( x => x.json() );
// console.log('got requests made ' + requestsMade)
};
@@ -107,7 +107,7 @@ could be a list of friends and if they're active but i can't see that yet
}
if (valid) {
sentFriendRequest = await fetch("http://{Domain}:{Port}/api/v2/network/myfriends", {
sentFriendRequest = await fetch(`http://${Domain}:${Port}/api/v2/network/myfriends`, {
method : "POST",
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
@@ -125,7 +125,7 @@ could be a list of friends and if they're active but i can't see that yet
// sendUsername = userBeingViewed.username;
// prolly like fetch if you're friends or not?
// GET http://{Domain}:{Port}/api/v2/networks/myfriends?username=aUser but i need to make that as long as Cherif
// GET `http://${Domain}:${Port}/api/v2/networks/myfriends?username=aUser` but i need to make that as long as Cherif
// doesn't have a better option
// like i want this thing to return the Friendship ID ideally
};

View File

@@ -17,7 +17,7 @@
let success = {username: '', avatar: '' };
onMount( async() => {
user = await fetch('http://{Domain}:{Port}/api/v2/user')
user = await fetch(`http://${Domain}:${Port}/api/v2/user`)
.then( (x) => x.json() );
// do a .catch?
@@ -34,7 +34,7 @@
// console.log('this is what is in the avatar before fetch')
// console.log(avatar)
await fetch("http://{Domain}:{Port}/api/v2/user/avatar", {method: "GET"})
await fetch(`http://${Domain}:${Port}/api/v2/user/avatar`, {method: "GET"})
.then(response => {return response.blob()})
.then(data => {
const url = URL.createObjectURL(data);
@@ -64,7 +64,7 @@
else {
errors.username = '';
}
await fetch('http://{Domain}:{Port}/api/v2/user',{
await fetch(`http://${Domain}:${Port}/api/v2/user`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
@@ -101,7 +101,7 @@
// tmp
console.log(data);
await fetch("http://{Domain}:{Port}/api/v2/user/avatar",
await fetch(`http://${Domain}:${Port}/api/v2/user/avatar`,
{
method : 'POST',
body : data,
@@ -109,7 +109,7 @@
.then(() => uploadAvatarSuccess = true ) // for some reason it needs to be a function, i think a TS thing, not a promis otherwise
.then(() => success.avatar = 'Your changes have been saved')
.catch(() => errors.avatar = 'Sorry failed to upload your new Avatar' );
await fetch("http://{Domain}:{Port}/api/v2/user/avatar", {method: "GET"})
await fetch(`http://${Domain}:${Port}/api/v2/user/avatar`, {method: "GET"})
.then(response => {return response.blob()})
.then(data => {
const url = URL.createObjectURL(data);

View File

@@ -10,8 +10,8 @@
onMount( async() => {
console.log('Display aUser username: '+ aUsername)
// http://{Domain}:{Port}/api/v2/user?username=NomDuUserATrouver
user = await fetch(`http://{Domain}:{Port}/api/v2/user?username=${aUsername}`)
//`http://${Domain}:${Port}/api/v2/user?username=NomDuUserATrouve`
user = await fetch(`http://${Domain}:${Port}/api/v2/user?username=${aUsername}`)
.then( (x) => x.json() );
// console.log('Display a user: ')
@@ -27,15 +27,15 @@
const updateUser = async(updatedUser) => {
console.log('Display Update aUser username: '+ updateUser)
// http://{Domain}:{Port}/api/v2/user?username=NomDuUserATrouver
user = await fetch(`http://{Domain}:{Port}/api/v2/user?username=${updateUser}`)
//`http://${Domain}:${Port}/api/v2/user?username=NomDuUserATrouve`
user = await fetch(`http://${Domain}:${Port}/api/v2/user?username=${updateUser}`)
.then( (x) => x.json() );
};
// export const updateUser = async(updatedUser) => {
// console.log('Display Update aUser username: '+ updateUser)
// // http://{Domain}:{Port}/api/v2/user?username=NomDuUserATrouver
// user = await fetch(`http://{Domain}:{Port}/api/v2/user?username=${updateUser}`)
// //`http://${Domain}:${Port}/api/v2/user?username=NomDuUserATrouve`
// user = await fetch(`http://${Domain}:${Port}/api/v2/user?username=${updateUser}`)
// .then( (x) => x.json() );
// updateGeneratedUser(updateUser);

View File

@@ -12,7 +12,7 @@
onMount( async() => {
// using this for now cuz for some reason there is yet to be a way to fet another person's avatar
if (primary) {
await fetch("http://{Domain}:{Port}/api/v2/user/avatar", {method: "GET"})
await fetch(`http://${Domain}:${Port}/api/v2/user/avatar`, {method: "GET"})
.then(response => {return response.blob()})
.then(data => {
const url = URL.createObjectURL(data);

View File

@@ -8,7 +8,7 @@
let handleClickLogout = async () => {
await fetch('http://{Domain}:{Port}/api/v2/auth/logout', {
await fetch(`http://${Domain}:${Port}/api/v2/auth/logout`, {
method: 'POST',
})
// .then(resp => resp.json)

View File

@@ -2,14 +2,14 @@
<script lang="ts">
import Layouts from './Chat_layouts.svelte';
import { Domain, Port } from "../Constantes.svelte";
import { Domain, PortIo } from "../../Constantes.svelte";
export let color = "transparent";
/* web sockets with socket.io
*/
import { onMount } from 'svelte';
import io from 'socket.io-client';
const socket = io('http://{Domain}:{Port}', {
const socket = io(`http://${Domain}:${PortIo}`, {
path: '/chat'
});
onMount(async => {