Compare commits

...

2 Commits

Author SHA1 Message Date
fe065f3390 Add assets/js/login.js
login page with api
2024-08-29 13:41:09 +00:00
ea92027a3c Add assets/js/all_apis.js
add apis from manual
2024-08-29 13:34:42 +00:00
2 changed files with 215 additions and 0 deletions

171
assets/js/all_apis.js Normal file
View File

@ -0,0 +1,171 @@
async function getChatEvents(chatId, localHistoryId) {
const response = await fetch('/api/chatPollEvents', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatUpdReq: {
chatId: chatId,
LocalHistoryId: localHistoryId
}
})
});
const data = await response.json();
return data.chatUpdResp;
}
async function getChatListEvents(localHistoryId) {
const response = await fetch('/api/chatListPollEvents', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatListUpdReq: {
LocalHistoryId: localHistoryId
}
})
});
const data = await response.json();
return data.chatListUpdResp;
}
async function getMessageNeighbours(chatId, msgId, direction, amount, localHistoryId) {
const response = await fetch('/api/getMessageNeighbours', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatUpdReq: {
chatId: chatId,
LocalHistoryId: localHistoryId
},
msgId: msgId,
direction: direction,
amount: amount
})
});
const data = await response.json();
return data.chatUpdResp;
}
async function sendMessage(chatId, localHistoryId, text) {
const response = await fetch('/api/sendMessage', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatUpdReq: {
chatId: chatId,
LocalHistoryId: localHistoryId
},
content: {
text: text
}
})
});
const data = await response.json();
return data.chatUpdResp;
}
async function deleteMessage(chatId, localHistoryId, messageId) {
const response = await fetch('/api/deleteMessage', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatUpdReq: {
chatId: chatId,
LocalHistoryId: localHistoryId
},
id: messageId
})
});
const data = await response.json();
return data.chatUpdResp;
}
async function addMemberToChat(chatId, localHistoryId, nickname) {
const response = await fetch('/api/addMemberToChat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatUpdReq: {
chatId: chatId,
LocalHistoryId: localHistoryId
},
nickname: nickname
})
});
const data = await response.json();
return data.chatUpdResp;
}
async function removeMemberFromChat(chatId, localHistoryId, userId) {
const response = await fetch('/api/removeMemberFromChat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatUpdReq: {
chatId: chatId,
LocalHistoryId: localHistoryId
},
userId: userId
})
});
const data = await response.json();
return data.chatUpdResp;
}
async function createChat(localHistoryId, name, nickname) {
const response = await fetch('/api/createChat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatListUpdReq: {
LocalHistoryId: localHistoryId
},
content: {
name: name,
nickname: nickname
}
})
});
const data = await response.json();
return data.chatListUpdResp;
}
async function leaveChat(localHistoryId, chatId) {
const response = await fetch('/api/leaveChat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatListUpdReq: {
LocalHistoryId: localHistoryId
},
chatId: chatId
})
});
const data = await response.json();
return data.chatListUpdResp;
}

44
assets/js/login.js Normal file
View File

@ -0,0 +1,44 @@
document.addEventListener('DOMContentLoaded', function() {
let nickname, password;
function handleSubmit(event) {
event.preventDefault();
nickname = document.getElementById('nickname').value;
password = document.getElementById('password').value;
pageStatusUpdate();
}
function pageStatusUpdate() {
const req = {
nickname,
password
};
const apiUrl = 'http://127.0.0.1:1025/login';
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
})
.then(response => {
if (response.ok) {
return response.json();
}
})
.then(data => {
if (data && data.status === 0) {
window.location.href = '/list-rooms';
}
});
}
const form = document.querySelector('form');
form.addEventListener('submit', handleSubmit);
setInterval(pageStatusUpdate, 1000);
});