mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-18 13:01:13 +01:00
added more form functions
This commit is contained in:
@@ -320,3 +320,29 @@ func Download(w io.Writer, c *cfg.Config, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/**** Forms stuff ****/
|
||||
func CreateForm(w io.Writer, c *cfg.Config) error {
|
||||
// setup url, req.Request, timeout handling etc
|
||||
rq := Setup(c, "/forms")
|
||||
|
||||
// actual post w/ settings
|
||||
resp, err := rq.R.
|
||||
SetFormData(map[string]string{
|
||||
"expire": c.Expire,
|
||||
"description": c.Description,
|
||||
}).
|
||||
Post(rq.Url)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := HandleResponse(c, resp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return RespondExtended(w, resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ func prepareExpire(expire string, start common.Timestamp) string {
|
||||
case "asap":
|
||||
return "On first access"
|
||||
default:
|
||||
return time.Unix(start.Unix()+int64(common.Duration2int(expire)), 0).Format("2006-01-02 15:04:05")
|
||||
return time.Unix(start.Unix()+int64(common.Duration2int(expire)), 0).
|
||||
Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
return ""
|
||||
@@ -87,7 +88,16 @@ func WriteExtended(w io.Writer, response *common.Response) {
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
|
||||
// FIXME: add response.Forms loop here
|
||||
for _, entry := range response.Forms {
|
||||
expire := prepareExpire(entry.Expire, entry.Created)
|
||||
fmt.Fprintf(w, format, "Id", entry.Id)
|
||||
fmt.Fprintf(w, format, "Expire", expire)
|
||||
fmt.Fprintf(w, format, "Context", entry.Context)
|
||||
fmt.Fprintf(w, format, "Created", entry.Created)
|
||||
fmt.Fprintf(w, format, "Description", entry.Description)
|
||||
fmt.Fprintf(w, format, "Url", entry.Url)
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
}
|
||||
|
||||
// extract an common.Uploads{} struct from json response
|
||||
|
||||
Reference in New Issue
Block a user