after_store: Remove most of StatusNet config usage
Information under `pleromafe` key is equivalent to the one under `pleroma_fe` key in `/api/pleroma/frontend_configurations`. All other information had equivalents in `/nodeinfo/2.0.json`, except `textlimit` and `vapidPublicKey`.
This commit is contained in:
		
							parent
							
								
									6e14fb292c
								
							
						
					
					
						commit
						7dfa734665
					
				
					 1 changed files with 33 additions and 18 deletions
				
			
		|  | @ -13,28 +13,13 @@ const getStatusnetConfig = async ({ store }) => { | |||
|     const res = await window.fetch('/api/statusnet/config.json') | ||||
|     if (res.ok) { | ||||
|       const data = await res.json() | ||||
|       const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey, safeDMMentionsEnabled } = data.site | ||||
|       const { textlimit, vapidPublicKey } = data.site | ||||
| 
 | ||||
|       store.dispatch('setInstanceOption', { name: 'name', value: name }) | ||||
|       store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) | ||||
|       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) { | ||||
|         store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) | ||||
|       } | ||||
| 
 | ||||
|       return data.site.pleromafe | ||||
|     } else { | ||||
|       throw (res) | ||||
|     } | ||||
|  | @ -44,6 +29,21 @@ const getStatusnetConfig = async ({ store }) => { | |||
|   } | ||||
| } | ||||
| 
 | ||||
| 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 { | ||||
|       throw (res) | ||||
|     } | ||||
|   } catch (error) { | ||||
|     console.error('Could not load backend-provided frontend config, potentially fatal') | ||||
|     console.error(error) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| const getStaticConfig = async () => { | ||||
|   try { | ||||
|     const res = await window.fetch('/static/config.json') | ||||
|  | @ -200,13 +200,22 @@ const getNodeInfo = async ({ store }) => { | |||
|       const data = await res.json() | ||||
|       const metadata = data.metadata | ||||
|       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: 'safeDM', value: features.includes('safe_dm_mentions') }) | ||||
|       store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') }) | ||||
|       store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') }) | ||||
|       store.dispatch('setInstanceOption', { name: 'pollsAvailable', value: features.includes('polls') }) | ||||
|       store.dispatch('setInstanceOption', { name: 'pollLimits', value: metadata.pollLimits }) | ||||
|       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: 'restrictedNicknames', value: metadata.restrictedNicknames }) | ||||
|       store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats }) | ||||
| 
 | ||||
|  | @ -254,7 +263,7 @@ const getNodeInfo = async ({ store }) => { | |||
| 
 | ||||
| const setConfig = async ({ store }) => { | ||||
|   // apiConfig, staticConfig
 | ||||
|   const configInfos = await Promise.all([getStatusnetConfig({ store }), getStaticConfig()]) | ||||
|   const configInfos = await Promise.all([getBackendProvidedConfig({ store }), getStaticConfig()]) | ||||
|   const apiConfig = configInfos[0] | ||||
|   const staticConfig = configInfos[1] | ||||
| 
 | ||||
|  | @ -277,6 +286,11 @@ const checkOAuthToken = async ({ store }) => { | |||
| const afterStoreSetup = async ({ store, i18n }) => { | ||||
|   const width = windowWidth() | ||||
|   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 }) | ||||
| 
 | ||||
|   const { customTheme, customThemeSource } = store.state.config | ||||
|  | @ -301,7 +315,8 @@ const afterStoreSetup = async ({ store, i18n }) => { | |||
|     getTOS({ store }), | ||||
|     getInstancePanel({ store }), | ||||
|     getStickers({ store }), | ||||
|     getNodeInfo({ store }) | ||||
|     getNodeInfo({ store }), | ||||
|     getStatusnetConfig({ store }) | ||||
|   ]) | ||||
| 
 | ||||
|   const router = new VueRouter({ | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 rinpatch
						rinpatch