File tree Expand file tree Collapse file tree 1 file changed +86
-0
lines changed Expand file tree Collapse file tree 1 file changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { WEBUI_API_BASE_URL } from '$lib/constants' ;
2
+ import { getUserPosition } from '$lib/utils' ;
3
+
4
+ export const getRoles = async ( token : string ) => {
5
+ let error = null ;
6
+
7
+ const res = await fetch ( `${ WEBUI_API_BASE_URL } /roles` , {
8
+ method : 'GET' ,
9
+ headers : {
10
+ 'Content-Type' : 'application/json' ,
11
+ Authorization : `Bearer ${ token } `
12
+ }
13
+ } )
14
+ . then ( async ( res ) => {
15
+ if ( ! res . ok ) throw await res . json ( ) ;
16
+ return res . json ( ) ;
17
+ } )
18
+ . catch ( ( err ) => {
19
+ console . log ( err ) ;
20
+ error = err . detail ;
21
+ return null ;
22
+ } ) ;
23
+
24
+ if ( error ) {
25
+ throw error ;
26
+ }
27
+
28
+ return res ;
29
+ } ;
30
+
31
+ export const addRole = async ( token : string , role : string ) => {
32
+ let error = null ;
33
+
34
+ const res = await fetch ( `${ WEBUI_API_BASE_URL } /roles` , {
35
+ method : 'POST' ,
36
+ headers : {
37
+ 'Content-Type' : 'application/json' ,
38
+ Authorization : `Bearer ${ token } `
39
+ } ,
40
+ body : JSON . stringify ( {
41
+ role : role
42
+ } )
43
+ } )
44
+ . then ( async ( res ) => {
45
+ if ( ! res . ok ) throw await res . json ( ) ;
46
+ return res . json ( ) ;
47
+ } )
48
+ . catch ( ( err ) => {
49
+ console . log ( err ) ;
50
+ error = err . detail ;
51
+ return null ;
52
+ } ) ;
53
+
54
+ if ( error ) {
55
+ throw error ;
56
+ }
57
+
58
+ return res ;
59
+ } ;
60
+
61
+ export const deleteRole = async ( token : string , roleId : string ) => {
62
+ let error = null ;
63
+
64
+ const res = await fetch ( `${ WEBUI_API_BASE_URL } /roles/${ roleId } ` , {
65
+ method : 'DELETE' ,
66
+ headers : {
67
+ 'Content-Type' : 'application/json' ,
68
+ Authorization : `Bearer ${ token } `
69
+ } ,
70
+ } )
71
+ . then ( async ( res ) => {
72
+ if ( ! res . ok ) throw await res . json ( ) ;
73
+ return res . json ( ) ;
74
+ } )
75
+ . catch ( ( err ) => {
76
+ console . log ( err ) ;
77
+ error = err . detail ;
78
+ return null ;
79
+ } ) ;
80
+
81
+ if ( error ) {
82
+ throw error ;
83
+ }
84
+
85
+ return res ;
86
+ } ;
You can’t perform that action at this time.
0 commit comments