feat: fetch settings from api

This commit is contained in:
Pitu 2021-06-17 01:10:24 +09:00
parent 334c3d1c34
commit 50d13e2ae7
6 changed files with 36 additions and 21 deletions

View File

@ -60,13 +60,7 @@ export default {
linkExactActiveClass: 'is-active'
},
env: {
development: process.env.NODE_ENV !== 'production',
version: process.env.npm_package_version,
serviceName: Util.config.serviceName,
maxFileSize: Util.config.maxSize,
chunkSize: Util.config.chunkSize,
publicMode: Util.config.publicMode,
userAccounts: Util.config.userAccounts
development: process.env.NODE_ENV !== 'production'
},
axios: {
baseURL: `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:5000'}/api`

View File

@ -3,20 +3,21 @@ const Util = require('../../utils/Util');
class configGET extends Route {
constructor() {
super('/service/config', 'get', { adminOnly: true });
super('/service/config', 'get', { bypassAuth: true });
}
run(req, res) {
return res.json({
message: 'Successfully retrieved config',
config: {
version: process.env.npm_package_version,
serviceName: Util.config.serviceName,
maxUploadSize: Util.config.maxSize,
filenameLength: Util.config.generatedFilenameLength,
albumLinkLength: Util.config.generatedAlbumLength,
generateZips: Util.config.generateZips,
chunkSize: Util.config.chunkSize,
publicMode: Util.config.publicMode,
enableAccounts: Util.config.userAccounts
userAccounts: Util.config.userAccounts
}
});
}

View File

@ -9,7 +9,7 @@
href="https://github.com/pitu"
class="no-block">Pitu</a>
</span><br>
<span>v{{ version }}</span>
<span>{{ version }}</span>
</div>
<div class="column is-narrow bottom-up">
<a href="https://github.com/weebdev/chibisafe">GitHub</a>

View File

@ -124,7 +124,7 @@ export default {
parallelChunkUploads: false,
chunkSize: this.config.chunkSize * 1000000,
chunksUploaded: this.dropzoneChunksUploaded,
maxFilesize: this.config.maxFileSize,
maxFilesize: this.config.maxUploadSize,
previewTemplate: this.$refs.template.innerHTML,
dictDefaultMessage: 'Drag & Drop your files or click to browse',
headers: { Accept: 'application/vnd.chibisafe.json' }

View File

@ -1,11 +1,33 @@
export const state = () => ({
development: process.env.development,
version: process.env.version,
version: '',
URL: process.env.development ? 'http://localhost:5000' : '/',
baseURL: `${process.env.development ? 'http://localhost:5000' : ''}/api`,
serviceName: process.env.serviceName,
maxFileSize: process.env.maxFilesize,
chunkSize: process.env.chunkSize,
publicMode: process.env.publicMode,
userAccounts: process.env.userAccounts
serviceName: '',
maxFileSize: '',
chunkSize: 0,
publicMode: false,
userAccounts: false
});
export const mutations = {
setSettings(state, { config }) {
state.version = `v${config.version}`;
state.serviceName = config.serviceName;
state.maxUploadSize = config.maxUploadSize;
state.filenameLength = config.filenameLength;
state.albumLinkLength = config.albumLinkLength;
state.chunkSize = config.chunkSize;
state.publicMode = config.publicMode;
state.userAccounts = config.userAccounts;
}
};
export const actions = {
async fetchSettings({ commit }) {
const response = await this.$axios.$get('service/config');
commit('setSettings', response);
return response;
}
};

View File

@ -1,8 +1,6 @@
import config from '../../../dist/config.json';
export const actions = {
async nuxtServerInit({ commit, dispatch }) {
commit('config/set', config);
await dispatch('config/fetchSettings');
const cookies = this.$cookies.getAll();
if (!cookies.token) return dispatch('auth/logout');