Fix issue pages URL params
This commit is contained in:
parent
34f4af9ebf
commit
eb6021f73f
7 changed files with 49 additions and 30 deletions
|
@ -47,6 +47,7 @@ func HashEmail(email string) string {
|
|||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// Avatar represents the avatar object.
|
||||
type Avatar struct {
|
||||
Hash string
|
||||
AlterImage string // image path
|
||||
|
@ -96,8 +97,8 @@ func (this *Avatar) Encode(wr io.Writer, size int) (err error) {
|
|||
return
|
||||
}
|
||||
defer fd.Close()
|
||||
img, err = jpeg.Decode(fd)
|
||||
if err != nil {
|
||||
|
||||
if img, err = jpeg.Decode(fd); err != nil {
|
||||
fd.Seek(0, os.SEEK_SET)
|
||||
img, err = png.Decode(fd)
|
||||
}
|
||||
|
@ -110,8 +111,8 @@ func (this *Avatar) Encode(wr io.Writer, size int) (err error) {
|
|||
}
|
||||
imgPath = this.AlterImage
|
||||
}
|
||||
img, err = decodeImageFile(imgPath)
|
||||
if err != nil {
|
||||
|
||||
if img, err = decodeImageFile(imgPath); err != nil {
|
||||
return
|
||||
}
|
||||
m := resize.Resize(uint(size), 0, img, resize.Lanczos3)
|
||||
|
@ -124,8 +125,7 @@ func (this *Avatar) Update() {
|
|||
this.imagePath)
|
||||
}
|
||||
|
||||
func (this *Avatar) UpdateTimeout(timeout time.Duration) error {
|
||||
var err error
|
||||
func (this *Avatar) UpdateTimeout(timeout time.Duration) (err error) {
|
||||
select {
|
||||
case <-time.After(timeout):
|
||||
err = fmt.Errorf("get gravatar image %s timeout", this.Hash)
|
||||
|
@ -140,8 +140,7 @@ type service struct {
|
|||
altImage string
|
||||
}
|
||||
|
||||
func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string) int {
|
||||
var v int
|
||||
func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string) (v int) {
|
||||
for _, k := range keys {
|
||||
if _, err := fmt.Sscanf(r.FormValue(k), "%d", &v); err == nil {
|
||||
defaultValue = v
|
||||
|
@ -176,8 +175,8 @@ func (this *service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
w.Header().Set("ETag", etag)
|
||||
}
|
||||
w.Header().Set("Content-Type", "image/jpeg")
|
||||
err := avatar.Encode(w, size)
|
||||
if err != nil {
|
||||
|
||||
if err := avatar.Encode(w, size); err != nil {
|
||||
log.Warn("avatar encode error: %v", err)
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
|
|
|
@ -412,6 +412,11 @@ func (f StrTo) Int() (int, error) {
|
|||
return int(v), err
|
||||
}
|
||||
|
||||
func (f StrTo) Int64() (int64, error) {
|
||||
v, err := strconv.ParseInt(f.String(), 10, 64)
|
||||
return int64(v), err
|
||||
}
|
||||
|
||||
func (f StrTo) String() string {
|
||||
if f.Exist() {
|
||||
return string(f)
|
||||
|
@ -541,16 +546,10 @@ func ActionDesc(act Actioner, avatarLink string) string {
|
|||
}
|
||||
|
||||
func DiffTypeToStr(diffType int) string {
|
||||
switch diffType {
|
||||
case 1:
|
||||
return "add"
|
||||
case 2:
|
||||
return "modify"
|
||||
case 3:
|
||||
return "del"
|
||||
default:
|
||||
return "unknown"
|
||||
diffTypes := map[int]string{
|
||||
1: "add", 2: "modify", 3: "del",
|
||||
}
|
||||
return diffTypes[diffType]
|
||||
}
|
||||
|
||||
func DiffLineTypeToStr(diffType int) string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue