Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CoreX-wg-easy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hendrik Garske
CoreX-wg-easy
Commits
037d854d
Commit
037d854d
authored
Dec 27, 2025
by
Hendrik Garske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: TypeScript-Fehler in wg-api.ts behoben
parent
85cc2200
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
wg-api.ts
lib/wg-api.ts
+32
-9
No files found.
lib/wg-api.ts
View file @
037d854d
...
@@ -56,9 +56,9 @@ export class WgApiClient {
...
@@ -56,9 +56,9 @@ export class WgApiClient {
private
async
request
<
T
>
(
endpoint
:
string
,
options
:
RequestInit
=
{}):
Promise
<
T
>
{
private
async
request
<
T
>
(
endpoint
:
string
,
options
:
RequestInit
=
{}):
Promise
<
T
>
{
const
url
=
`
${
this
.
baseUrl
}${
endpoint
}
`
const
url
=
`
${
this
.
baseUrl
}${
endpoint
}
`
const
headers
=
{
const
headers
:
Record
<
string
,
string
>
=
{
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
...
options
.
headers
,
...
(
options
.
headers
as
Record
<
string
,
string
>
||
{})
,
}
}
// Add basic auth if password is set
// Add basic auth if password is set
...
@@ -80,7 +80,24 @@ export class WgApiClient {
...
@@ -80,7 +80,24 @@ export class WgApiClient {
}
}
async
getStats
():
Promise
<
WgStats
>
{
async
getStats
():
Promise
<
WgStats
>
{
return
this
.
request
<
WgStats
>
(
'/api/sessions'
)
try
{
return
await
this
.
request
<
WgStats
>
(
'/api/sessions'
)
}
catch
(
error
)
{
// If API is not available, return empty stats
console
.
warn
(
'WG API not available, returning empty stats:'
,
error
)
return
{
clients
:
[],
server
:
{
address
:
''
,
listenPort
:
0
,
publicKey
:
''
,
endpoint
:
''
,
dns
:
''
,
allowedIPs
:
''
,
createdAt
:
new
Date
().
toISOString
(),
},
}
}
}
}
async
getClients
():
Promise
<
WgClient
[]
>
{
async
getClients
():
Promise
<
WgClient
[]
>
{
...
@@ -119,10 +136,13 @@ export class WgApiClient {
...
@@ -119,10 +136,13 @@ export class WgApiClient {
}
}
async
getClientConfig
(
id
:
string
):
Promise
<
string
>
{
async
getClientConfig
(
id
:
string
):
Promise
<
string
>
{
const
headers
:
Record
<
string
,
string
>
=
{}
if
(
this
.
password
)
{
headers
[
'Authorization'
]
=
`Basic
${
Buffer
.
from
(
`:
${
this
.
password
}
`
).
toString
(
'base64'
)}
`
}
const
response
=
await
fetch
(
`
${
this
.
baseUrl
}
/api/users/
${
id
}
/configuration`
,
{
const
response
=
await
fetch
(
`
${
this
.
baseUrl
}
/api/users/
${
id
}
/configuration`
,
{
headers
:
this
.
password
?
{
headers
,
'Authorization'
:
`Basic
${
Buffer
.
from
(
`:
${
this
.
password
}
`
).
toString
(
'base64'
)}
`
}
:
{},
})
})
if
(
!
response
.
ok
)
{
if
(
!
response
.
ok
)
{
...
@@ -133,10 +153,13 @@ export class WgApiClient {
...
@@ -133,10 +153,13 @@ export class WgApiClient {
}
}
async
getClientQR
(
id
:
string
):
Promise
<
string
>
{
async
getClientQR
(
id
:
string
):
Promise
<
string
>
{
const
headers
:
Record
<
string
,
string
>
=
{}
if
(
this
.
password
)
{
headers
[
'Authorization'
]
=
`Basic
${
Buffer
.
from
(
`:
${
this
.
password
}
`
).
toString
(
'base64'
)}
`
}
const
response
=
await
fetch
(
`
${
this
.
baseUrl
}
/api/users/
${
id
}
/qr-code`
,
{
const
response
=
await
fetch
(
`
${
this
.
baseUrl
}
/api/users/
${
id
}
/qr-code`
,
{
headers
:
this
.
password
?
{
headers
,
'Authorization'
:
`Basic
${
Buffer
.
from
(
`:
${
this
.
password
}
`
).
toString
(
'base64'
)}
`
}
:
{},
})
})
if
(
!
response
.
ok
)
{
if
(
!
response
.
ok
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment