github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/analyzer_handler.go (about) 1 // Copyright 2019 The WPT Dashboard Project. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package webapp 6 7 import ( 8 "fmt" 9 "net/http" 10 11 "github.com/web-platform-tests/wpt.fyi/shared" 12 ) 13 14 func analyzerHandler(w http.ResponseWriter, r *http.Request) { 15 q := r.URL.Query() 16 screenshots := q["screenshot"] 17 before, after := q.Get("before"), q.Get("after") 18 if before != "" { 19 screenshots = append(screenshots, before) 20 } 21 if after != "" { 22 screenshots = append(screenshots, after) 23 } 24 if len(screenshots) != 2 { 25 http.Error(w, "Expected exactly 2 screenshots (before + after)", http.StatusBadRequest) 26 return 27 } 28 29 ctx := r.Context() 30 aeAPI := shared.NewAppEngineAPI(ctx) 31 /* #nosec G101 */ 32 bucket := "wptd-screenshots-staging" 33 if aeAPI.GetHostname() == "wpt.fyi" { 34 /* #nosec G101 */ 35 bucket = "wptd-screenshots" 36 } 37 38 data := struct { 39 Before string 40 After string 41 }{ 42 fmt.Sprintf("https://storage.googleapis.com/%s/%s.png", bucket, screenshots[0]), 43 fmt.Sprintf("https://storage.googleapis.com/%s/%s.png", bucket, screenshots[1]), 44 } 45 RenderTemplate(w, r, "analyzer.html", data) 46 }