|
|
@ -8,38 +8,64 @@ import backendInteractorService from '../services/backend_interactor_service/bac
|
|
|
|
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
|
|
|
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
|
|
|
import { applyTheme } from '../services/style_setter/style_setter.js'
|
|
|
|
import { applyTheme } from '../services/style_setter/style_setter.js'
|
|
|
|
|
|
|
|
|
|
|
|
const getStatusnetConfig = async ({ store }) => {
|
|
|
|
let staticInitialResults = null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const parsedInitialResults = () => {
|
|
|
|
|
|
|
|
if (!document.getElementById('initial-results')) {
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!staticInitialResults) {
|
|
|
|
|
|
|
|
staticInitialResults = JSON.parse(document.getElementById('initial-results').textContent)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return staticInitialResults
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const preloadFetch = async (request) => {
|
|
|
|
|
|
|
|
const data = parsedInitialResults()
|
|
|
|
|
|
|
|
if (!data || !data[request]) {
|
|
|
|
|
|
|
|
return window.fetch(request)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const requestData = atob(data[request])
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
|
|
json: () => JSON.parse(requestData),
|
|
|
|
|
|
|
|
text: () => requestData
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getInstanceConfig = async ({ store }) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/api/statusnet/config.json')
|
|
|
|
const res = await preloadFetch('/api/v1/instance')
|
|
|
|
if (res.ok) {
|
|
|
|
if (res.ok) {
|
|
|
|
const data = await res.json()
|
|
|
|
const data = await res.json()
|
|
|
|
const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey, safeDMMentionsEnabled } = data.site
|
|
|
|
const textlimit = data.max_toot_chars
|
|
|
|
|
|
|
|
const vapidPublicKey = data.pleroma.vapid_public_key
|
|
|
|
store.dispatch('setInstanceOption', { name: 'name', value: name })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'textlimit', value: textlimit })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'server', value: server })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'safeDM', value: safeDMMentionsEnabled !== '0' })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: default values for this stuff, added if to not make it break on
|
|
|
|
|
|
|
|
// my dev config out of the box.
|
|
|
|
|
|
|
|
if (uploadlimit) {
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (vapidPublicKey) {
|
|
|
|
if (vapidPublicKey) {
|
|
|
|
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw (res)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('Could not load instance config, potentially fatal')
|
|
|
|
|
|
|
|
console.error(error)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return data.site.pleromafe
|
|
|
|
const getBackendProvidedConfig = async ({ store }) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const res = await window.fetch('/api/pleroma/frontend_configurations')
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
|
|
|
return data.pleroma_fe
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw (res)
|
|
|
|
throw (res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Could not load statusnet config, potentially fatal')
|
|
|
|
console.error('Could not load backend-provided frontend config, potentially fatal')
|
|
|
|
console.error(error)
|
|
|
|
console.error(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -132,7 +158,7 @@ const getTOS = async ({ store }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const getInstancePanel = async ({ store }) => {
|
|
|
|
const getInstancePanel = async ({ store }) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/instance/panel.html')
|
|
|
|
const res = await preloadFetch('/instance/panel.html')
|
|
|
|
if (res.ok) {
|
|
|
|
if (res.ok) {
|
|
|
|
const html = await res.text()
|
|
|
|
const html = await res.text()
|
|
|
|
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
|
|
|
@ -195,18 +221,28 @@ const resolveStaffAccounts = ({ store, accounts }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const getNodeInfo = async ({ store }) => {
|
|
|
|
const getNodeInfo = async ({ store }) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/nodeinfo/2.0.json')
|
|
|
|
const res = await preloadFetch('/nodeinfo/2.0.json')
|
|
|
|
if (res.ok) {
|
|
|
|
if (res.ok) {
|
|
|
|
const data = await res.json()
|
|
|
|
const data = await res.json()
|
|
|
|
const metadata = data.metadata
|
|
|
|
const metadata = data.metadata
|
|
|
|
const features = metadata.features
|
|
|
|
const features = metadata.features
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'name', value: metadata.nodeName })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'registrationOpen', value: data.openRegistrations })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'safeDM', value: features.includes('safe_dm_mentions') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'pollsAvailable', value: features.includes('polls') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'pollsAvailable', value: features.includes('polls') })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'pollLimits', value: metadata.pollLimits })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'pollLimits', value: metadata.pollLimits })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'mailerEnabled', value: metadata.mailerEnabled })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'mailerEnabled', value: metadata.mailerEnabled })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uploadLimits = metadata.uploadLimits
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadLimits.general) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadLimits.avatar) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadLimits.background) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadLimits.banner) })
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'fieldsLimits', value: metadata.fieldsLimits })
|
|
|
|
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats })
|
|
|
|
store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats })
|
|
|
|
|
|
|
|
|
|
|
@ -257,7 +293,7 @@ const getNodeInfo = async ({ store }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const setConfig = async ({ store }) => {
|
|
|
|
const setConfig = async ({ store }) => {
|
|
|
|
// apiConfig, staticConfig
|
|
|
|
// apiConfig, staticConfig
|
|
|
|
const configInfos = await Promise.all([getStatusnetConfig({ store }), getStaticConfig()])
|
|
|
|
const configInfos = await Promise.all([getBackendProvidedConfig({ store }), getStaticConfig()])
|
|
|
|
const apiConfig = configInfos[0]
|
|
|
|
const apiConfig = configInfos[0]
|
|
|
|
const staticConfig = configInfos[1]
|
|
|
|
const staticConfig = configInfos[1]
|
|
|
|
|
|
|
|
|
|
|
@ -280,6 +316,11 @@ const checkOAuthToken = async ({ store }) => {
|
|
|
|
const afterStoreSetup = async ({ store, i18n }) => {
|
|
|
|
const afterStoreSetup = async ({ store, i18n }) => {
|
|
|
|
const width = windowWidth()
|
|
|
|
const width = windowWidth()
|
|
|
|
store.dispatch('setMobileLayout', width <= 800)
|
|
|
|
store.dispatch('setMobileLayout', width <= 800)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const overrides = window.___pleromafe_dev_overrides || {}
|
|
|
|
|
|
|
|
const server = (typeof overrides.target !== 'undefined') ? overrides.target : window.location.origin
|
|
|
|
|
|
|
|
store.dispatch('setInstanceOption', { name: 'server', value: server })
|
|
|
|
|
|
|
|
|
|
|
|
await setConfig({ store })
|
|
|
|
await setConfig({ store })
|
|
|
|
|
|
|
|
|
|
|
|
const { customTheme, customThemeSource } = store.state.config
|
|
|
|
const { customTheme, customThemeSource } = store.state.config
|
|
|
@ -299,16 +340,18 @@ const afterStoreSetup = async ({ store, i18n }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now we can try getting the server settings and logging in
|
|
|
|
// Now we can try getting the server settings and logging in
|
|
|
|
|
|
|
|
// Most of these are preloaded into the index.html so blocking is minimized
|
|
|
|
await Promise.all([
|
|
|
|
await Promise.all([
|
|
|
|
checkOAuthToken({ store }),
|
|
|
|
checkOAuthToken({ store }),
|
|
|
|
getTOS({ store }),
|
|
|
|
|
|
|
|
getInstancePanel({ store }),
|
|
|
|
getInstancePanel({ store }),
|
|
|
|
getStickers({ store }),
|
|
|
|
getNodeInfo({ store }),
|
|
|
|
getNodeInfo({ store })
|
|
|
|
getInstanceConfig({ store })
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
// Start fetching things that don't need to block the UI
|
|
|
|
// Start fetching things that don't need to block the UI
|
|
|
|
store.dispatch('fetchMutes')
|
|
|
|
store.dispatch('fetchMutes')
|
|
|
|
|
|
|
|
getTOS({ store })
|
|
|
|
|
|
|
|
getStickers({ store })
|
|
|
|
|
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
const router = new VueRouter({
|
|
|
|
mode: 'history',
|
|
|
|
mode: 'history',
|
|
|
|