Merge branch 'betterStorage' into shigusegubu

* betterStorage:
  Fixed "user.id is undefined" or something error more sane by properly handling HTTP errors
  undo rename because it makes less sense now.
  proxying nodeinfo
  made FE work even without either api or static config
  Removed warning. Added support for working without static/config.json
  more missing stuff
  fix some missing stuff
  translations
  Added more stuff that's actually being added to instanceConfig, simplified the whitelist.
  more refactoring
  some recategorization of options...
  Initial version
This commit is contained in:
Henry Jameson 2018-09-17 19:08:41 +03:00
commit b0af6b572c
5 changed files with 96 additions and 74 deletions

View file

@ -27,6 +27,11 @@ module.exports = {
changeOrigin: true, changeOrigin: true,
cookieDomainRewrite: 'localhost' cookieDomainRewrite: 'localhost'
}, },
'/nodeinfo': {
target: 'http://localhost:4000/',
changeOrigin: true,
cookieDomainRewrite: 'localhost'
},
'/socket': { '/socket': {
target: 'http://localhost:4000/', target: 'http://localhost:4000/',
changeOrigin: true, changeOrigin: true,

View file

@ -92,8 +92,6 @@ export default function createPersistedState ({
store.dispatch('settingsSaved', { error }) store.dispatch('settingsSaved', { error })
} }
}) })
} else {
console.warn(`Not saving to localStorage for: ${mutation.type}`)
} }
} catch (e) { } catch (e) {
console.log("Couldn't persist state:") console.log("Couldn't persist state:")

View file

@ -89,80 +89,87 @@ window.fetch('/api/statusnet/config.json')
var apiConfig = data.site.pleromafe var apiConfig = data.site.pleromafe
window.fetch('/static/config.json') window.fetch('/static/config.json')
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .catch((err) => {
var staticConfig = data console.warn('Failed to load static/config.json, continuing without it.')
// This takes static config and overrides properties that are present in apiConfig console.warn('Error was: ')
var config = Object.assign({}, staticConfig, apiConfig) console.warn(err)
return {}
})
.then((staticConfig) => {
// This takes static config and overrides properties that are present in apiConfig
var config = Object.assign({}, staticConfig, apiConfig)
var theme = (config.theme) var theme = (config.theme)
var background = (config.background) var background = (config.background)
var logo = (config.logo) var logo = (config.logo)
var logoMask = (typeof config.logoMask === 'undefined' ? true : config.logoMask) var logoMask = (typeof config.logoMask === 'undefined' ? true : config.logoMask)
var logoMargin = (typeof config.logoMargin === 'undefined' ? 0 : config.logoMargin) var logoMargin = (typeof config.logoMargin === 'undefined' ? 0 : config.logoMargin)
var redirectRootNoLogin = (config.redirectRootNoLogin) var redirectRootNoLogin = (config.redirectRootNoLogin)
var redirectRootLogin = (config.redirectRootLogin) var redirectRootLogin = (config.redirectRootLogin)
var chatDisabled = (config.chatDisabled) var chatDisabled = (config.chatDisabled)
var showInstanceSpecificPanel = (config.showInstanceSpecificPanel) var showInstanceSpecificPanel = (config.showInstanceSpecificPanel)
var scopeOptionsEnabled = (config.scopeOptionsEnabled) var scopeOptionsEnabled = (config.scopeOptionsEnabled)
var formattingOptionsEnabled = (config.formattingOptionsEnabled) var formattingOptionsEnabled = (config.formattingOptionsEnabled)
var defaultCollapseMessageWithSubject = (config.collapseMessageWithSubject) var collapseMessageWithSubject = (config.collapseMessageWithSubject)
store.dispatch('setInstanceOption', { name: 'theme', value: theme }) store.dispatch('setInstanceOption', { name: 'theme', value: theme })
store.dispatch('setInstanceOption', { name: 'background', value: background }) store.dispatch('setInstanceOption', { name: 'background', value: background })
store.dispatch('setInstanceOption', { name: 'logo', value: logo }) store.dispatch('setInstanceOption', { name: 'logo', value: logo })
store.dispatch('setInstanceOption', { name: 'logoMask', value: logoMask }) store.dispatch('setInstanceOption', { name: 'logoMask', value: logoMask })
store.dispatch('setInstanceOption', { name: 'logoMargin', value: logoMargin }) store.dispatch('setInstanceOption', { name: 'logoMargin', value: logoMargin })
store.dispatch('setInstanceOption', { name: 'redirectRootNoLogin', value: redirectRootNoLogin }) store.dispatch('setInstanceOption', { name: 'redirectRootNoLogin', value: redirectRootNoLogin })
store.dispatch('setInstanceOption', { name: 'redirectRootLogin', value: redirectRootLogin }) store.dispatch('setInstanceOption', { name: 'redirectRootLogin', value: redirectRootLogin })
store.dispatch('setInstanceOption', { name: 'showInstanceSpecificPanel', value: showInstanceSpecificPanel }) store.dispatch('setInstanceOption', { name: 'showInstanceSpecificPanel', value: showInstanceSpecificPanel })
store.dispatch('setInstanceOption', { name: 'scopeOptionsEnabled', value: scopeOptionsEnabled }) store.dispatch('setInstanceOption', { name: 'scopeOptionsEnabled', value: scopeOptionsEnabled })
store.dispatch('setInstanceOption', { name: 'formattingOptionsEnabled', value: formattingOptionsEnabled }) store.dispatch('setInstanceOption', { name: 'formattingOptionsEnabled', value: formattingOptionsEnabled })
store.dispatch('setInstanceOption', { name: 'collapseMessageWithSubject', value: defaultCollapseMessageWithSubject }) store.dispatch('setInstanceOption', { name: 'collapseMessageWithSubject', value: collapseMessageWithSubject })
if (chatDisabled) { if (chatDisabled) {
store.dispatch('disableChat') store.dispatch('disableChat')
}
const routes = [
{ name: 'root',
path: '/',
redirect: to => {
return (store.state.users.currentUser ? redirectRootLogin : redirectRootNoLogin) || '/main/all'
}},
{ path: '/main/all', component: PublicAndExternalTimeline },
{ path: '/main/public', component: PublicTimeline },
{ path: '/main/friends', component: FriendsTimeline },
{ path: '/tag/:tag', component: TagTimeline },
{ name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } },
{ name: 'user-profile', path: '/users/:id', component: UserProfile },
{ name: 'mentions', path: '/:username/mentions', component: Mentions },
{ name: 'settings', path: '/settings', component: Settings },
{ name: 'registration', path: '/registration', component: Registration },
{ name: 'registration', path: '/registration/:token', component: Registration },
{ name: 'friend-requests', path: '/friend-requests', component: FollowRequests },
{ name: 'user-settings', path: '/user-settings', component: UserSettings }
]
const router = new VueRouter({
mode: 'history',
routes,
scrollBehavior: (to, from, savedPosition) => {
if (to.matched.some(m => m.meta.dontScroll)) {
return false
}
return savedPosition || { x: 0, y: 0 }
} }
})
/* eslint-disable no-new */ const routes = [
new Vue({ { name: 'root',
router, path: '/',
store, redirect: to => {
i18n, return (store.state.users.currentUser
el: '#app', ? store.state.instance.redirectRootLogin
render: h => h(App) : store.state.instance.redirectRootNoLogin) || '/main/all'
}},
{ path: '/main/all', component: PublicAndExternalTimeline },
{ path: '/main/public', component: PublicTimeline },
{ path: '/main/friends', component: FriendsTimeline },
{ path: '/tag/:tag', component: TagTimeline },
{ name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } },
{ name: 'user-profile', path: '/users/:id', component: UserProfile },
{ name: 'mentions', path: '/:username/mentions', component: Mentions },
{ name: 'settings', path: '/settings', component: Settings },
{ name: 'registration', path: '/registration', component: Registration },
{ name: 'registration', path: '/registration/:token', component: Registration },
{ name: 'friend-requests', path: '/friend-requests', component: FollowRequests },
{ name: 'user-settings', path: '/user-settings', component: UserSettings }
]
const router = new VueRouter({
mode: 'history',
routes,
scrollBehavior: (to, from, savedPosition) => {
if (to.matched.some(m => m.meta.dontScroll)) {
return false
}
return savedPosition || { x: 0, y: 0 }
}
})
/* eslint-disable no-new */
new Vue({
router,
store,
i18n,
el: '#app',
render: h => h(App)
})
}) })
})
}) })
window.fetch('/static/terms-of-service.html') window.fetch('/static/terms-of-service.html')

