Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Son Of Anton
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
Administrator
Son Of Anton
Commits
1e7d1256
Commit
1e7d1256
authored
Mar 29, 2026
by
Mahmoud Aglan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
يبلابيلةيلؤ
parent
fd8a1643
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
api.js
frontend/src/api.js
+11
-4
No files found.
frontend/src/api.js
View file @
1e7d1256
...
...
@@ -10,13 +10,20 @@ function authHeader(token) {
return
token
?
{
Authorization
:
`Bearer
${
token
}
`
}
:
{};
}
function
extractError
(
err
,
defaultMsg
)
{
let
msg
=
err
.
detail
||
err
.
message
||
defaultMsg
;
if
(
Array
.
isArray
(
msg
))
return
msg
.
map
(
m
=>
m
.
msg
||
JSON
.
stringify
(
m
)).
join
(
", "
);
if
(
typeof
msg
===
"object"
&&
msg
!==
null
)
return
msg
.
message
||
JSON
.
stringify
(
msg
);
return
String
(
msg
);
}
async
function
request
(
method
,
path
,
token
,
body
)
{
const
opts
=
{
method
,
headers
:
headers
(
token
)
};
if
(
body
)
opts
.
body
=
JSON
.
stringify
(
body
);
const
res
=
await
fetch
(
`
${
BASE
}${
path
}
`
,
opts
);
if
(
!
res
.
ok
)
{
const
err
=
await
res
.
json
().
catch
(()
=>
({
detail
:
res
.
statusText
}));
throw
new
Error
(
e
rr
.
detail
||
err
.
message
||
"Request failed"
);
throw
new
Error
(
e
xtractError
(
err
,
"Request failed"
)
);
}
return
res
.
json
();
}
...
...
@@ -42,7 +49,7 @@ export async function* streamMessage(token, chatId, body, signal) {
});
if
(
!
res
.
ok
)
{
const
err
=
await
res
.
json
().
catch
(()
=>
({
detail
:
res
.
statusText
}));
throw
new
Error
(
e
rr
.
detail
||
"Stream failed"
);
throw
new
Error
(
e
xtractError
(
err
,
"Stream failed"
)
);
}
const
reader
=
res
.
body
.
getReader
();
const
decoder
=
new
TextDecoder
();
...
...
@@ -72,7 +79,7 @@ export async function uploadAttachments(token, chatId, files) {
const
res
=
await
fetch
(
`
${
BASE
}
/chats/
${
chatId
}
/attachments`
,
{
method
:
"POST"
,
headers
:
authHeader
(
token
),
body
:
form
,
});
if
(
!
res
.
ok
)
{
const
err
=
await
res
.
json
().
catch
(()
=>
({}));
throw
new
Error
(
e
rr
.
detail
||
"Upload failed"
);
}
if
(
!
res
.
ok
)
{
const
err
=
await
res
.
json
().
catch
(()
=>
({}));
throw
new
Error
(
e
xtractError
(
err
,
"Upload failed"
)
);
}
return
res
.
json
();
}
export
function
getAttachmentUrl
(
attachmentId
)
{
return
`
${
BASE
}
/attachments/
${
attachmentId
}
/file`
;
}
...
...
@@ -90,7 +97,7 @@ export async function uploadDocuments(token, kbId, files) {
const
form
=
new
FormData
();
for
(
const
file
of
files
)
form
.
append
(
"files"
,
file
);
const
res
=
await
fetch
(
`
${
BASE
}
/knowledge/
${
kbId
}
/upload`
,
{
method
:
"POST"
,
headers
:
authHeader
(
token
),
body
:
form
});
if
(
!
res
.
ok
)
{
const
err
=
await
res
.
json
().
catch
(()
=>
({}));
throw
new
Error
(
e
rr
.
detail
||
"Upload failed"
);
}
if
(
!
res
.
ok
)
{
const
err
=
await
res
.
json
().
catch
(()
=>
({}));
throw
new
Error
(
e
xtractError
(
err
,
"Upload failed"
)
);
}
return
res
.
json
();
}
export
const
uploadDocument
=
(
token
,
kbId
,
file
)
=>
uploadDocuments
(
token
,
kbId
,
[
file
]);
...
...
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