Simplify api and clean zh_cn lang file

This commit is contained in:
Henrique Dias 2017-08-01 08:31:28 +01:00
parent 68c31eb8fa
commit 02b9d9f54b
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
4 changed files with 49 additions and 88 deletions

View File

@ -40,7 +40,7 @@
<script> <script>
import { mapState, mapMutations } from 'vuex' import { mapState, mapMutations } from 'vuex'
import api from '@/utils/api' import { getSettings, updateSettings } from '@/utils/api'
export default { export default {
name: 'settings', name: 'settings',
@ -54,24 +54,20 @@ export default {
...mapState([ 'user' ]) ...mapState([ 'user' ])
}, },
created () { created () {
api.getCommands() getSettings()
.then(commands => { .then(settings => {
for (let key in commands) { for (let key in settings.plugins) {
this.plugins.push(this.parsePlugin(key, settings.plugins[key]))
}
for (let key in settings.commands) {
this.commands.push({ this.commands.push({
name: key, name: key,
value: commands[key].join('\n') value: settings.commands[key].join('\n')
}) })
} }
}) })
.catch(error => { this.showError(error) }) .catch(error => { this.showError(error) })
api.getPlugins()
.then(plugins => {
for (let key in plugins) {
this.plugins.push(this.parsePlugin(key, plugins[key]))
}
})
.catch(error => { this.showError(error) })
}, },
methods: { methods: {
...mapMutations([ 'showSuccess', 'showError' ]), ...mapMutations([ 'showSuccess', 'showError' ]),
@ -100,7 +96,7 @@ export default {
commands[command.name] = value commands[command.name] = value
} }
api.updateCommands(commands) updateSettings(commands, 'commands')
.then(() => { this.showSuccess(this.$t('settings.commandsUpdated')) }) .then(() => { this.showSuccess(this.$t('settings.commandsUpdated')) })
.catch(error => { this.showError(error) }) .catch(error => { this.showError(error) })
}, },
@ -127,9 +123,7 @@ export default {
plugins[plugin.name] = p plugins[plugin.name] = p
} }
console.log(plugins) updateSettings(plugins, 'plugins')
api.updatePlugins(plugins)
.then(() => { this.showSuccess(this.$t('settings.pluginsUpdated')) }) .then(() => { this.showSuccess(this.$t('settings.pluginsUpdated')) })
.catch(error => { this.showError(error) }) .catch(error => { this.showError(error) })
}, },

View File

@ -71,7 +71,7 @@ prompts:
downloadMessage: 请选择要下载的压缩格式. downloadMessage: 请选择要下载的压缩格式.
error: 出了一点问题... error: 出了一点问题...
fileInfo: 文件信息 fileInfo: 文件信息
filesSelected: "选择 {count} 个文件." filesSelected: '选择 {count} 个文件.'
lastModified: 最后修改 lastModified: 最后修改
move: 移动 move: 移动
moveMessage: '请选择欲移动至的目录:' moveMessage: '请选择欲移动至的目录:'
@ -82,7 +82,7 @@ prompts:
numberDirs: 目录数 numberDirs: 目录数
numberFiles: 文件数 numberFiles: 文件数
rename: 重命名 rename: 重命名
renameMessage: 请输入新名称, 旧名称是: renameMessage: '请输入新名称, 旧名称是:'
size: 大小 size: 大小
settings: settings:
admin: 管理员 admin: 管理员
@ -90,12 +90,13 @@ settings:
allowCommands: 执行命令(Linux 代码) allowCommands: 执行命令(Linux 代码)
allowEdit: 编辑、重命名或删除文件/目录. allowEdit: 编辑、重命名或删除文件/目录.
allowNew: 创建新文件和目录. allowNew: 创建新文件和目录.
avoidChanges: "(留空以避免更改)" avoidChanges: '(留空以避免更改)'
changePassword: 更改密码 changePassword: 更改密码
commands: 命令(linux 代码) commands: 命令(linux 代码)
commandsHelp: Here you can set commands that are executed in the named events. commandsHelp: >
每行一条命令. If the event is related to files, such as before and after saving, 'Here you can set commands that are executed in the named events.
the environment variable "file" will be available with the path of the file. 每行一条命令. If the event is related to files, such as before and after saving,
the environment variable "file" will be available with the path of the file.'
commandsUpdated: 命令更新! commandsUpdated: 命令更新!
customStylesheet: 自定义样式表 customStylesheet: 自定义样式表
examples: 例子 examples: 例子
@ -108,19 +109,20 @@ settings:
passwordUpdated: 密码更新! passwordUpdated: 密码更新!
permissions: 权限 permissions: 权限
permissionsHelp: > permissionsHelp: >
'您可以将该用户设置为管理员 或单独选择各项权限. 如果选择 "管理员(Administrator)" , '您可以将该用户设置为管理员 或单独选择各项权限. 如果选择 "管理员(Administrator)" ,
将自动检查所有其他选项, 并且该用户可以管理其他用户.' 将自动检查所有其他选项, 并且该用户可以管理其他用户.'
pluginsUpdated: 插件设置更新! pluginsUpdated: 插件设置更新!
profileSettings: 配置文件设置 profileSettings: 配置文件设置
ruleExample1: > ruleExample1: >
'阻止用户访问每个文件夹下任何以 . 开头的文件(隐藏文件, 例如: .git, .gitignore).' '阻止用户访问每个文件夹下任何以 . 开头的文件(隐藏文件, 例如: .git, .gitignore).'
ruleExample2: 阻止用户访问其目录范围内任何名为 Caddyfile 的文件/文件夹. ruleExample2: 阻止用户访问其目录范围内任何名为 Caddyfile 的文件/文件夹.
rules: 规则 rules: 规则
rulesHelp1: > rulesHelp1: >
'这里您可以为特定用户制定一组允许或不允许的规则, '这里您可以为特定用户制定一组允许或不允许的规则,
阻止的文件将不会显示到列表中, 用户将无法访问, 支持相对于用户的范围.' 阻止的文件将不会显示到列表中, 用户将无法访问, 支持相对于用户的范围.'
rulesHelp2: 每行一条规则, 必须以关键词 {0} 或 {1} 开头. 如果使用正则表达式, rulesHelp2: >
然后使用表达式或路径, 则需要在第二列单词加入 {2} . 每行一条规则, 必须以关键词 {0} 或 {1} 开头. 如果使用正则表达式,
然后使用表达式或路径, 则需要在第二列单词加入 {2} .
scope: 目录范围 scope: 目录范围
stylesUpdated: 样式更新! stylesUpdated: 样式更新!
user: 用户 user: 用户

