Skip to content

Commit c31b147

Browse files
committed
Working version for creating and editing requests
1 parent 873682e commit c31b147

File tree

9 files changed

+158
-84
lines changed

9 files changed

+158
-84
lines changed

internal/webserver/api/Api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ func apiURequestSave(w http.ResponseWriter, r requestParser, user models.User) {
788788
}
789789
uploadRequest := models.FileRequest{}
790790

791-
if !request.IsNewRequest {
791+
if request.Id != 0 {
792792
uploadRequest, ok = database.GetFileRequest(request.Id)
793793
if !ok {
794794
sendError(w, http.StatusNotFound, "FileRequest does not exist with the given ID")

internal/webserver/api/routing.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ type paramURequestSave struct {
581581
Expiry int64 `header:"expiry"`
582582
MaxFiles int `header:"maxfiles"`
583583
MaxSize int `header:"maxsize"`
584-
IsNewRequest bool
585584
IsNameSet bool
586585
IsExpirySet bool
587586
IsMaxFilesSet bool
@@ -591,9 +590,6 @@ type paramURequestSave struct {
591590
}
592591

593592
func (p *paramURequestSave) ProcessParameter(_ *http.Request) error {
594-
if !p.foundHeaders["id"] {
595-
p.IsNewRequest = true
596-
}
597593
if p.foundHeaders["name"] {
598594
p.IsNameSet = true
599595
}
@@ -606,6 +602,13 @@ func (p *paramURequestSave) ProcessParameter(_ *http.Request) error {
606602
if p.foundHeaders["maxsize"] {
607603
p.IsMaxSizeSet = true
608604
}
605+
if strings.HasPrefix(p.Name, base64Prefix) {
606+
decoded, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(p.Name, base64Prefix))
607+
if err != nil {
608+
return err
609+
}
610+
p.Name = string(decoded)
611+
}
609612
return nil
610613
}
611614

internal/webserver/web/static/apidocumentation/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@
10681068
{
10691069
"name": "name",
10701070
"in": "header",
1071-
"description": "The given name for the request",
1071+
"description": "The given name for the request. If the name includes non-ANSI characters, you can encode them with base64, by adding 'base64:' at the beginning, e.g. 'base64:ZmlsZW5hbWU='",
10721072
"required": false,
10731073
"style": "simple",
10741074
"explode": false,

internal/webserver/web/static/js/admin_api.js

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function getToken(permission, forceRenewal) {
5151
async function apiAuthModify(apiKey, permission, modifier) {
5252
const apiUrl = './api/auth/modify';
5353
const reqPerm = 'PERM_API_MOD';
54-
54+
5555
let token;
5656

5757
try {
@@ -88,7 +88,7 @@ async function apiAuthModify(apiKey, permission, modifier) {
8888
async function apiAuthFriendlyName(apiKey, newName) {
8989
const apiUrl = './api/auth/friendlyname';
9090
const reqPerm = 'PERM_API_MOD';
91-
91+
9292
let token;
9393

9494
try {
@@ -124,7 +124,7 @@ async function apiAuthFriendlyName(apiKey, newName) {
124124
async function apiAuthDelete(apiKey) {
125125
const apiUrl = './api/auth/delete';
126126
const reqPerm = 'PERM_API_MOD';
127-
127+
128128
let token;
129129

130130
try {
@@ -158,7 +158,7 @@ async function apiAuthDelete(apiKey) {
158158
async function apiAuthCreate() {
159159
const apiUrl = './api/auth/create';
160160
const reqPerm = 'PERM_API_MOD';
161-
161+
162162
let token;
163163

164164
try {
@@ -199,7 +199,7 @@ async function apiAuthCreate() {
199199
async function apiChunkComplete(uuid, filename, filesize, realsize, contenttype, allowedDownloads, expiryDays, password, isE2E, nonblocking) {
200200
const apiUrl = './api/chunk/complete';
201201
const reqPerm = 'PERM_UPLOAD';
202-
202+
203203
let token;
204204

205205
try {
@@ -258,7 +258,7 @@ async function apiChunkComplete(uuid, filename, filesize, realsize, contenttype,
258258
async function apiFilesReplace(id, newId) {
259259
const apiUrl = './api/files/replace';
260260
const reqPerm = 'PERM_REPLACE';
261-
261+
262262
let token;
263263

264264
try {
@@ -295,7 +295,7 @@ async function apiFilesReplace(id, newId) {
295295
async function apiFilesListById(fileId) {
296296
const apiUrl = './api/files/list/' + fileId;
297297
const reqPerm = 'PERM_VIEW';
298-
298+
299299
let token;
300300

301301
try {
@@ -304,7 +304,7 @@ async function apiFilesListById(fileId) {
304304
console.error("Unable to gain permission token:", error);
305305
throw error;
306306
}
307-
307+
308308
const requestOptions = {
309309
method: 'GET',
310310
headers: {
@@ -331,7 +331,7 @@ async function apiFilesListById(fileId) {
331331
async function apiFilesModify(id, allowedDownloads, expiry, password, originalPw) {
332332
const apiUrl = './api/files/modify';
333333
const reqPerm = 'PERM_EDIT';
334-
334+
335335
let token;
336336

337337
try {
@@ -371,7 +371,7 @@ async function apiFilesModify(id, allowedDownloads, expiry, password, originalPw
371371
async function apiFilesDelete(id, delay) {
372372
const apiUrl = './api/files/delete';
373373
const reqPerm = 'PERM_DELETE';
374-
374+
375375
let token;
376376

377377
try {
@@ -406,7 +406,7 @@ async function apiFilesDelete(id, delay) {
406406
async function apiFilesRestore(id) {
407407
const apiUrl = './api/files/restore';
408408
const reqPerm = 'PERM_DELETE';
409-
409+
410410
let token;
411411

412412
try {
@@ -446,7 +446,7 @@ async function apiFilesRestore(id) {
446446
async function apiUserCreate(userName) {
447447
const apiUrl = './api/user/create';
448448
const reqPerm = 'PERM_MANAGE_USERS';
449-
449+
450450
let token;
451451

452452
try {
@@ -486,7 +486,7 @@ async function apiUserCreate(userName) {
486486
async function apiUserModify(userId, permission, modifier) {
487487
const apiUrl = './api/user/modify';
488488
const reqPerm = 'PERM_MANAGE_USERS';
489-
489+
490490
let token;
491491

492492
try {
@@ -523,7 +523,7 @@ async function apiUserModify(userId, permission, modifier) {
523523
async function apiUserChangeRank(userId, newRank) {
524524
const apiUrl = './api/user/changeRank';
525525
const reqPerm = 'PERM_MANAGE_USERS';
526-
526+
527527
let token;
528528

529529
try {
@@ -558,7 +558,7 @@ async function apiUserChangeRank(userId, newRank) {
558558
async function apiUserDelete(id, deleteFiles) {
559559
const apiUrl = './api/user/delete';
560560
const reqPerm = 'PERM_MANAGE_USERS';
561-
561+
562562
let token;
563563

564564
try {
@@ -594,7 +594,7 @@ async function apiUserDelete(id, deleteFiles) {
594594
async function apiUserResetPassword(id, generatePw) {
595595
const apiUrl = './api/user/resetPassword';
596596
const reqPerm = 'PERM_MANAGE_USERS';
597-
597+
598598
let token;
599599

600600
try {
@@ -632,7 +632,7 @@ async function apiUserResetPassword(id, generatePw) {
632632
async function apiLogsDelete(timestamp) {
633633
const apiUrl = './api/logs/delete';
634634
const reqPerm = 'PERM_MANAGE_LOGS';
635-
635+
636636
let token;
637637

638638
try {
@@ -668,7 +668,7 @@ async function apiLogsDelete(timestamp) {
668668
async function apiE2eGet() {
669669
const apiUrl = './api/e2e/get';
670670
const reqPerm = 'PERM_UPLOAD';
671-
671+
672672
let token;
673673

674674
try {
@@ -703,7 +703,7 @@ async function apiE2eGet() {
703703
async function apiE2eStore(content) {
704704
const apiUrl = './api/e2e/set';
705705
const reqPerm = 'PERM_UPLOAD';
706-
706+
707707
let token;
708708

709709
try {
@@ -735,10 +735,13 @@ async function apiE2eStore(content) {
735735
}
736736
}
737737

738+
739+
// Upload Requests
740+
738741
async function apiURequestDelete(id) {
739742
const apiUrl = './api/uploadrequest/delete';
740743
const reqPerm = 'PERM_MANAGE_FILE_REQUESTS';
741-
744+
742745
let token;
743746

744747
try {
@@ -767,3 +770,44 @@ async function apiURequestDelete(id) {
767770
throw error;
768771
}
769772
}
773+
774+
775+
776+
async function apiURequestSave(id, name, maxfiles, maxsize, expiry) {
777+
const apiUrl = './api/uploadrequest/save';
778+
const reqPerm = 'PERM_MANAGE_FILE_REQUESTS';
779+
780+
let token;
781+
782+
try {
783+
token = await getToken(reqPerm, false);
784+
} catch (error) {
785+
console.error("Unable to gain permission token:", error);
786+
throw error;
787+
}
788+
789+
const requestOptions = {
790+
method: 'POST',
791+
headers: {
792+
'Content-Type': 'application/json',
793+
'apikey': token,
794+
'id': id,
795+
'name': 'base64:' + Base64.encode(name),
796+
'expiry': expiry,
797+
'maxfiles': maxfiles,
798+
'maxsize': maxsize
799+
},
800+
};
801+
802+
try {
803+
const response = await fetch(apiUrl, requestOptions);
804+
if (!response.ok) {
805+
throw new Error(`Request failed with status: ${response.status}`);
806+
}
807+
const data = await response.json();
808+
return data;
809+
} catch (error) {
810+
console.error("Error in apiURequestDelete:", error);
811+
throw error;
812+
}
813+
}

0 commit comments

Comments
 (0)