mastodon_algorithm_frontend/js/setup.js

52 lines
1.6 KiB
JavaScript

const client = new Appwrite.Client()
.setEndpoint(APPWRITE_ENDPOINT) // Your API Endpoint
.setProject(APPWRITE_PROJECT_ID); // Your project ID
const account = new Appwrite.Account(client);
const databases = new Appwrite.Databases(client);
const functions = new Appwrite.Functions(client);
let accountDetails;
if (window.location.pathname !== '/login.php') {
account.get().then((response) => {
console.log(response);
document.querySelectorAll('.fill-name').forEach(el => el.innerHTML = response.name);
if (response.emailVerification == false) {
message_box('error', 'Your account is not verified!');
return
}
if (response.prefs.user_token == undefined) {
message_box('info', "You haven't connected to Mastodon yet! <a href='connect.php'>Do it now</a>");
}
}).catch((err) => {
if (err == "AppwriteException: User (role: guests) missing scope (account)") {
location.href = "login.php";
}
})
document.getElementById('logout').addEventListener('click', () => {
account.deleteSession('current').then((res) => {
window.location.reload();
});
})
accountDetails = await account.get();
}
export function message_box(type, message) {
const message_box = document.getElementById('message-box');
message_box.classList.remove('info', 'error', 'success');
message_box.innerHTML = message;
message_box.classList.add(type);
message_box.style.display = 'block';
}
export { client, account, databases, functions, accountDetails };