@@ -20,6 +20,10 @@ import (
"io"
// pdf "github.com/SebastiaanKlippert/go-wkhtmltopdf"
"github.com/golang-jwt/jwt/v4"
"github.com/disintegration/gift"
"image"
"image/png"
_ "image/jpeg"
)
type User struct {
@@ -1566,12 +1570,13 @@ func checkFHA(l Loan, b Borrower) error {
return nil
}
// Loan option for veterans with no set rules
// Loan option for veterans with no set rules. Mainly placeholder.
func checkVA(l Loan, b Borrower) error {
return nil
}
// Loan option for residents of rural areas with no set rules
// Loan option for residents of rural areas with no set rules.
// Mainly placeholder.
func checkUSDA(l Loan, b Borrower) error {
return nil
}
@@ -1677,6 +1682,31 @@ func showPDF(w http.ResponseWriter, r *http.Request) {
}
func clipLetterhead(w http.ResponseWriter, db *sql.DB, r *http.Request) {
var validTypes []string = []string{"image/png", "image/jpeg"}
var isValidType bool
var err error
// claims, err := getClaims(r)
if err != nil { http.Error(w, "Invalid token.", 422); return }
img, t, err := image.Decode(r.Body)
if err != nil { http.Error(w, "Invalid file.", 422); return }
for _, v := range validTypes {
if v == "image/"+t { isValidType = true }
}
if !isValidType { http.Error(w, "Invalid file type.", 422); return }
g := gift.New(
gift.ResizeToFit(400, 200, gift.LanczosResampling),
)
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
w.Header().Set("Content-Type", "image/png")
err = png.Encode(w, dst)
if err != nil { http.Error(w, "Error encoding.", 500); return }
}
func api(w http.ResponseWriter, r *http.Request) {
var args []string
@@ -1702,6 +1732,9 @@ func api(w http.ResponseWriter, r *http.Request) {
case match(p, "/api/token", &args) &&
r.Method == http.MethodGet && guard(r, 1):
getToken(w, db, r)
case match(p, "/api/letterhead", &args) &&
r.Method == http.MethodPost && guard(r, 1):
clipLetterhead(w, db, r)
case match(p, "/api/users", &args) && // Array of all users
r.Method == http.MethodGet && guard(r, 3):
getUsers(w, db, r)