View File

@ -203,10 +203,10 @@ export function download (format, ...files) {
window.open(url) window.open(url)
} }
export function getCommands () { export function getSettings () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let request = new window.XMLHttpRequest() let request = new window.XMLHttpRequest()
request.open('GET', `${store.state.baseURL}/api/commands/`, true) request.open('GET', `${store.state.baseURL}/api/settings/`, true)
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`) request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
request.onload = () => { request.onload = () => {
@ -224,10 +224,18 @@ export function getCommands () {
}) })
} }
export function updateCommands (commands) { export function updateSettings (param, which) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = {
what: 'settings',
which: which,
data: {}
}
data.data[which] = param
let request = new window.XMLHttpRequest() let request = new window.XMLHttpRequest()
request.open('PUT', `${store.state.baseURL}/api/commands/`, true) request.open('PUT', `${store.state.baseURL}/api/settings/`, true)
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`) request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
request.onload = () => { request.onload = () => {
@ -240,49 +248,7 @@ export function updateCommands (commands) {
break break
} }
} }
request.onerror = (error) => reject(error) request.onerror = (error) => { reject(error) }
request.send(JSON.stringify(commands))
})
}
export function getPlugins () {
return new Promise((resolve, reject) => {
let request = new window.XMLHttpRequest()
request.open('GET', `${store.state.baseURL}/api/plugins/`, true)
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
request.onload = () => {
switch (request.status) {
case 200:
resolve(JSON.parse(request.responseText))
break
default:
reject(request.responseText)
break
}
}
request.onerror = (error) => reject(error)
request.send()
})
}
export function updatePlugins (data) {
return new Promise((resolve, reject) => {
let request = new window.XMLHttpRequest()
request.open('PUT', `${store.state.baseURL}/api/plugins/`, true)
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
request.onload = () => {
switch (request.status) {
case 200:
resolve()
break
default:
reject(request.responseText)
break
}
}
request.onerror = (error) => reject(error)
request.send(JSON.stringify(data)) request.send(JSON.stringify(data))
}) })
} }
@ -411,10 +377,8 @@ export default {
search, search,
download, download,
// other things // other things
getCommands, getSettings,
updateCommands, updateSettings,
getPlugins,
updatePlugins,
// User things // User things
newUser, newUser,
getUser, getUser,

View File

@ -16,11 +16,6 @@ type modifySettingsRequest struct {
} `json:"data"` } `json:"data"`
} }
type settingsGetRequest struct {
Commands map[string][]string `json:"commands"`
Plugins map[string][]pluginOption `json:"plugins"`
}
type pluginOption struct { type pluginOption struct {
Variable string `json:"variable"` Variable string `json:"variable"`
Name string `json:"name"` Name string `json:"name"`
@ -49,7 +44,7 @@ func parsePutSettingsRequest(r *http.Request) (*modifySettingsRequest, error) {
} }
func settingsHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) { func settingsHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
if r.URL.Path != "" { if r.URL.Path != "" && r.URL.Path != "/" {
return http.StatusNotFound, nil return http.StatusNotFound, nil
} }
@ -63,6 +58,11 @@ func settingsHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
return http.StatusMethodNotAllowed, nil return http.StatusMethodNotAllowed, nil
} }
type settingsGetRequest struct {
Commands map[string][]string `json:"commands"`
Plugins map[string][]pluginOption `json:"plugins"`
}
func settingsGetHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) { func settingsGetHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
if !c.User.Admin { if !c.User.Admin {
return http.StatusForbidden, nil return http.StatusForbidden, nil
@ -98,7 +98,7 @@ func settingsPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Reques
if err != nil { if err != nil {
return http.StatusBadRequest, err return http.StatusBadRequest, err
} }
// Update the commands.
if mod.Which == "commands" { if mod.Which == "commands" {
if err := c.FM.db.Set("config", "commands", mod.Data.Commands); err != nil { if err := c.FM.db.Set("config", "commands", mod.Data.Commands); err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
@ -108,6 +108,7 @@ func settingsPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Reques
return http.StatusOK, nil return http.StatusOK, nil
} }
// Update the plugins.
if mod.Which == "plugins" { if mod.Which == "plugins" {
for name, plugin := range mod.Data.Plugins { for name, plugin := range mod.Data.Plugins {
err = mapstructure.Decode(plugin, c.FM.Plugins[name]) err = mapstructure.Decode(plugin, c.FM.Plugins[name])