Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
424eb12
Refactoring, added request url
Forceu Jul 28, 2025
55ded88
Merge branch 'master' into guestupload
Forceu Sep 7, 2025
0826a01
Merge branch 'master' into guestupload
Forceu Nov 5, 2025
d3aee21
Added migration for new file request user permission, added permissio…
Forceu Dec 1, 2025
0b00d5a
Make user permission buttons dynamic for new user instead of hard cod…
Forceu Dec 1, 2025
862e3c0
Merge branch 'master' into guestupload
Forceu Dec 1, 2025
0872801
Added API permission PERM_MANAGE_FILE_REQUESTS
Forceu Dec 1, 2025
90e6060
Merge branch 'master' into guestupload
Forceu Dec 4, 2025
60fd353
Fixed API button UI/JS
Forceu Dec 4, 2025
dc7d9e6
Added database table operation for file requests, added basic overvie…
Forceu Dec 12, 2025
b8f13d4
Populate info on overview, disallow regular download, sort requests
Forceu Dec 13, 2025
0399740
Don't allow downloads with hotlink URLs, reordered header menu, impro…
Forceu Dec 13, 2025
decd5cb
Added api/filerequest/delete and possibly fixed /e2e/set call
Forceu Dec 16, 2025
8d23de5
Implementation of delete button, possible fix /e2e/set?
Forceu Dec 17, 2025
1690e17
Refactoring, clean api keys and file requests with invalid users, mak…
Forceu Dec 19, 2025
185cdd6
Merge branch 'master' into guestupload
Forceu Dec 20, 2025
1817bf7
Changed admin JS version to 15 to avoid conflicts
Forceu Dec 20, 2025
5fa7d04
Fixed sqlite upgrade
Forceu Dec 20, 2025
ee92156
Fix UI and JS
Forceu Dec 21, 2025
77f9986
Delete or migrate file request when user is deleted
Forceu Dec 27, 2025
cfd3c64
Add modal for creating / editing file requests (not functional yet)
Forceu Dec 27, 2025
23dad2c
Change db version to 12
Forceu Dec 29, 2025
e8ef6f5
Merge branch 'master' into guestupload
Forceu Dec 29, 2025
e8f5601
Use browser TZ for file request times
Forceu Dec 29, 2025
5d10d5d
Added Total size column, display max files in table as well
Forceu Dec 29, 2025
9e8a4b1
Added API call to edit and create file requests, improved openapi
Forceu Dec 29, 2025
30539b8
Added API call for listing file requests, fixed errors in openapi.json
Forceu Dec 29, 2025
5c60acc
Formatting
Forceu Dec 29, 2025
240b2b6
Save defaults for new FR (date not working yet), copied openapi.json
Forceu Dec 29, 2025
873682e
Working date picker, formatting
Forceu Dec 29, 2025
c31b147
Working version for creating and editing requests
Forceu Dec 29, 2025
03fa4c2
Working add/update UI for file requests
Forceu Dec 29, 2025
54c771b
Add API call to download files and optionally not increasing counter,…
Forceu Dec 30, 2025
25a3b87
Added option for presigned URLs and add download button in main menu
Forceu Dec 30, 2025
701130a
Don't allow download for e2e encrypted files
Forceu Dec 30, 2025
86ba188
Added file IDs to API UR output, added autocomplete hint to login form
Forceu Dec 30, 2025
25ab29b
Working download if only one file is uploaded to file request, indica…
Forceu Dec 30, 2025
b9e86a6
Working implementation of zipping files, add base64 decoding for head…
Forceu Dec 31, 2025
571e018
Download all working now in UI
Forceu Dec 31, 2025
de4b483
Add logging for file requests
Forceu Dec 31, 2025
f80f49e
Merge branch 'master' into guestupload
Forceu Dec 31, 2025
94b822f
Create api key for new file request, don't allow file request api key…
Forceu Jan 1, 2026
49aaa99
Merge branch 'master' into guestupload
Forceu Jan 1, 2026
4500d04
Fixed creation date not being saved for file request, updated openapi
Forceu Jan 1, 2026
260bbab
Refactoring
Forceu Jan 1, 2026
bc0afcf
Refactoring, fixed GetAll() not populating files, added placeholder f…
Forceu Jan 2, 2026
b61d914
Working file list for file requests
Forceu Jan 2, 2026
70917e2
Fixed file request expiry defaults
Forceu Jan 2, 2026
20fc632
Improved file view ui
Forceu Jan 2, 2026
f3905e3
Merge branch 'master' into guestupload
Forceu Jan 2, 2026
4a2abde
Merge branch 'master' into guestupload
Forceu Jan 2, 2026
c21a4f5
Changed file request ID to string type, updated openapi
Forceu Jan 3, 2026
cc59fff
Implemented API calls for uploading files as file request
Forceu Jan 6, 2026
3fad4c2
First working prototype
Forceu Jan 6, 2026
c4f5a1e
Check for max file count and expiry
Forceu Jan 6, 2026
c87c23f
Add URL to JS on new file request, fixed race condition
Forceu Jan 6, 2026
315fb51
Merge branch 'master' into guestupload
Forceu Jan 6, 2026
b314fa3
Fixed logs for file requests and fixed some tests
Forceu Jan 6, 2026
de36c1b
Fixed JSON output for chunkcomplete, fixed tests
Forceu Jan 6, 2026
f315b3b
Fixed tests
Forceu Jan 6, 2026
96f975d
Refactoring JS, adding note for upload requests, better view for publ…
Forceu Jan 7, 2026
3a9639f
Show icon button for expanding instead of clickable file number, add …
Forceu Jan 7, 2026
3a79f40
Add delete button for files to be uploaded
Forceu Jan 7, 2026
bd8385b
Merge branch 'master' into guestupload
Forceu Jan 12, 2026
f464ecb
Merge branch 'master' into guestupload
Forceu Jan 12, 2026
421e254
Merge branch 'master' into guestupload
Forceu Jan 12, 2026
725d264
Fixed DB upgrade, working prototype for upload page
Forceu Jan 12, 2026
3944206
Merge branch 'master' into guestupload
Forceu Jan 14, 2026
4d66e5c
Merge branch 'master' into guestupload
Forceu Jan 14, 2026
867dbd6
Change api name
Forceu Jan 14, 2026
00b82b9
Added chunk reservation system for public uploads, fixed openapi
Forceu Jan 15, 2026
c0f1abd
Fixed tests
Forceu Jan 15, 2026
0a2ca7f
Add download option for gokapi-cli, TODO: error on e2e
Forceu Jan 18, 2026
335f204
Remove file after upload if requested, output json result
Forceu Jan 19, 2026
15af392
Better error page
Forceu Jan 19, 2026
7ab8bfc
Changed wording, fixed tests
Forceu Jan 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions build/go-generate/minifyStaticContent.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,10 @@ func getPaths() []converter {
Name: "wasm_exec JS",
})
result = append(result, converter{
InputPath: pathPrefix + "js/dateformat.js",
OutputPath: pathPrefix + "js/min/dateformat.min.js",
InputPath: pathPrefix + "js/all_public.js",
OutputPath: pathPrefix + "js/min/all_public.min.js",
Type: "text/javascript",
Name: "Dateformat JS",
})
result = append(result, converter{
InputPath: pathPrefix + "js/uuid.js",
OutputPath: pathPrefix + "js/min/uuid.min.js",
Type: "text/javascript",
Name: "UUID JS",
Name: "Public functions JS",
})
return result
}
Expand Down
58 changes: 45 additions & 13 deletions build/go-generate/updateApiRouting.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,28 @@ func hasRequiredTag(tags []string) bool {
return false
}

