fixed pbm in room name check

This commit is contained in:
simplonco
2023-01-10 10:32:46 +01:00
parent 89ffe9d4a3
commit 223599542b
4 changed files with 276 additions and 236 deletions

View File

@@ -7,6 +7,7 @@ import { PartialUsersDto } from 'src/users/dto/partial-users.dto';
import { createRoomDto } from './dto/createRoom.dto';
import { joinRoomDto } from './dto/joinRoom.dto';
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
import { ChatGateway } from './chat.gateway';
@Controller('chat')
export class ChatController {
@@ -15,6 +16,7 @@ export class ChatController {
constructor(
private chatService: ChatService,
private chatGateway: ChatGateway,
)
{
this.allowed_chars = "#!?-_";
@@ -71,9 +73,13 @@ export class ChatController {
{
console.log("- in createRoom controller");
let regex = new RegExp("^[a-zA-Z0-9\\s" + this.allowed_chars + "]+$/");
if (!regex.test(createRoomDto.room_name))
throw new HttpException(`Onlly special characters accepted in room name: ${this.allowed_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
let regex_base = `[a-zA-Z0-9\\s${this.allowed_chars}]`;
let test_regex = new RegExp(`^${regex_base}+$`);
if (test_regex.test(createRoomDto.room_name) === false)
{
let forbidden_chars = createRoomDto.room_name.replace(new RegExp(regex_base, "g"), "");
throw new HttpException(`Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
}
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
console.log("- out createRoom controller");
@@ -88,6 +94,9 @@ export class ChatController {
console.log("- in joinRoom controller");
console.log("-- room_name", joinRoomDto.room_name);
const response = await this.chatService.addUserToRoom(req.user.username, joinRoomDto.room_name);
//this.chatGateway.joinRoom(null, joinRoomDto.room_name);
console.log("- out joinRoom controller");
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
}

View File

@@ -2531,7 +2531,7 @@ var app = (function () {
validate_slots('Header', slots, []);
let handleClickLogout = async () => {
await fetch(`http://${'localhost'}:${'8080'}/api/v2/auth/logout`, { method: 'POST' }).then(() => push('/'));
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/auth/logout`, { method: 'POST' }).then(() => push('/'));
console.log('clicked logout header');
};
@@ -2898,7 +2898,7 @@ var app = (function () {
onMount(async () => {
// console.log('Generate User Display, on mount ' + user.username)
if (primary) {
await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/avatar`, { method: "GET" }).then(response => {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/avatar`, { method: "GET" }).then(response => {
return response.blob();
}).then(data => {
const url = URL.createObjectURL(data);
@@ -2906,7 +2906,7 @@ var app = (function () {
}).catch(() => $$invalidate(3, errors.avatar = 'Sorry your avatar could not be loaded', errors));
} else // console.log(avatar)
{
await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/avatar?username=${user.username}`, {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/avatar?username=${user.username}`, {
method: "GET", // console.log('avatar: ')
}).then(response => {
@@ -3853,44 +3853,56 @@ var app = (function () {
}
}
async function get_room_messages() {
async function get_room_messages()
{
console.log("in get_room_messages");
const response = await fetch('/api/v2/chat/messages');
const data = await response.json();
const messages = data.messages;
messages.forEach(function (item) {
messages.forEach(function(item) {
if (item.name === user.username) {
item.name = "me";
}
});
msgs.set(messages);
}
async function create_room(room_name, room_type) {
async function create_room(room_name, room_type)
{
console.log("in create_room");
let form_data = {
room_name: room_name,
room_type: room_type,
};
// send the new room
const response = await fetch('/api/v2/chat/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(form_data),
});
// get response status and message
let response_status = response.status;
let data = await response.json();
let response_message = "";
if (data.message)
response_message = data.message;
return {
status: response_status,
message: response_message
};
}
async function join_room(room_name) {
async function join_room(room_name)
{
console.log("in join_room");
console.log(room_name);
let name = {
room_name: room_name,
};
@@ -3901,10 +3913,14 @@ var app = (function () {
});
let data = await response.json();
console.log(data.message);
socket$1.emit('join', room_name);
}
async function change_room(room_name) {
async function change_room(room_name)
{
console.log("in change_room");
let room_name_request = {
room_name: room_name,
};
@@ -3915,47 +3931,68 @@ var app = (function () {
});
let data = await response.json();
console.log(data.message);
await get_room_messages();
socket$1.emit('change', room_name);
current_room_name.set(room_name);
layout.set("room");
}
async function get_my_rooms() {
async function get_my_rooms()
{
console.log("in get_my_rooms");
const response = await fetch('/api/v2/chat/myrooms');
const data = await response.json();
console.log("data.rooms:", data.rooms);
for (let room of data.rooms)
console.log(room.name);
let rooms = data.rooms;
return rooms;
}
async function get_all_rooms() {
async function get_all_rooms()
{
console.log("in get_all_rooms");
const response = await fetch('/api/v2/chat/allrooms');
const data = await response.json();
console.log("data.rooms:", data.rooms);
for (let room of data.rooms)
console.log(room.name);
let rooms = data.rooms;
return rooms;
}
async function get_room_users() {
async function get_room_users()
{
console.log("in get_room_users");
const response = await fetch('/api/v2/chat/roomusers');
const data = await response.json();
console.log("data.users:", data.users);
for (let user of data.users)
console.log(user.username);
let users = data.users;
return users;
}
async function user_leave_room() {
async function user_leave_room()
{
console.log("in leave_room");
const response = await fetch('/api/v2/chat/removeuser', {
method: 'DELETE',
});
const data = await response.json();
console.log("data", data);
}
@@ -7367,7 +7404,7 @@ var app = (function () {
let current;
warning = new Element_warning({
props: { content: /*response*/ ctx[6].message },
props: { content: /*response*/ ctx[5].message },
$$inline: true
});
@@ -7381,7 +7418,7 @@ var app = (function () {
},
p: function update(ctx, dirty) {
const warning_changes = {};
if (dirty & /*response*/ 64) warning_changes.content = /*response*/ ctx[6].message;
if (dirty & /*response*/ 32) warning_changes.content = /*response*/ ctx[5].message;
warning.$set(warning_changes);
},
i: function intro(local) {
@@ -7409,7 +7446,7 @@ var app = (function () {
return block;
}
// (77:3) {#if room_type === 'protected'}
// (80:3) {#if room_type === 'protected'}
function create_if_block$b(ctx) {
let div;
let label;
@@ -7428,10 +7465,10 @@ var app = (function () {
t1 = space();
input = element("input");
attr_dev(p, "class", "svelte-1ulnmwp");
add_location(p, file$i, 78, 28, 2417);
add_location(p, file$i, 81, 28, 2570);
attr_dev(label, "for", "chat_pswd");
attr_dev(label, "class", "svelte-1ulnmwp");
add_location(label, file$i, 78, 5, 2394);
add_location(label, file$i, 81, 5, 2547);
attr_dev(input, "id", "chat_pswd");
attr_dev(input, "type", "password");
attr_dev(input, "placeholder", "minimum 8 characters");
@@ -7439,9 +7476,9 @@ var app = (function () {
attr_dev(input, "name", "password");
input.required = true;
attr_dev(input, "class", "svelte-1ulnmwp");
add_location(input, file$i, 79, 5, 2457);
add_location(input, file$i, 82, 5, 2610);
attr_dev(div, "class", "svelte-1ulnmwp");
add_location(div, file$i, 77, 4, 2383);
add_location(div, file$i, 80, 4, 2536);
},
m: function mount(target, anchor) {
insert_dev(target, div, anchor);
@@ -7449,16 +7486,16 @@ var app = (function () {
append_dev(label, p);
append_dev(div, t1);
append_dev(div, input);
set_input_value(input, /*room_password*/ ctx[5]);
set_input_value(input, /*room_password*/ ctx[4]);
if (!mounted) {
dispose = listen_dev(input, "input", /*input_input_handler*/ ctx[13]);
dispose = listen_dev(input, "input", /*input_input_handler*/ ctx[12]);
mounted = true;
}
},
p: function update(ctx, dirty) {
if (dirty & /*room_password*/ 32 && input.value !== /*room_password*/ ctx[5]) {
set_input_value(input, /*room_password*/ ctx[5]);
if (dirty & /*room_password*/ 16 && input.value !== /*room_password*/ ctx[4]) {
set_input_value(input, /*room_password*/ ctx[4]);
}
},
d: function destroy(detaching) {
@@ -7472,7 +7509,7 @@ var app = (function () {
block,
id: create_if_block$b.name,
type: "if",
source: "(77:3) {#if room_type === 'protected'}",
source: "(80:3) {#if room_type === 'protected'}",
ctx
});
@@ -7547,8 +7584,8 @@ var app = (function () {
$$inline: true
});
let if_block0 = /*response*/ ctx[6].status >= 300 && create_if_block_1$5(ctx);
let if_block1 = /*room_type*/ ctx[4] === 'protected' && create_if_block$b(ctx);
let if_block0 = /*response*/ ctx[5].status >= 300 && create_if_block_1$5(ctx);
let if_block1 = /*room_type*/ ctx[3] === 'protected' && create_if_block$b(ctx);
const block = {
c: function create() {
@@ -7591,19 +7628,18 @@ var app = (function () {
t16 = space();
input4 = element("input");
attr_dev(p0, "class", "svelte-1ulnmwp");
add_location(p0, file$i, 58, 26, 1496);
add_location(p0, file$i, 58, 26, 1500);
attr_dev(label0, "for", "chat_name");
attr_dev(label0, "class", "svelte-1ulnmwp");
add_location(label0, file$i, 58, 3, 1473);
add_location(label0, file$i, 58, 3, 1477);
attr_dev(input0, "id", "chat_name");
attr_dev(input0, "name", "room_name");
attr_dev(input0, "placeholder", input0_placeholder_value = "allowed special characters: " + /*allowed_chars*/ ctx[1]);
attr_dev(input0, "pattern", /*regex*/ ctx[2]);
input0.required = true;
attr_dev(input0, "class", "svelte-1ulnmwp");
add_location(input0, file$i, 59, 3, 1530);
add_location(input0, file$i, 62, 3, 1699);
attr_dev(p1, "class", "svelte-1ulnmwp");
add_location(p1, file$i, 62, 4, 1747);
add_location(p1, file$i, 65, 4, 1900);
attr_dev(input1, "id", "chat_public");
attr_dev(input1, "type", "radio");
attr_dev(input1, "name", "room_type");
@@ -7611,13 +7647,13 @@ var app = (function () {
input1.value = input1.__value;
input1.required = true;
attr_dev(input1, "class", "svelte-1ulnmwp");
/*$$binding_groups*/ ctx[10][0].push(input1);
add_location(input1, file$i, 63, 4, 1765);
/*$$binding_groups*/ ctx[9][0].push(input1);
add_location(input1, file$i, 66, 4, 1918);
attr_dev(label1, "for", "chat_public");
attr_dev(label1, "class", "_radio svelte-1ulnmwp");
add_location(label1, file$i, 61, 3, 1702);
add_location(label1, file$i, 64, 3, 1855);
attr_dev(p2, "class", "svelte-1ulnmwp");
add_location(p2, file$i, 67, 4, 1958);
add_location(p2, file$i, 70, 4, 2111);
attr_dev(input2, "id", "chat_private");
attr_dev(input2, "type", "radio");
attr_dev(input2, "name", "room_type");
@@ -7625,13 +7661,13 @@ var app = (function () {
input2.value = input2.__value;
input2.required = true;
attr_dev(input2, "class", "svelte-1ulnmwp");
/*$$binding_groups*/ ctx[10][0].push(input2);
add_location(input2, file$i, 68, 4, 1977);
/*$$binding_groups*/ ctx[9][0].push(input2);
add_location(input2, file$i, 71, 4, 2130);
attr_dev(label2, "for", "chat_private");
attr_dev(label2, "class", "_radio hide svelte-1ulnmwp");
add_location(label2, file$i, 66, 3, 1907);
add_location(label2, file$i, 69, 3, 2060);
attr_dev(p3, "class", "svelte-1ulnmwp");
add_location(p3, file$i, 72, 4, 2176);
add_location(p3, file$i, 75, 4, 2329);
attr_dev(input3, "id", "chat_protected");
attr_dev(input3, "type", "radio");
attr_dev(input3, "name", "room_type");
@@ -7639,21 +7675,21 @@ var app = (function () {
input3.value = input3.__value;
input3.required = true;
attr_dev(input3, "class", "svelte-1ulnmwp");
/*$$binding_groups*/ ctx[10][0].push(input3);
add_location(input3, file$i, 73, 4, 2197);
/*$$binding_groups*/ ctx[9][0].push(input3);
add_location(input3, file$i, 76, 4, 2350);
attr_dev(label3, "for", "chat_protected");
attr_dev(label3, "class", "_radio hide svelte-1ulnmwp");
add_location(label3, file$i, 71, 3, 2123);
add_location(label3, file$i, 74, 3, 2276);
attr_dev(input4, "type", "submit");
input4.value = "⮡";
attr_dev(input4, "class", "svelte-1ulnmwp");
add_location(input4, file$i, 82, 3, 2621);
add_location(input4, file$i, 85, 3, 2774);
attr_dev(form, "class", "svelte-1ulnmwp");
add_location(form, file$i, 53, 2, 1322);
add_location(form, file$i, 53, 2, 1326);
attr_dev(div0, "class", "panel panel_create __border_top svelte-1ulnmwp");
add_location(div0, file$i, 52, 1, 1274);
add_location(div0, file$i, 52, 1, 1278);
attr_dev(div1, "class", "grid_box svelte-1ulnmwp");
add_location(div1, file$i, 34, 0, 953);
add_location(div1, file$i, 34, 0, 957);
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -7674,25 +7710,25 @@ var app = (function () {
append_dev(label0, p0);
append_dev(form, t5);
append_dev(form, input0);
set_input_value(input0, /*room_name*/ ctx[3]);
set_input_value(input0, /*room_name*/ ctx[2]);
append_dev(form, t6);
append_dev(form, label1);
append_dev(label1, p1);
append_dev(label1, t8);
append_dev(label1, input1);
input1.checked = input1.__value === /*room_type*/ ctx[4];
input1.checked = input1.__value === /*room_type*/ ctx[3];
append_dev(form, t9);
append_dev(form, label2);
append_dev(label2, p2);
append_dev(label2, t11);
append_dev(label2, input2);
input2.checked = input2.__value === /*room_type*/ ctx[4];
input2.checked = input2.__value === /*room_type*/ ctx[3];
append_dev(form, t12);
append_dev(form, label3);
append_dev(label3, p3);
append_dev(label3, t14);
append_dev(label3, input3);
input3.checked = input3.__value === /*room_type*/ ctx[4];
input3.checked = input3.__value === /*room_type*/ ctx[3];
append_dev(form, t15);
if (if_block1) if_block1.m(form, null);
append_dev(form, t16);
@@ -7701,11 +7737,11 @@ var app = (function () {
if (!mounted) {
dispose = [
listen_dev(input0, "input", /*input0_input_handler*/ ctx[8]),
listen_dev(input1, "change", /*input1_change_handler*/ ctx[9]),
listen_dev(input2, "change", /*input2_change_handler*/ ctx[11]),
listen_dev(input3, "change", /*input3_change_handler*/ ctx[12]),
listen_dev(form, "submit", prevent_default(/*handleSubmit*/ ctx[7]), false, true, false)
listen_dev(input0, "input", /*input0_input_handler*/ ctx[7]),
listen_dev(input1, "change", /*input1_change_handler*/ ctx[8]),
listen_dev(input2, "change", /*input2_change_handler*/ ctx[10]),
listen_dev(input3, "change", /*input3_change_handler*/ ctx[11]),
listen_dev(form, "submit", prevent_default(/*handleSubmit*/ ctx[6]), false, true, false)
];
mounted = true;
@@ -7716,31 +7752,31 @@ var app = (function () {
if (dirty & /*back*/ 1) button0_changes.new_layout = /*back*/ ctx[0];
if (dirty & /*back*/ 1) button0_changes.my_title = "go back " + /*back*/ ctx[0];
if (dirty & /*$$scope*/ 16384) {
if (dirty & /*$$scope*/ 8192) {
button0_changes.$$scope = { dirty, ctx };
}
button0.$set(button0_changes);
const button1_changes = {};
if (dirty & /*$$scope*/ 16384) {
if (dirty & /*$$scope*/ 8192) {
button1_changes.$$scope = { dirty, ctx };
}
button1.$set(button1_changes);
const button2_changes = {};
if (dirty & /*$$scope*/ 16384) {
if (dirty & /*$$scope*/ 8192) {
button2_changes.$$scope = { dirty, ctx };
}
button2.$set(button2_changes);
if (/*response*/ ctx[6].status >= 300) {
if (/*response*/ ctx[5].status >= 300) {
if (if_block0) {
if_block0.p(ctx, dirty);
if (dirty & /*response*/ 64) {
if (dirty & /*response*/ 32) {
transition_in(if_block0, 1);
}
} else {
@@ -7763,27 +7799,23 @@ var app = (function () {
attr_dev(input0, "placeholder", input0_placeholder_value);
}
if (!current || dirty & /*regex*/ 4) {
attr_dev(input0, "pattern", /*regex*/ ctx[2]);
if (dirty & /*room_name*/ 4 && input0.value !== /*room_name*/ ctx[2]) {
set_input_value(input0, /*room_name*/ ctx[2]);
}
if (dirty & /*room_name*/ 8 && input0.value !== /*room_name*/ ctx[3]) {
set_input_value(input0, /*room_name*/ ctx[3]);
if (dirty & /*room_type*/ 8) {
input1.checked = input1.__value === /*room_type*/ ctx[3];
}
if (dirty & /*room_type*/ 16) {
input1.checked = input1.__value === /*room_type*/ ctx[4];
if (dirty & /*room_type*/ 8) {
input2.checked = input2.__value === /*room_type*/ ctx[3];
}
if (dirty & /*room_type*/ 16) {
input2.checked = input2.__value === /*room_type*/ ctx[4];
if (dirty & /*room_type*/ 8) {
input3.checked = input3.__value === /*room_type*/ ctx[3];
}
if (dirty & /*room_type*/ 16) {
input3.checked = input3.__value === /*room_type*/ ctx[4];
}
if (/*room_type*/ ctx[4] === 'protected') {
if (/*room_type*/ ctx[3] === 'protected') {
if (if_block1) {
if_block1.p(ctx, dirty);
} else {
@@ -7817,9 +7849,9 @@ var app = (function () {
destroy_component(button1);
destroy_component(button2);
if (if_block0) if_block0.d();
/*$$binding_groups*/ ctx[10][0].splice(/*$$binding_groups*/ ctx[10][0].indexOf(input1), 1);
/*$$binding_groups*/ ctx[10][0].splice(/*$$binding_groups*/ ctx[10][0].indexOf(input2), 1);
/*$$binding_groups*/ ctx[10][0].splice(/*$$binding_groups*/ ctx[10][0].indexOf(input3), 1);
/*$$binding_groups*/ ctx[9][0].splice(/*$$binding_groups*/ ctx[9][0].indexOf(input1), 1);
/*$$binding_groups*/ ctx[9][0].splice(/*$$binding_groups*/ ctx[9][0].indexOf(input2), 1);
/*$$binding_groups*/ ctx[9][0].splice(/*$$binding_groups*/ ctx[9][0].indexOf(input3), 1);
if (if_block1) if_block1.d();
mounted = false;
run_all(dispose);
@@ -7842,15 +7874,14 @@ var app = (function () {
validate_slots('Layout_create', slots, []);
let { back = "" } = $$props;
let allowed_chars = 'loading...';
let regex;
//let regex;
onMount(async () => {
let response = await fetch('/api/v2/chat/allowedchars');
let data = await response.json();
console.log("data:", data);
$$invalidate(1, allowed_chars = data.chars);
$$invalidate(2, regex = new RegExp(`^[a-zA-Z0-9\\s${allowed_chars}]+$`));
});
}); //regex = new RegExp(`^[a-zA-Z0-9\\s${allowed_chars}]+$`);
let room_name;
let room_type;
@@ -7862,7 +7893,7 @@ var app = (function () {
if (!formIsValid) return;
// send the new room
$$invalidate(6, response = await create_room(room_name, room_type));
$$invalidate(5, response = await create_room(room_name, room_type));
// go to room
if (response.status === 200) await change_room(room_name);
@@ -7878,27 +7909,27 @@ var app = (function () {
function input0_input_handler() {
room_name = this.value;
$$invalidate(3, room_name);
$$invalidate(2, room_name);
}
function input1_change_handler() {
room_type = this.__value;
$$invalidate(4, room_type);
$$invalidate(3, room_type);
}
function input2_change_handler() {
room_type = this.__value;
$$invalidate(4, room_type);
$$invalidate(3, room_type);
}
function input3_change_handler() {
room_type = this.__value;
$$invalidate(4, room_type);
$$invalidate(3, room_type);
}
function input_input_handler() {
room_password = this.value;
$$invalidate(5, room_password);
$$invalidate(4, room_password);
}
$$self.$$set = $$props => {
@@ -7913,7 +7944,6 @@ var app = (function () {
Warning: Element_warning,
back,
allowed_chars,
regex,
room_name,
room_type,
room_password,
@@ -7924,11 +7954,10 @@ var app = (function () {
$$self.$inject_state = $$props => {
if ('back' in $$props) $$invalidate(0, back = $$props.back);
if ('allowed_chars' in $$props) $$invalidate(1, allowed_chars = $$props.allowed_chars);
if ('regex' in $$props) $$invalidate(2, regex = $$props.regex);
if ('room_name' in $$props) $$invalidate(3, room_name = $$props.room_name);
if ('room_type' in $$props) $$invalidate(4, room_type = $$props.room_type);
if ('room_password' in $$props) $$invalidate(5, room_password = $$props.room_password);
if ('response' in $$props) $$invalidate(6, response = $$props.response);
if ('room_name' in $$props) $$invalidate(2, room_name = $$props.room_name);
if ('room_type' in $$props) $$invalidate(3, room_type = $$props.room_type);
if ('room_password' in $$props) $$invalidate(4, room_password = $$props.room_password);
if ('response' in $$props) $$invalidate(5, response = $$props.response);
};
if ($$props && "$$inject" in $$props) {
@@ -7938,7 +7967,6 @@ var app = (function () {
return [
back,
allowed_chars,
regex,
room_name,
room_type,
room_password,
@@ -14186,7 +14214,7 @@ var app = (function () {
});
}
const address = `http://${'localhost'}:${'8080'}`;
const address = `http://${'transcendance'}:${'8080'}`;
async function init_socket() {
const response = await fetch(`${address}/api/v2/user`);
const response_data = await response.json();
@@ -14515,7 +14543,7 @@ var app = (function () {
onMount(async () => {
// console.log('mounting profile display')
$$invalidate(0, user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(x => x.json()));
$$invalidate(0, user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`).then(x => x.json()));
});
const writable_props = [];
@@ -15348,7 +15376,7 @@ var app = (function () {
let success = { username: '', avatar: '' };
onMount(async () => {
user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(x => x.json());
user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`).then(x => x.json());
// do a .catch?
if (user === undefined) {
@@ -15364,7 +15392,7 @@ var app = (function () {
// tmp
// console.log('this is what is in the avatar before fetch')
// console.log(avatar)
await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/avatar`, { method: "GET" }).then(response => {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/avatar`, { method: "GET" }).then(response => {
return response.blob();
}).then(data => {
const url = URL.createObjectURL(data);
@@ -15389,7 +15417,7 @@ var app = (function () {
$$invalidate(4, errors.username = '', errors);
}
await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`, {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -15416,7 +15444,7 @@ var app = (function () {
// tmp
console.log(data);
const responseWhenChangeAvatar = fetch(`http://${'localhost'}:${'8080'}/api/v2/user/avatar`, { method: 'POST', body: data });
const responseWhenChangeAvatar = fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/avatar`, { method: 'POST', body: data });
const responseFromServer = await responseWhenChangeAvatar;
if (responseFromServer.ok === true) {
@@ -15426,7 +15454,7 @@ var app = (function () {
$$invalidate(4, errors.avatar = responseFromServer.statusText, errors);
}
await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/avatar`, { method: "GET" }).then(response => {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/avatar`, { method: "GET" }).then(response => {
return response.blob();
}).then(data => {
const url = URL.createObjectURL(data);
@@ -15708,15 +15736,15 @@ var app = (function () {
onMount(async () => {
console.log('Display aUser username: ' + aUsername);
//`http://${'localhost'}:${'8080'}/api/v2/user?username=NomDuUserATrouve`
$$invalidate(1, user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user?username=${aUsername}`).then(x => x.json()));
//`http://${'transcendance'}:${'8080'}/api/v2/user?username=NomDuUserATrouve`
$$invalidate(1, user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user?username=${aUsername}`).then(x => x.json()));
});
const updateUser = async () => {
// console.log('Display Update aUser username: '+ aUsername)
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
$$invalidate(1, user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user?username=${aUsername}`).then(x => x.json()));
$$invalidate(1, user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user?username=${aUsername}`).then(x => x.json()));
};
$$self.$$.on_mount.push(function () {
@@ -18417,7 +18445,7 @@ var app = (function () {
// ALSO I COULD JUST USE THE FUNCITONS I MADE...
// yea no idea what
// i mean do i fetch user? i will for now
$$invalidate(0, user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(x => x.json()));
$$invalidate(0, user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`).then(x => x.json()));
fetchAll();
}); // ok this shit works!
@@ -18438,7 +18466,7 @@ var app = (function () {
/***** Fetch basic things *****/
const fetchAllUsers = async () => {
$$invalidate(1, allUsers = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/all`).then(x => x.json()));
$$invalidate(1, allUsers = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/all`).then(x => x.json()));
console.log('got all users ');
console.log(Object.assign({}, allUsers));
};
@@ -18446,25 +18474,25 @@ var app = (function () {
// it's more like fetch friendships
// then i need to extract the users
const fetchMyFriendships = async () => {
$$invalidate(2, myFriendships = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/myfriends`).then(x => x.json()));
$$invalidate(2, myFriendships = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/myfriends`).then(x => x.json()));
console.log('got my friends ');
console.log(Object.assign({}, myFriendships));
};
const fetchRequestsMade = async () => {
requestsMade = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/pending`).then(x => x.json());
requestsMade = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/pending`).then(x => x.json());
console.log('got requests made ');
console.log(Object.assign({}, requestsMade));
};
const fetchRequestsReceived = async () => {
$$invalidate(3, requestsRecieved = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/received`).then(x => x.json()));
$$invalidate(3, requestsRecieved = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/received`).then(x => x.json()));
console.log('got requests received ');
console.log(Object.assign({}, requestsRecieved));
};
const fetchBlockedUsers = async () => {
$$invalidate(4, blockedUsers = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/blocked`).then(x => x.json()));
$$invalidate(4, blockedUsers = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/blocked`).then(x => x.json()));
console.log('got blocked users, is it empty?');
console.log(Object.assign({}, blockedUsers));
console.log(Object.keys(blockedUsers));
@@ -18475,7 +18503,7 @@ var app = (function () {
const fetchFriendshipFull = async aUsername => {
console.log('fetch friendship from a username');
console.log(aUsername);
$$invalidate(6, friendshipStatusFull = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/myfriends?username=${aUsername}`).then(x => x.json()));
$$invalidate(6, friendshipStatusFull = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/myfriends?username=${aUsername}`).then(x => x.json()));
console.log(Object.assign({}, friendshipStatusFull));
};
@@ -18483,7 +18511,7 @@ var app = (function () {
console.log('sending a friend request');
console.log(aUsername);
const resp = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/relations`, {
const resp = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/relations`, {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -18513,7 +18541,7 @@ var app = (function () {
const acceptFriendRequest = async relationshipId => {
console.log('accept friend request');
const resp = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/relations/${relationshipId}/accept`, { method: "PATCH" }).then(x => x.json());
const resp = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/relations/${relationshipId}/accept`, { method: "PATCH" }).then(x => x.json());
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
console.log('accepted friend request, now response');
@@ -18527,7 +18555,7 @@ var app = (function () {
const declineFriendRequest = async relationshipId => {
console.log('decline friend request');
const resp = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/relations/${relationshipId}/decline`, { method: "PATCH" }).then(x => x.json());
const resp = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/relations/${relationshipId}/decline`, { method: "PATCH" }).then(x => x.json());
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
console.log('declined friend request, now response');
@@ -18538,7 +18566,7 @@ var app = (function () {
const unfriend = async relationshipId => {
console.log('Unfriend');
await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/relations/${relationshipId}`, { method: "DELETE" }).then(x => x.json());
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/relations/${relationshipId}`, { method: "DELETE" }).then(x => x.json());
// friendshipStatusFull = undefined;
// OR
@@ -18554,7 +18582,7 @@ var app = (function () {
console.log('Block a non friend user, their username');
console.log(aUsername);
sentFriendRequest = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/relations`, {
sentFriendRequest = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/relations`, {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -18575,7 +18603,7 @@ var app = (function () {
const blockAFriend = async relationshipId => {
console.log('blocking a friend, the relationshipID');
console.log(relationshipId);
const resp = await fetch(`http://${'localhost'}:${'8080'}/api/v2/network/relations/${relationshipId}/block`, { method: "PATCH" }).then(x => x.json());
const resp = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/network/relations/${relationshipId}/block`, { method: "PATCH" }).then(x => x.json());
console.log('blocked a user response');
console.log(Object.assign({}, resp));
await fetchBlockedUsers();
@@ -19264,7 +19292,7 @@ var app = (function () {
let user;
onMount(async () => {
$$invalidate(0, user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(resp => resp.json()));
$$invalidate(0, user = await fetch(`http://${'transcendance'}:${'8080'}/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
console.log('User var');
@@ -19285,14 +19313,14 @@ var app = (function () {
});
const login = async () => {
window.location.href = `http://${'localhost'}:${'8080'}/api/v2/auth`;
window.location.href = `http://${'transcendance'}:${'8080'}/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://${'localhost'}:${'8080'}/api/v2/auth/logout`, { method: 'POST' });
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/auth/logout`, { method: 'POST' });
$$invalidate(0, user = undefined);
};
@@ -19626,7 +19654,7 @@ var app = (function () {
let wrongCode = "";
const fetchQrCodeImg = (async () => {
await fetch(`http://${'localhost'}:${'8080'}/api/v2/auth/2fa/generate`, { method: 'POST' }).then(response => {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/auth/2fa/generate`, { method: 'POST' }).then(response => {
return response.blob();
}).then(blob => {
const url = URL.createObjectURL(blob);
@@ -19635,7 +19663,7 @@ var app = (function () {
})();
const submitCode = async () => {
const response = await fetch(`http://${'localhost'}:${'8080'}/api/v2/auth/2fa/check`, {
const response = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/auth/2fa/check`, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ "twoFaCode": qrCode })
@@ -20035,13 +20063,13 @@ var app = (function () {
we should continue initAudio() regardless of the muteFlag.
*/
}
soundPongArr.push(new Audio("http://" + 'localhost' + ":" + '8080' + "/sound/pong/" + 1 + ".ogg"));
soundPongArr.push(new Audio("http://" + 'localhost' + ":" + '8080' + "/sound/pong/" + 2 + ".ogg"));
soundPongArr.push(new Audio("http://" + 'transcendance' + ":" + '8080' + "/sound/pong/" + 1 + ".ogg"));
soundPongArr.push(new Audio("http://" + 'transcendance' + ":" + '8080' + "/sound/pong/" + 2 + ".ogg"));
soundPongArr.forEach((value) => {
value.volume = soundRobloxVolume;
value.muted = muteFlag;
});
soundRoblox = new Audio("http://" + 'localhost' + ":" + '8080' + "/sound/roblox-oof.ogg");
soundRoblox = new Audio("http://" + 'transcendance' + ":" + '8080' + "/sound/roblox-oof.ogg");
soundRoblox.volume = soundRobloxVolume;
soundRoblox.muted = muteFlag;
}
@@ -20125,7 +20153,7 @@ var app = (function () {
}
class ClientInfoSpectator {
}
const wsUrl = "ws://" + 'localhost' + ":" + '8080' + "/pong";
const wsUrl = "ws://" + 'transcendance' + ":" + '8080' + "/pong";
let socket;
const clientInfo = new ClientInfo();
const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this
@@ -22457,8 +22485,8 @@ var app = (function () {
let watchGameStateInterval;
onMount(async () => {
$$invalidate(11, user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(x => x.json()));
$$invalidate(1, allUsers = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/all`).then(x => x.json()));
$$invalidate(11, user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`).then(x => x.json()));
$$invalidate(1, allUsers = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/all`).then(x => x.json()));
$$invalidate(2, options.playerOneUsername = user.username, options);
});
@@ -22484,7 +22512,7 @@ var app = (function () {
const matchOptions = computeMatchOptions(options);
try {
const response = await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/ticket`, {
const response = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/ticket`, {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -22576,11 +22604,11 @@ var app = (function () {
const fetchInvitations = async () => {
$$invalidate(5, showGameOptions = false);
$$invalidate(6, showInvitations = true);
$$invalidate(10, invitations = await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/invitations`).then(x => x.json()));
$$invalidate(10, invitations = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/invitations`).then(x => x.json()));
};
const rejectInvitation = async invitation => {
await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/decline`, {
await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/decline`, {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: invitation.token })
@@ -22590,7 +22618,7 @@ var app = (function () {
};
const acceptInvitation = async invitation => {
const res = await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/accept`, {
const res = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/accept`, {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: invitation.token })
@@ -23143,8 +23171,8 @@ var app = (function () {
let idInterval;
onMount(async () => {
$$invalidate(0, currentUser = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(x => x.json()));
$$invalidate(1, allUsers = await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/ranking`).then(x => x.json()));
$$invalidate(0, currentUser = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`).then(x => x.json()));
$$invalidate(1, allUsers = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/ranking`).then(x => x.json()));
idInterval = setInterval(fetchScores, 10000);
});
@@ -23153,7 +23181,7 @@ var app = (function () {
});
function fetchScores() {
fetch(`http://${'localhost'}:${'8080'}/api/v2/game/ranking`).then(x => x.json()).then(x => $$invalidate(1, allUsers = x));
fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/ranking`).then(x => x.json()).then(x => $$invalidate(1, allUsers = x));
}
const writable_props = [];
@@ -24137,9 +24165,9 @@ var app = (function () {
let watchGameStateInterval;
onMount(async () => {
user = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user`).then(x => x.json());
allUsers = await fetch(`http://${'localhost'}:${'8080'}/api/v2/user/all`).then(x => x.json());
const responseForMatchList = await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/match/all`);
user = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user`).then(x => x.json());
allUsers = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/user/all`).then(x => x.json());
const responseForMatchList = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/match/all`);
const jsonForMatchList = await responseForMatchList.json();
$$invalidate(2, matchList = jsonForMatchList);
});
@@ -24192,7 +24220,7 @@ var app = (function () {
}
async function fetchMatchList() {
$$invalidate(2, matchList = await fetch(`http://${'localhost'}:${'8080'}/api/v2/game/match/all`).then(x => x.json()));
$$invalidate(2, matchList = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/game/match/all`).then(x => x.json()));
}
const writable_props = [];
@@ -24286,7 +24314,7 @@ var app = (function () {
component: Game,
conditions: [
async(detail) => {
const user = await fetch('http://' + 'localhost' + ":" + '8080' + '/api/v2/user')
const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json());
console.log('in /profile what is in user');
@@ -24303,7 +24331,7 @@ var app = (function () {
component: GameSpectator,
conditions: [
async(detail) => {
const user = await fetch('http://' + 'localhost' + ":" + '8080' + '/api/v2/user')
const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json());
console.log('in /profile what is in user');
@@ -24320,7 +24348,7 @@ var app = (function () {
component: Ranking,
conditions: [
async(detail) => {
const user = await fetch('http://' + 'localhost' + ":" + '8080' + '/api/v2/user')
const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json());
console.log('in /profile what is in user');
@@ -24337,7 +24365,7 @@ var app = (function () {
component: ProfilePage,
conditions: [
async(detail) => {
const user = await fetch('http://' + 'localhost' + ":" + '8080' + '/api/v2/user')
const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json());
console.log('in /profile what is in user');
@@ -24354,7 +24382,7 @@ var app = (function () {
component: ProfilePage,
conditions: [
async(detail) => {
const user = await fetch('http://' + 'localhost' + ":" + '8080' + '/api/v2/user')
const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json());
console.log('in /profile/* what is in user');

File diff suppressed because one or more lines are too long

View File

@@ -9,13 +9,13 @@
export let back = "";
let allowed_chars = 'loading...';
let regex;
//let regex;
onMount(async() => {
let response = await fetch('/api/v2/chat/allowedchars');
let data = await response.json();
console.log("data:", data);
allowed_chars = data.chars;
regex = new RegExp(`^[a-zA-Z0-9\\s${allowed_chars}]+$`);
//regex = new RegExp(`^[a-zA-Z0-9\\s${allowed_chars}]+$`);
});
let room_name: string;
@@ -68,7 +68,10 @@
{/if}
<!-- name: -->
<label for="chat_name"><p>new room name :</p></label>
<!--
<input id="chat_name" bind:value={room_name} name="room_name" placeholder="allowed special characters: {allowed_chars}" pattern={regex} required>
-->
<input id="chat_name" bind:value={room_name} name="room_name" placeholder="allowed special characters: {allowed_chars}" required>
<!-- [ ] pubic -->
<label for="chat_public" class="_radio">
<p>public</p>