Browse Source

REFERENCING CURRENT HOSTING

tags/v1.0.0
Andrea Spacca 5 years ago
parent
commit
d2c8b85b15
2 changed files with 779 additions and 751 deletions
  1. +31
    -4
      server/handlers.go
  2. +748
    -747
      vendor/github.com/dutchcoders/transfer.sh-web/bindata_gen.go

+ 31
- 4
server/handlers.go View File

@@ -160,11 +160,16 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {


qrCode := base64.StdEncoding.EncodeToString(png) qrCode := base64.StdEncoding.EncodeToString(png)


hostname := getURL(r).Host
webAddress := resolveWebAddress(r)

data := struct { data := struct {
ContentType string ContentType string
Content html_template.HTML Content html_template.HTML
Filename string Filename string
Url string Url string
Hostname string
WebAddress string
ContentLength uint64 ContentLength uint64
GAKey string GAKey string
UserVoiceKey string UserVoiceKey string
@@ -174,6 +179,8 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
content, content,
filename, filename,
resolvedUrl, resolvedUrl,
hostname,
webAddress,
contentLength, contentLength,
s.gaKey, s.gaKey,
s.userVoiceKey, s.userVoiceKey,
@@ -193,13 +200,27 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
// vars := mux.Vars(r) // vars := mux.Vars(r)


hostname := getURL(r).Host
webAddress := resolveWebAddress(r)

data := struct {
Hostname string
WebAddress string
GAKey string
}{
hostname,
webAddress,
s.gaKey,
}

if acceptsHTML(r.Header) { if acceptsHTML(r.Header) {
if err := htmlTemplates.ExecuteTemplate(w, "index.html", nil); err != nil {
if err := htmlTemplates.ExecuteTemplate(w, "index.html", data); err != nil {
s.logger.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
} else { } else {
if err := textTemplates.ExecuteTemplate(w, "index.txt", nil); err != nil {
if err := textTemplates.ExecuteTemplate(w, "index.txt", data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@@ -464,8 +485,14 @@ func resolveUrl(r *http.Request, u *url.URL, absolutePath bool) string {
return getURL(r).ResolveReference(u).String() return getURL(r).ResolveReference(u).String()
} }


func resolveWebAddress(r *http.Request) string {
url := getURL(r)

return fmt.Sprintf("%s://%s", url.ResolveReference(url).Scheme, url.ResolveReference(url).Host)
}

func getURL(r *http.Request) *url.URL { func getURL(r *http.Request) *url.URL {
u := *r.URL
u, _ := url.Parse(r.URL.String())


if r.TLS != nil { if r.TLS != nil {
u.Scheme = "https" u.Scheme = "https"
@@ -488,7 +515,7 @@ func getURL(r *http.Request) *url.URL {
} }
} }


return &u
return u
} }


func (s *Server) Lock(token, filename string) error { func (s *Server) Lock(token, filename string) error {


+ 748
- 747
vendor/github.com/dutchcoders/transfer.sh-web/bindata_gen.go
File diff suppressed because it is too large
View File


Loading…
Cancel
Save