From 9fe209eb3bac10e2f5e4cdab3270caa7692bf1f3 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 18 Mar 2014 12:00:38 +0100 Subject: [PATCH] Include timestamp of last change in URL instead of human readable update index. --- src/app/spreed-speakfreely-server/images.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/spreed-speakfreely-server/images.go b/src/app/spreed-speakfreely-server/images.go index c907f18f..b2724fdd 100644 --- a/src/app/spreed-speakfreely-server/images.go +++ b/src/app/spreed-speakfreely-server/images.go @@ -4,19 +4,22 @@ import ( "bytes" "crypto/rand" "encoding/base64" + "encoding/binary" "log" - "strconv" "strings" "sync" + "time" ) var imageFilenames map[string]string type Image struct { - updateIdx int - userid string - mimetype string - data []byte + updateIdx int + lastChange time.Time + lastChangeId string + userid string + mimetype string + data []byte } type ImageCache interface { @@ -99,10 +102,14 @@ func (self *imageCache) Update(userId string, image string) string { } if mimetype != img.mimetype || !bytes.Equal(img.data, decoded) { img.updateIdx++ + img.lastChange = time.Now() + tmp := make([]byte, binary.MaxVarintLen64) + count := binary.PutUvarint(tmp, uint64(img.lastChange.UnixNano())) + img.lastChangeId = base64.URLEncoding.EncodeToString(tmp[:count]) img.mimetype = mimetype img.data = decoded } - result += "/" + strconv.Itoa(img.updateIdx) + result += "/" + img.lastChangeId filename, ok := imageFilenames[mimetype] if ok { result += "/" + filename