View file

@ -1,4 +1,5 @@
import { set } from 'vue' import { set } from 'vue'
import StyleSetter from '../services/style_setter/style_setter.js'
const defaultState = { const defaultState = {
// Stuff from static/config.json and apiConfig // Stuff from static/config.json and apiConfig
@ -7,7 +8,7 @@ const defaultState = {
textlimit: 5000, textlimit: 5000,
server: 'http://localhost:4040/', server: 'http://localhost:4040/',
theme: 'pleroma-dark', theme: 'pleroma-dark',
background: 'img.png', background: '/static/aurora_borealis.jpg',
logo: '/static/logo.png', logo: '/static/logo.png',
logoMask: true, logoMask: true,
logoMargin: '.2em', logoMargin: '.2em',
@ -40,7 +41,9 @@ const instance = {
state: defaultState, state: defaultState,
mutations: { mutations: {
setInstanceOption (state, { name, value }) { setInstanceOption (state, { name, value }) {
set(state, name, value) if (typeof value !== 'undefined') {
set(state, name, value)
}
} }
}, },
actions: { actions: {
@ -50,6 +53,8 @@ const instance = {
case 'name': case 'name':
dispatch('setPageTitle') dispatch('setPageTitle')
break break
case 'theme':
StyleSetter.setPreset(value, commit)
} }
} }
} }

View file

@ -335,7 +335,14 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
url += `?${queryString}` url += `?${queryString}`
return fetch(url, { headers: authHeaders(credentials) }).then((data) => data.json()) return fetch(url, { headers: authHeaders(credentials) })
.then((data) => {
if (data.ok) {
return data
}
throw new Error('Error fetching timeline')
})
.then((data) => data.json())
} }
const verifyCredentials = (user) => { const verifyCredentials = (user) => {