mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-17 04:30:57 +01:00
put shared code into own mod (common), + apicontext env vars
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
//"github.com/alecthomas/repr"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"github.com/tlinden/cenophane/common"
|
||||
"github.com/tlinden/up/upctl/cfg"
|
||||
"mime"
|
||||
"os"
|
||||
@@ -47,23 +48,6 @@ type ListParams struct {
|
||||
Apicontext string `json:"apicontext"`
|
||||
}
|
||||
|
||||
type Upload struct {
|
||||
Id string `json:"id"`
|
||||
Expire string `json:"expire"`
|
||||
File string `json:"file"` // final filename (visible to the downloader)
|
||||
Members []string `json:"members"` // contains multiple files, so File is an archive
|
||||
Uploaded Timestamp `json:"uploaded"`
|
||||
Context string `json:"context"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type Uploads struct {
|
||||
Entries []*Upload `json:"uploads"`
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
const Maxwidth = 10
|
||||
|
||||
func Setup(c *cfg.Config, path string) *Request {
|
||||
@@ -279,7 +263,7 @@ func Download(c *cfg.Config, args []string) error {
|
||||
return fmt.Errorf("No filename provided!")
|
||||
}
|
||||
|
||||
cleanfilename, _ := Untaint(filename, regexp.MustCompile(`[^a-zA-Z0-9\-\._]`))
|
||||
cleanfilename, _ := common.Untaint(filename, regexp.MustCompile(`[^a-zA-Z0-9\-\._]`))
|
||||
|
||||
if err := os.Rename(id, cleanfilename); err != nil {
|
||||
os.Remove(id)
|
||||
@@ -290,26 +274,3 @@ func Download(c *cfg.Config, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
Untaint user input, that is: remove all non supported chars.
|
||||
|
||||
wanted is a regexp matching chars we shall leave. Everything else
|
||||
will be removed. Eg:
|
||||
|
||||
untainted := Untaint(input, `[^a-zA-Z0-9\-]`)
|
||||
|
||||
Returns a new string and an error if the input string has been
|
||||
modified. It's the callers choice to decide what to do about
|
||||
it. You may ignore the error and use the untainted string or bail
|
||||
out.
|
||||
*/
|
||||
func Untaint(input string, wanted *regexp.Regexp) (string, error) {
|
||||
untainted := wanted.ReplaceAllString(input, "")
|
||||
|
||||
if len(untainted) != len(input) {
|
||||
return untainted, errors.New("Invalid input string!")
|
||||
}
|
||||
|
||||
return untainted, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user