Skip to content
Permalink
Browse files

Merge pull request #64 from tribut/curl-tutorial-hostname

Use correct hostname in curl tutorial
  • Loading branch information...
Depado committed Mar 1, 2018
2 parents 6a73d99 + 6e9af24 commit 351ac87fead45e4e5d7059ab05983ef3a47eafb9
Showing with 36 additions and 16 deletions.
  1. +10 −5 server/curl/curl.go
  2. +23 −0 server/utils/servername.go
  3. +1 −5 server/views/resources.go
  4. +1 −5 server/views/unencrypted.go
  5. +1 −1 server/views/web.go
@@ -1,13 +1,18 @@
package curl

import "io"
import (
"github.com/gin-gonic/gin"

// WriteTutorial will write to an io.Writer the full curl tutorial
func WriteTutorial(w io.Writer) {
"github.com/Depado/goploader/server/utils"
)

// WriteTutorial will write to a gin.Context's writer the full curl tutorial
func WriteTutorial(c *gin.Context) {
w := c.Writer
Header(w, header)
Title(w, "Usage\n")
Standard(w, "Upload from stdin")
Command(w, "$ tree | curl -F file=@- https://gpldr.in/\n")
Command(w, "$ tree | curl -F file=@- "+utils.ServerURI(c))
Standard(w, "Simple file upload")
Command(w, "$ curl -F file=@myfile.txt https://gpldr.in/")
Command(w, "$ curl -F file=@myfile.txt "+utils.ServerURI(c))
}
@@ -0,0 +1,23 @@
package utils

import (
"fmt"

"github.com/gin-gonic/gin"

"github.com/Depado/goploader/server/conf"
)

// ServerName returns the configured hostname (and port) of the server
func ServerName() string {
ns := conf.C.NameServer
if conf.C.AppendPort {
ns = fmt.Sprintf("%s:%d", conf.C.NameServer, conf.C.Port)
}
return ns
}

// ServerURI returns the full URI to the server including scheme
func ServerURI(c *gin.Context) string {
return DetectScheme(c) + "://" + ServerName()
}
@@ -82,11 +82,7 @@ func CreateC(c *gin.Context) {
return
}
res.OnCreated(c)
ns := conf.C.NameServer
if conf.C.AppendPort {
ns = fmt.Sprintf("%s:%d", conf.C.NameServer, conf.C.Port)
}
c.String(http.StatusCreated, "%v://%s/v/%s/%s\n", utils.DetectScheme(c), ns, res.Key, k)
c.String(http.StatusCreated, "%s/v/%s/%s\n", utils.ServerURI(c), res.Key, k)
}

// ViewC handles the file views for encrypted files
@@ -90,11 +90,7 @@ func Create(c *gin.Context) {
return
}
newres.LogCreated(c)
ns := conf.C.NameServer
if conf.C.AppendPort {
ns = fmt.Sprintf("%s:%d", conf.C.NameServer, conf.C.Port)
}
c.String(http.StatusCreated, "%v://%s/v/%s\n", utils.DetectScheme(c), ns, u)
c.String(http.StatusCreated, "%s/v/%s\n", utils.ServerURI(c), u)
}

// HandleRequest responds to a View or Head request for unencrypted files
@@ -18,7 +18,7 @@ import (
func Index(c *gin.Context) {
logger.InfoC(c, "server", "GET /")
if strings.HasPrefix(c.Request.Header.Get("User-Agent"), "curl") {
curl.WriteTutorial(c.Writer)
curl.WriteTutorial(c)
return
}
data := gin.H{

0 comments on commit 351ac87

Please sign in to comment.
You can’t perform that action at this time.