From 401675ec717dffe06def62cc040baa56c2ae066b Mon Sep 17 00:00:00 2001 From: Aleksandr Tihomirov Date: Wed, 4 Jan 2017 22:28:54 +0200 Subject: [PATCH] Partial solution to #2 --- cmd/gowo/cmd/upload.go | 8 ++++++++ endpoints.go | 2 ++ 2 files changed, 10 insertions(+) diff --git a/cmd/gowo/cmd/upload.go b/cmd/gowo/cmd/upload.go index dc642ad..f9bfeef 100644 --- a/cmd/gowo/cmd/upload.go +++ b/cmd/gowo/cmd/upload.go @@ -26,6 +26,7 @@ import ( "log" "os" + humanize "github.com/dustin/go-humanize" "github.com/spf13/cobra" "fmt" @@ -47,6 +48,13 @@ var uploadCmd = &cobra.Command{ if err != nil { log.Fatal(err) } + stat, err := file.Stat() + if err != nil { + log.Fatal(err) + } + if stat.Size() > owo.FileUploadLimit { + log.Fatal(fmt.Errorf("[pre-flight] File '%s' exceeds upload limit (%s > %s)", file.Name(), humanize.Bytes(uint64(stat.Size())), humanize.Bytes(owo.FileUploadLimit))) + } files[idx] = owo.NamedReader{file, arg} defer file.Close() } diff --git a/endpoints.go b/endpoints.go index 72f5769..d6b6dd5 100644 --- a/endpoints.go +++ b/endpoints.go @@ -24,6 +24,8 @@ package owo // APIRoot defines base url for the service's API endpoints const APIRoot = "https://api.awau.moe" +const FileUploadLimit = 83886080 + var ( // APIFileUploadURL to send POSTs with files to APIFileUploadURL = APIRoot + "/upload/pomf"