1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
export const state = () => ({
users: [],
user: {
id: null,
username: null,
enabled: false,
createdAt: null,
editedAt: null,
apiKeyEditedAt: null,
isAdmin: null,
files: []
},
file: {},
settings: {},
statistics: {}
});
export const actions = {
async fetchSettings({ commit }) {
const response = await this.$axios.$get('service/config');
commit('setSettings', response);
return response;
},
async fetchStatistics({ commit }, category) {
const url = category ? `service/statistics/${category}` : 'service/statistics';
const response = await this.$axios.$get(url);
commit('setStatistics', { statistics: response.statistics, category: category });
return response;
},
async fetchUsers({ commit }) {
const response = await this.$axios.$get('admin/users');
commit('setUsers', response);
return response;
},
async fetchUser({ commit }, id) {
const response = await this.$axios.$get(`admin/users/${id}`);
commit('setUserInfo', response);
return response;
},
async fetchFile({ commit }, id) {
const response = await this.$axios.$get(`admin/file/${id}`);
commit('setFile', response);
commit('setUserInfo', response);
return response;
},
async banIP(_, ip) {
const response = await this.$axios.$post('admin/ban/ip', { ip });
return response;
},
async enableUser({ commit }, id) {
const response = await this.$axios.$post('admin/users/enable', { id });
commit('changeUserState', { userId: id, enabled: true });
return response;
},
async disableUser({ commit }, id) {
const response = await this.$axios.$post('admin/users/disable', { id });
commit('changeUserState', { userId: id, enabled: false });
return response;
},
async promoteUser({ commit }, id) {
const response = await this.$axios.$post('admin/users/promote', { id });
commit('changeUserState', { userId: id, isAdmin: true });
return response;
},
async demoteUser({ commit }, id) {
const response = await this.$axios.$post('admin/users/demote', { id });
commit('changeUserState', { userId: id, isAdmin: false });
return response;
},
async purgeUserFiles(_, id) {
const response = await this.$axios.$post('admin/users/purge', { id });
return response;
},
async restartService() {
const response = await this.$axios.$post('service/restart');
return response;
}
};
export const mutations = {
setSettings(state, { config }) {
state.settings = config;
},
setStatistics(state, { statistics, category }) {
if (category) {
state.statistics[category] = statistics[category];
} else {
state.statistics = statistics;
}
},
setUsers(state, { users }) {
state.users = users;
},
setUserInfo(state, { user, files }) {
state.user = { ...state.user, ...user };
state.user.files = files || [];
},
setFile(state, { file }) {
state.file = file || {};
},
changeUserState(state, { userId, enabled, isAdmin }) {
const foundIndex = state.users.findIndex(({ id }) => id === userId);
if (foundIndex > -1) {
if (enabled !== undefined) {
state.users[foundIndex].enabled = enabled;
}
if (isAdmin !== undefined) {
state.users[foundIndex].isAdmin = isAdmin;
}
}
if (state.user.id === userId) {
if (enabled !== undefined) {
state.user.enabled = enabled;
}
if (isAdmin !== undefined) {
state.user.isAdmin = isAdmin;
}
}
}
};
|