parent
766e74cc51
commit
15f296a780
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"no-shadow": ["error", { "allow": ["state"] }]
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable no-shadow */
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
files: [],
|
files: [],
|
||||||
name: null,
|
name: null,
|
||||||
|
@ -36,6 +35,10 @@ export const actions = {
|
||||||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// TODO: Fix duplicate code between this store and files store
|
||||||
|
deleteFile({ commit }, fileId) {
|
||||||
|
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable no-shadow */
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* eslint-disable no-shadow */
|
|
||||||
const getDefaultState = () => ({
|
const getDefaultState = () => ({
|
||||||
text: null,
|
text: null,
|
||||||
error: false
|
error: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const state = getDefaultState;
|
export const state = getDefaultState;
|
||||||
|
@ -12,7 +11,7 @@ export const actions = {
|
||||||
},
|
},
|
||||||
clear({ commit }) {
|
clear({ commit }) {
|
||||||
commit('clear');
|
commit('clear');
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
|
@ -22,5 +21,5 @@ export const mutations = {
|
||||||
},
|
},
|
||||||
clear(state) {
|
clear(state) {
|
||||||
Object.assign(state, getDefaultState());
|
Object.assign(state, getDefaultState());
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
/* eslint-disable no-shadow */
|
|
||||||
// only used so I could keep the convention of naming the first param as "state" in mutations
|
|
||||||
const getDefaultState = () => ({
|
const getDefaultState = () => ({
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
isLoading: false,
|
|
||||||
user: null,
|
user: null,
|
||||||
token: null,
|
token: null,
|
||||||
});
|
});
|
||||||
|
@ -23,18 +20,14 @@ export const actions = {
|
||||||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async login({ commit, dispatch }, { username, password }) {
|
async login({ commit }, { username, password }) {
|
||||||
commit('loginRequest');
|
commit('loginRequest');
|
||||||
|
|
||||||
try {
|
const data = await this.$axios.$post('auth/login', { username, password });
|
||||||
const data = await this.$axios.$post('auth/login', { username, password });
|
this.$axios.setToken(data.token, 'Bearer');
|
||||||
this.$axios.setToken(data.token, 'Bearer');
|
|
||||||
|
|
||||||
commit('setToken', data.token);
|
commit('setToken', data.token);
|
||||||
commit('loginSuccess', { token: data.token, user: data.user });
|
commit('loginSuccess', { token: data.token, user: data.user });
|
||||||
} catch (e) {
|
|
||||||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async fetchCurrentUser({ commit, dispatch }) {
|
async fetchCurrentUser({ commit, dispatch }) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable no-shadow */
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
development: true,
|
development: true,
|
||||||
version: '4.0.0',
|
version: '4.0.0',
|
||||||
|
@ -9,11 +8,11 @@ export const state = () => ({
|
||||||
chunkSize: 90,
|
chunkSize: 90,
|
||||||
maxLinksPerAlbum: 5,
|
maxLinksPerAlbum: 5,
|
||||||
publicMode: false,
|
publicMode: false,
|
||||||
userAccounts: false
|
userAccounts: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
set(state, config) {
|
set(state, config) {
|
||||||
Object.assign(state, config);
|
Object.assign(state, config);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
/* eslint-disable no-shadow */
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
files: [],
|
files: [],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
pagination: {
|
pagination: {
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 30,
|
limit: 30,
|
||||||
totalFiles: 0
|
totalFiles: 0,
|
||||||
}
|
},
|
||||||
|
name: null,
|
||||||
|
downloadEnabled: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
getTotalFiles: ({ pagination }) => pagination.totalFiles,
|
getTotalFiles: ({ pagination }) => pagination.totalFiles,
|
||||||
getFetchedCount: ({ files }) => files.length,
|
getFetchedCount: ({ files }) => files.length,
|
||||||
shouldPaginate: ({ pagination }) => pagination.totalFiles > pagination.limit,
|
shouldPaginate: ({ pagination }) => pagination.totalFiles > pagination.limit,
|
||||||
getLimit: ({ pagination }) => pagination.limit
|
getLimit: ({ pagination }) => pagination.limit,
|
||||||
|
getName: ({ name }) => name,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
@ -23,34 +25,37 @@ export const actions = {
|
||||||
page = page || 1;
|
page = page || 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.$axios.$get(`files`, { params: { limit: state.pagination.limit, page } });
|
const response = await this.$axios.$get('files', { params: { limit: state.pagination.limit, page } });
|
||||||
|
|
||||||
commit('setFiles', { files: response.files });
|
commit('setFilesAndMeta', { ...response, page });
|
||||||
commit('updatePaginationMeta', { totalFiles: response.count, page });
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async fetchById({ commit, dispatch }) {
|
async fetchByAlbumId({ commit, dispatch, state }, { id, page }) {
|
||||||
try {
|
commit('setIsLoading');
|
||||||
const response = await this.$axios.$get('verify');
|
|
||||||
commit('loginSuccess', response);
|
page = page || 1;
|
||||||
} catch (e) {
|
|
||||||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
const response = await this.$axios.$get(`album/${id}/full`, {
|
||||||
}
|
params: { limit: state.pagination.limit, page },
|
||||||
}
|
});
|
||||||
|
|
||||||
|
commit('setFilesAndMeta', { ...response, page });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
setIsLoading(state) {
|
setIsLoading(state) {
|
||||||
state.isLoading = true;
|
state.isLoading = true;
|
||||||
},
|
},
|
||||||
setFiles(state, { files }) {
|
setFilesAndMeta(state, {
|
||||||
|
files, name, page, count,
|
||||||
|
}) {
|
||||||
state.files = files || [];
|
state.files = files || [];
|
||||||
|
state.name = name ?? null;
|
||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
},
|
|
||||||
updatePaginationMeta(state, { page, totalFiles }) {
|
|
||||||
state.pagination.page = page || 1;
|
state.pagination.page = page || 1;
|
||||||
state.pagination.totalFiles = totalFiles || 0;
|
state.pagination.totalFiles = count || 0;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import config from '../../../dist/config.json';
|
import config from '../../../dist/config.json';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export const actions = {
|
export const actions = {
|
||||||
async nuxtClientInit({ commit, dispatch }) {
|
async nuxtClientInit({ commit, dispatch }) {
|
||||||
commit('config/set', config);
|
commit('config/set', config);
|
||||||
|
@ -8,8 +9,8 @@ export const actions = {
|
||||||
if (!cookies.token) return dispatch('auth/logout');
|
if (!cookies.token) return dispatch('auth/logout');
|
||||||
|
|
||||||
commit('auth/setToken', cookies.token);
|
commit('auth/setToken', cookies.token);
|
||||||
await dispatch('auth/verify');
|
return dispatch('auth/verify');
|
||||||
}
|
},
|
||||||
/* alert({ commit }, payload) {
|
/* alert({ commit }, payload) {
|
||||||
if (!payload) return commit('alert', null);
|
if (!payload) return commit('alert', null);
|
||||||
commit('alert', {
|
commit('alert', {
|
||||||
|
|
Loading…
Reference in New Issue