Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
whats-this
api
Commits
5b1f7cdf
Commit
5b1f7cdf
authored
5 years ago
by
Dean
Browse files
Options
Downloads
Patches
Plain Diff
version 1.6.5: update file extension logic
parent
c97d9277
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/routes/uploadpomf.go
+22
-8
22 additions, 8 deletions
lib/routes/uploadpomf.go
main.go
+1
-1
1 addition, 1 deletion
main.go
with
23 additions
and
9 deletions
lib/routes/uploadpomf.go
+
22
−
8
View file @
5b1f7cdf
...
...
@@ -9,6 +9,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"
"owo.codes/whats-this/api/lib/apierrors"
"owo.codes/whats-this/api/lib/db"
...
...
@@ -28,7 +29,26 @@ const maxMemory = 1000 * 1000 * 50 // 50 MB
const
fieldName
=
"files[]"
// File extension regex.
var
fileExtRegex
=
regexp
.
MustCompile
(
`(\.[a-z0-9_.-]+)$`
)
var
fileExtRegex
=
regexp
.
MustCompile
(
`(\.[a-z0-9_-]+)$`
)
// .*.gz extension regex.
var
gzExtRegex
=
regexp
.
MustCompile
(
`(\.[a-z0-9_-]+\.gz)$`
)
// determineExtension returns a file extension (including leading dot) for a
// filename.
func
determineExtension
(
filename
string
)
string
{
ext
:=
""
if
strings
.
HasSuffix
(
filename
,
".gz"
)
{
ext
=
gzExtRegex
.
FindString
(
filename
)
}
if
ext
==
""
&&
filename
!=
""
{
ext
=
fileExtRegex
.
FindString
(
filename
)
}
if
len
(
ext
)
>
20
{
ext
=
ext
[
0
:
20
]
// limit ext length to 20 chars
}
return
ext
}
// fileResponse represents a file response in an upload request.
type
fileResponse
struct
{
...
...
@@ -123,13 +143,7 @@ func UploadPomf(associateObjectsWithUser bool) func(http.ResponseWriter, *http.R
}
// Determine object extension for response.
ext
:=
""
if
file
.
Filename
!=
""
{
ext
=
fileExtRegex
.
FindString
(
file
.
Filename
)
}
if
len
(
ext
)
>
20
{
ext
=
ext
[
0
:
20
]
// limit ext length to 20 chars
}
ext
:=
determineExtension
(
file
.
Filename
)
// Determine Content-Type
contentType
:=
"application/octet-stream"
...
...
This diff is collapsed.
Click to expand it.
main.go
+
1
−
1
View file @
5b1f7cdf
...
...
@@ -26,7 +26,7 @@ import (
const
(
configLocationUnix
=
"/etc/whats-this/api/config.toml"
shutdownTimeout
=
10
*
time
.
Second
version
=
"1.6.
4
"
version
=
"1.6.
5
"
)
// printConfiguration iterates through a configuration map[string]interface{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment