You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
929 B
39 lines
929 B
class Session {
|
|
data = {}
|
|
|
|
init(data) {
|
|
this.data = data
|
|
}
|
|
|
|
get(key) {
|
|
const parts = key.split('.')
|
|
let value = this.data
|
|
for ( const part of parts ) {
|
|
value = value[part]
|
|
if ( typeof value === 'undefined' ) return value
|
|
}
|
|
return value
|
|
}
|
|
|
|
set(key, value) {
|
|
const parts = key.split('.')
|
|
let parent = this.data
|
|
|
|
for ( const part of parts.slice(0, -1) ) {
|
|
if ( !parent[part] ) parent[part] = {}
|
|
parent = parent[part]
|
|
}
|
|
|
|
parent[parts.reverse()[0]] = value
|
|
}
|
|
|
|
async check_permissions(...permissions) {
|
|
const result = await axios.post('/api/v1/reflect/check_permissions', { permissions })
|
|
if ( permissions.length === 1 ) return result.data.data[permissions[0]]
|
|
return result.data.data
|
|
}
|
|
}
|
|
|
|
const session = new Session()
|
|
export { session }
|