func headerExists(headerName string, required, isString bool) string {
func hasBase64Tag(tags []string) bool {
// Check if the tag contains "supportBase64:true"
for _, tag := range tags {
if strings.HasPrefix(tag, "supportBase64") {
return true
}
}
return false
}

func headerExists(headerName string, required, isString, base64Support bool) string {
base64SupportEntry := ""
if base64Support {
base64SupportEntry = ", has base64support"
}
return fmt.Sprintf("\n"+`
// RequestParser header value %s, required: %v
// RequestParser header value %s, required: %v%s
exists, err = checkHeaderExists(r, %s, %v, %v)
if err != nil {
return err
}
p.foundHeaders[%s] = exists`, headerName, required, headerName, required, isString, headerName)
p.foundHeaders[%s] = exists`, headerName, required, base64SupportEntry, headerName, required, isString, headerName)
}

func generateParseRequestMethod(typeName string, fields []*ast.Field) string {
Expand Down Expand Up @@ -122,25 +136,41 @@ func generateParseRequestMethod(typeName string, fields []*ast.Field) string {
// Check if the tag has the "header" key and extract its value
tagParts := strings.Split(tag, " ")
required := hasRequiredTag(tagParts)
base64Support := hasBase64Tag(tagParts)
for _, part := range tagParts {
if strings.HasPrefix(part, "header:") {
// Extract header name after 'header:'
// Extract the header name after 'header:'
headerName := strings.TrimPrefix(part, "header:")

fieldType := field.Type.(*ast.Ident).Name

// Use appropriate parsing function based on the field type
// Use the appropriate parsing function based on the field type
switch fieldType {
case "string":
method += headerExists(headerName, required, true)
method += fmt.Sprintf(`
if (exists) {
p.%s = r.Header.Get(%s)
method += headerExists(headerName, required, true, base64Support)
if !base64Support {
method += fmt.Sprintf(`
if (exists) {
p.%s = r.Header.Get(%s)
}
`, field.Names[0].Name, headerName)
} else {
method += fmt.Sprintf(`
if (exists) {
p.%s = r.Header.Get(%s)
if strings.HasPrefix(p.%s, "base64:") {
decoded, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(p.%s, "base64:"))
if err != nil {
return err
}
p.%s = string(decoded)
}
}
`, field.Names[0].Name, headerName, field.Names[0].Name, field.Names[0].Name, field.Names[0].Name)
}
`, field.Names[0].Name, headerName)

case "bool":
method += headerExists(headerName, required, false)
method += headerExists(headerName, required, false, false)
method += fmt.Sprintf(`
if (exists) {
p.%s, err = parseHeaderBool(r, %s)
Expand All @@ -151,7 +181,7 @@ func generateParseRequestMethod(typeName string, fields []*ast.Field) string {
`, field.Names[0].Name, headerName, strings.Replace(headerName, "\"", "", -1))

case "int":
method += headerExists(headerName, required, false)
method += headerExists(headerName, required, false, false)
method += fmt.Sprintf(`
if (exists) {
p.%s, err = parseHeaderInt(r, %s)
Expand All @@ -162,7 +192,7 @@ func generateParseRequestMethod(typeName string, fields []*ast.Field) string {
`, field.Names[0].Name, headerName, strings.Replace(headerName, "\"", "", -1))

case "int64":
method += headerExists(headerName, required, false)
method += headerExists(headerName, required, false, false)
method += fmt.Sprintf(`
if (exists) {
p.%s, err = parseHeaderInt64(r, %s)
Expand Down Expand Up @@ -236,8 +266,10 @@ func main() {
package api

import (
"encoding/base64"
"fmt"
"net/http"
"strings"
)

// Do not modify: This is an automatically generated file created by updateApiRouting.go
Expand Down
10 changes: 8 additions & 2 deletions build/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,30 @@ require (
golang.org/x/oauth2 v0.27.0
golang.org/x/sync v0.11.0
golang.org/x/term v0.37.0
golang.org/x/time v0.14.0
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.35.0
)

require (
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
github.com/djherbis/atime v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
github.com/tdewolff/minify/v2 v2.24.2 // indirect
github.com/tdewolff/parse/v2 v2.8.3 // indirect
github.com/tdewolff/argp v0.0.0-20250430135133-0f54527d2b1e // indirect
github.com/tdewolff/minify/v2 v2.24.8 // indirect
github.com/tdewolff/parse/v2 v2.8.5 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.shabbyrobe.org/gocovmerge v0.0.0-20230507111327-fa4f82cfbf4d // indirect
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
Expand Down
12 changes: 12 additions & 0 deletions build/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
Expand All @@ -8,21 +9,28 @@ github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5
github.com/cevatbarisyilmaz/ara v0.0.4/go.mod h1:BfFOxnUd6Mj6xmcvRxHN3Sr21Z1T3U2MYkYOmoQe4Ts=
github.com/coreos/go-oidc/v3 v3.12.0/go.mod h1:gE3LgjOgFoHi9a4ce4/tJczr0Ai2/BoDhf0r5lltWI0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/djherbis/atime v1.1.0/go.mod h1:28OF6Y8s3NQWwacXc5eZTsEsiMzp7LF8MbXE+XJPdBE=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/johannesboyne/gofakes3 v0.0.0-20250106100439-5c39aecd6999/go.mod h1:t6osVdP++3g4v2awHz4+HFccij23BbdT1rX3W7IijqQ=
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
Expand All @@ -34,12 +42,15 @@ github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tdewolff/argp v0.0.0-20250430135133-0f54527d2b1e/go.mod h1:xw2b1X81m4zY1OGytzHNr/YKXbf/STHkK5idoNamlYE=
github.com/tdewolff/minify/v2 v2.23.11 h1:cZqTVCtuVvPC8/GbCvYgIcdAQGmoxEObZzKeKIUixTE=
github.com/tdewolff/minify/v2 v2.23.11/go.mod h1:vmkbfGQ5hp/eYB+TswNWKma67S0a+32HBL+mFWxjZ2Q=
github.com/tdewolff/minify/v2 v2.24.2/go.mod h1:1JrCtoZXaDbqioQZfk3Jdmr0GPJKiU7c1Apmb+7tCeE=
github.com/tdewolff/minify/v2 v2.24.8/go.mod h1:0Ukj0CRpo/sW/nd8uZ4ccXaV1rEVIWA3dj8U7+Shhfw=
github.com/tdewolff/parse/v2 v2.8.2-0.20250806174018-50048bb39781 h1:2qicgFovKg1XtX7Wf6GwexUdpb7q/jMIE2IgkYsVAvE=
github.com/tdewolff/parse/v2 v2.8.2-0.20250806174018-50048bb39781/go.mod h1:Hwlni2tiVNKyzR1o6nUs4FOF07URA+JLBLd6dlIXYqo=
github.com/tdewolff/parse/v2 v2.8.3/go.mod h1:Hwlni2tiVNKyzR1o6nUs4FOF07URA+JLBLd6dlIXYqo=
github.com/tdewolff/parse/v2 v2.8.5/go.mod h1:Hwlni2tiVNKyzR1o6nUs4FOF07URA+JLBLd6dlIXYqo=
github.com/tdewolff/test v1.0.11 h1:FdLbwQVHxqG16SlkGveC0JVyrJN62COWTRyUFzfbtBE=
github.com/tdewolff/test v1.0.11/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down Expand Up @@ -96,6 +107,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190829051458-42f498d34c4d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
39 changes: 30 additions & 9 deletions cmd/cli-uploader/Main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"

"github.com/forceu/gokapi/cmd/cli-uploader/cliapi"
"github.com/forceu/gokapi/cmd/cli-uploader/cliconfig"
"github.com/forceu/gokapi/cmd/cli-uploader/cliconstants"
"github.com/forceu/gokapi/cmd/cli-uploader/cliflags"
"github.com/forceu/gokapi/internal/environment"
"github.com/forceu/gokapi/internal/helper"
"github.com/schollz/progressbar/v3"
"io"
"os"
"path/filepath"
)

func main() {
Expand All @@ -25,9 +26,11 @@ func main() {
case cliflags.ModeLogout:
doLogout()
case cliflags.ModeUpload:
processUpload(false)
processUpload(cliflags.ModeUpload)
case cliflags.ModeArchive:
processUpload(true)
processUpload(cliflags.ModeArchive)
case cliflags.ModeDownload:
processDownload()
case cliflags.ModeInvalid:
os.Exit(3)
}
Expand All @@ -38,11 +41,11 @@ func doLogin() {
cliconfig.CreateLogin()
}

func processUpload(isArchive bool) {
func processUpload(mode int) {
cliconfig.Load()
uploadParam := cliflags.GetUploadParameters(isArchive)
uploadParam := cliflags.GetUploadParameters(mode)

if isArchive {
if mode == cliflags.ModeArchive {
zipPath, err := zipFolder(uploadParam.Directory, uploadParam.TmpFolder, !uploadParam.JsonOutput)
if err != nil {
fmt.Println(err)
Expand All @@ -57,7 +60,7 @@ func processUpload(isArchive bool) {
if err != nil {
fmt.Println()
if errors.Is(cliapi.ErrUnauthorised, err) {
fmt.Println("ERROR: Unauthorised API key. Please re-run login.")
fmt.Println("ERROR: Unauthorised API key. Please re-run login or make sure that the API key has the permission to upload files.")
} else {
fmt.Println("ERROR: Could not upload file")
fmt.Println(err)
Expand All @@ -77,6 +80,24 @@ func processUpload(isArchive bool) {
fmt.Println("File Download URL: " + result.UrlDownload)
}

func processDownload() {
cliconfig.Load()
uploadParam := cliflags.GetUploadParameters(cliflags.ModeDownload)

// Perform the download
err := cliapi.DownloadFile(uploadParam)
if err != nil {
fmt.Println()
if errors.Is(cliapi.ErrUnauthorised, err) {
fmt.Println("ERROR: Unauthorised API key. Please re-run login or make sure that the API key has the permission to download files.")
} else {
fmt.Println("ERROR: Could not download file")
fmt.Println(err)
}
os.Exit(1)
}
}

func doLogout() {
err := cliconfig.Delete()
if err != nil {
Expand Down
Loading