1212package app
1313
1414import (
15- "appengine"
16- "appengine/memcache"
1715 "bufio"
1816 "bytes"
1917 "encoding/json"
2018 "fmt"
2119 "github.com/disintegration/gift"
20+ "golang.org/x/net/context"
21+ "google.golang.org/appengine"
22+ "google.golang.org/appengine/memcache"
2223 "hash/crc32"
2324 "image"
2425 "image/gif"
@@ -35,10 +36,10 @@ import (
3536)
3637
3738const (
38- WEBSITE = "https://blueimp.github.io/jQuery-File-Upload/"
39- MIN_FILE_SIZE = 1 // bytes
39+ WEBSITE = "https://blueimp.github.io/jQuery-File-Upload/"
40+ MIN_FILE_SIZE = 1 // bytes
4041 // Max file size is memcache limit (1MB) minus key size minus overhead:
41- MAX_FILE_SIZE = 999000 // bytes
42+ MAX_FILE_SIZE = 999000 // bytes
4243 IMAGE_TYPES = "image/(gif|p?jpeg|(x-)?png)"
4344 ACCEPT_FILE_TYPES = IMAGE_TYPES
4445 THUMB_MAX_WIDTH = 80
5354 imageTypes = regexp .MustCompile (IMAGE_TYPES )
5455 acceptFileTypes = regexp .MustCompile (ACCEPT_FILE_TYPES )
5556 thumbSuffix = "." + fmt .Sprint (THUMB_MAX_WIDTH ) + "x" +
56- fmt .Sprint (THUMB_MAX_HEIGHT )
57+ fmt .Sprint (THUMB_MAX_HEIGHT )
5758)
5859
5960func escape (s string ) string {
@@ -105,7 +106,7 @@ func (fi *FileInfo) ValidateSize() (valid bool) {
105106 return false
106107}
107108
108- func (fi * FileInfo ) CreateUrls (r * http.Request , c appengine .Context ) {
109+ func (fi * FileInfo ) CreateUrls (r * http.Request , c context .Context ) {
109110 u := & url.URL {
110111 Scheme : r .URL .Scheme ,
111112 Host : appengine .DefaultVersionHostname (c ),
@@ -126,7 +127,7 @@ func (fi *FileInfo) SetKey(checksum uint32) {
126127 escape (string (fi .Name ))
127128}
128129
129- func (fi * FileInfo ) createThumb (buffer * bytes.Buffer , c appengine .Context ) {
130+ func (fi * FileInfo ) createThumb (buffer * bytes.Buffer , c context .Context ) {
130131 if imageTypes .MatchString (fi .Type ) {
131132 src , _ , err := image .Decode (bytes .NewReader (buffer .Bytes ()))
132133 check (err )
@@ -238,7 +239,7 @@ func validateRedirect(r *http.Request, redirect string) bool {
238239 return false
239240 }
240241 redirectAllowTarget = regexp .MustCompile ("^" + regexp .QuoteMeta (
241- refererUrl .Scheme + "://" + refererUrl .Host + "/" ,
242+ refererUrl .Scheme + "://" + refererUrl .Host + "/" ,
242243 ))
243244 }
244245 return redirectAllowTarget .MatchString (redirect )
@@ -276,17 +277,17 @@ func get(w http.ResponseWriter, r *http.Request) {
276277}
277278
278279func post (w http.ResponseWriter , r * http.Request ) {
279- result := make (map [string ][]* FileInfo , 1 )
280- result ["files" ] = handleUploads (r )
280+ result := make (map [string ][]* FileInfo , 1 )
281+ result ["files" ] = handleUploads (r )
281282 b , err := json .Marshal (result )
282283 check (err )
283284 if redirect := r .FormValue ("redirect" ); validateRedirect (r , redirect ) {
284- if strings .Contains (redirect , "%s" ) {
285- redirect = fmt .Sprintf (
286- redirect ,
287- escape (string (b )),
288- )
289- }
285+ if strings .Contains (redirect , "%s" ) {
286+ redirect = fmt .Sprintf (
287+ redirect ,
288+ escape (string (b )),
289+ )
290+ }
290291 http .Redirect (w , r , redirect , http .StatusFound )
291292 return
292293 }
@@ -338,7 +339,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
338339 "Content-Type, Content-Range, Content-Disposition" ,
339340 )
340341 switch r .Method {
341- case "OPTIONS" ,"HEAD" :
342+ case "OPTIONS" , "HEAD" :
342343 return
343344 case "GET" :
344345 get (w , r )
0 commit comments