Browse Source

Include timestamp of last change in URL instead of human readable update index.

pull/15/head
Joachim Bauch 12 years ago
parent
commit
9fe209eb3b
  1. 11
      src/app/spreed-speakfreely-server/images.go

11
src/app/spreed-speakfreely-server/images.go

@ -4,16 +4,19 @@ import ( @@ -4,16 +4,19 @@ import (
"bytes"
"crypto/rand"
"encoding/base64"
"encoding/binary"
"log"
"strconv"
"strings"
"sync"
"time"
)
var imageFilenames map[string]string
type Image struct {
updateIdx int
lastChange time.Time
lastChangeId string
userid string
mimetype string
data []byte
@ -99,10 +102,14 @@ func (self *imageCache) Update(userId string, image string) string { @@ -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

Loading…
Cancel
Save