MAstodon server
Build LinkLog Development Image / development-image (push) Successful in 9s

This commit is contained in:
Olaf
2026-08-25 23:40:11 +02:00
parent 57e9775882
commit b35249cb86
2 changed files with 18 additions and 7 deletions
+14 -3
View File
@@ -7,7 +7,6 @@ const passwordForm = document.querySelector('#password-form');
const mastodonForm = document.querySelector('#mastodon-form');
const profileLogoutButton = document.querySelector('#logout-button');
const accessToken = localStorage.getItem('linklogAccessToken');
const defaultMastodonInstance = 'mastodon.social';
const defaultPostPrefix = 'From my #LinkLog: ';
const mastodonConnectButton = document.querySelector('#mastodon-connect');
@@ -46,7 +45,7 @@ async function loadMastodonConfig() {
const response = await fetch('/api/user/plugins/mastodon', {headers: authHeaders()});
if (!response.ok) throw new Error('Could not load Mastodon settings');
const config = await response.json();
document.querySelector('#mastodon-instance').value = config.instance || defaultMastodonInstance;
document.querySelector('#mastodon-instance').value = config.instance || 'mastodon.social';
document.querySelector('#mastodon-post-prefix').value = config.post_prefix || defaultPostPrefix;
}
@@ -96,8 +95,20 @@ mastodonForm.addEventListener('submit', async (event) => {
mastodonConnectButton.addEventListener('click', async () => {
mastodonConnectButton.disabled = true;
const instance = document.querySelector('#mastodon-instance').value || defaultMastodonInstance;
const instance = document.querySelector('#mastodon-instance').value.trim();
if (!instance) {
setStatus('#mastodon-status', 'Enter the Mastodon server you want to use.', true);
mastodonConnectButton.disabled = false;
return;
}
try {
const settingsResponse = await fetch('/api/user/plugins/mastodon', {
method: 'PUT',
headers: authHeaders(true),
body: JSON.stringify({instance}),
});
if (!settingsResponse.ok) throw new Error('Could not save the Mastodon server.');
setStatus('#mastodon-status', `Authorizing with ${instance}...`);
const response = await fetch(`/api/mastodon/oauth/start?instance=${encodeURIComponent(instance)}`, {headers: authHeaders()});
const result = await response.json();
if (!response.ok || !result.authorization_url) throw new Error(result.error || 'Could not start Mastodon authorization.');