Skip to content

Commit e60e5c5

Browse files
committed
Fixed upload failing or showing incorrect filename for non-ASCII filenames #269, added option to base64 encode filename in API, fixed API documentation
1 parent 1db59e0 commit e60e5c5

File tree

11 files changed

+154
-24
lines changed

11 files changed

+154
-24
lines changed

build/go-generate/minifyStaticContent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ func fileExists(filename string) bool {
137137
// Auto-generated content below, do not modify
138138
// Version codes can be changed in updateVersionNumbers.go
139139

140-
const jsAdminVersion = 10
140+
const jsAdminVersion = 11
141141
const jsE2EVersion = 6
142142
const cssMainVersion = 5

build/go-generate/updateVersionNumbers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strings"
1212
)
1313

14-
const versionJsAdmin = 10
14+
const versionJsAdmin = 11
1515
const versionJsDropzone = 5
1616
const versionJsE2EAdmin = 6
1717
const versionCssMain = 5

cmd/gokapi/Main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
// versionGokapi is the current version in readable form.
3636
// Other version numbers can be modified in /build/go-generate/updateVersionNumbers.go
37-
const versionGokapi = "2.0.0"
37+
const versionGokapi = "2.0.1"
3838

3939
// The following calls update the version numbers, update documentation, minify Js/CSS and build the WASM modules
4040
//go:generate go run "../../build/go-generate/updateVersionNumbers.go"

internal/webserver/api/routing.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package api
22

33
import (
4+
"encoding/base64"
45
"errors"
56
"github.com/forceu/gokapi/internal/models"
67
"github.com/forceu/gokapi/internal/storage"
@@ -18,6 +19,8 @@ type apiRoute struct {
1819
execution apiFunc
1920
}
2021

22+
const base64Prefix = "base64:"
23+
2124
func (r apiRoute) Continue(w http.ResponseWriter, request requestParser, user models.User) {
2225
r.execution(w, request, user)
2326
}
@@ -469,6 +472,15 @@ func (p *paramChunkComplete) ProcessParameter(_ *http.Request) error {
469472
if p.foundHeaders["expiryDays"] && p.ExpiryDays == 0 {
470473
p.UnlimitedTime = true
471474
}
475+
476+
if strings.HasPrefix(p.FileName, base64Prefix) {
477+
decoded, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(p.FileName, base64Prefix))
478+
if err != nil {
479+
return err
480+
}
481+
p.FileName = string(decoded)
482+
}
483+
472484
p.FileHeader = chunking.FileHeader{
473485
Filename: p.FileName,
474486
ContentType: p.ContentType,

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

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,71 @@
175175
"apikey": ["UPLOAD"]
176176
},
177177
],
178-
"requestBody": {
179-
"content": {
180-
"application/x-www-form-urlencoded": {
181-
"schema": {
182-
"$ref": "#/components/schemas/chunkingcomplete"
183-
}
178+
"parameters": [
179+
{
180+
"name": "uuid",
181+
"in": "header",
182+
"description": "The unique ID that was used for the uploaded chunks",
183+
"required": true,
184+
"schema": {
185+
"type": "string"
184186
}
185187
},
186-
"required": true
187-
},
188+
{
189+
"name": "filename",
190+
"in": "header",
191+
"description": "The filename of the uploaded file. If the filename includes non-ANSI characters, you can encode them with base64, by adding 'base64:' at the beginning, e.g. 'base64:ZmlsZW5hbWU='",
192+
"required": true,
193+
"schema": {
194+
"type": "string"
195+
}
196+
},
197+
{
198+
"name": "filesize",
199+
"in": "header",
200+
"description": "The total filesize of the uploaded file in bytes",
201+
"required": true,
202+
"schema": {
203+
"type": "integer"
204+
}
205+
},
206+
{
207+
"name": "contenttype",
208+
"in": "header",
209+
"description": "The MIME content type. If empty, application/octet-stream will be used.",
210+
"required": false,
211+
"schema": {
212+
"type": "string"
213+
}
214+
},
215+
{
216+
"name": "allowedDownloads",
217+
"in": "header",
218+
"description": "How many downloads are allowed. Default of 1 will be used if empty. Unlimited if 0 is passed.",
219+
"required": false,
220+
"schema": {
221+
"type": "integer"
222+
}
223+
},
224+
{
225+
"name": "expiryDays",
226+
"in": "header",
227+
"description": "How many days the file will be stored. Default of 14 will be used if empty. Unlimited if 0 is passed.",
228+
"required": false,
229+
"schema": {
230+
"type": "integer"
231+
}
232+
},
233+
{
234+
"name": "password",
235+
"in": "header",
236+
"description": "Password for this file to be set. No password will be used if empty.",
237+
"required": false,
238+
"schema": {
239+
"type": "string"
240+
}
241+
}
242+
],
188243
"responses": {
189244
"200": {
190245
"description": "Operation successful",

internal/webserver/web/static/assets/dist/js/base64.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ async function apiAuthCreate() {
114114

115115
async function apiChunkComplete(uuid, filename, filesize, realsize, contenttype, allowedDownloads, expiryDays, password, isE2E, nonblocking) {
116116
const apiUrl = './api/chunk/complete';
117-
117+
118118
const requestOptions = {
119119
method: 'POST',
120120
headers: {
121121
'Content-Type': 'application/json',
122122
'apikey': systemKey,
123123
'uuid': uuid,
124-
'filename': filename,
124+
'filename': 'base64:'+Base64.encode(filename),
125125
'filesize': filesize,
126126
'realsize': realsize,
127127
'contenttype': contenttype,

internal/webserver/web/static/js/min/admin.min.10.js renamed to internal/webserver/web/static/js/min/admin.min.11.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/webserver/web/templates/html_header.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<link href="./assets/dist/css/datatables.min.css" rel="stylesheet">
2626
<link href="./assets/dist/css/flatpickr.min.css" rel="stylesheet">
2727
<link href="./assets/dist/css/flatpickr.dark.min.css" rel="stylesheet">
28+
<script src="./assets/dist/js/base64.min.js"></script>
2829
<style>
2930
.masthead-brand {
3031
float: left;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// File contains auto-generated values. Do not change manually
2-
{{define "version"}}2.0.0{{end}}
2+
{{define "version"}}2.0.1{{end}}
33

44
// Specifies the version of JS files, so that the browser doesn't
55
// use a cached version, if the file has been updated
6-
{{define "js_admin_version"}}10{{end}}
6+
{{define "js_admin_version"}}11{{end}}
77
{{define "js_dropzone_version"}}5{{end}}
88
{{define "js_e2eversion"}}6{{end}}
99
{{define "css_main"}}5{{end}}

0 commit comments

Comments
 (0)