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. 19
      src/app/spreed-speakfreely-server/images.go

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

@ -4,19 +4,22 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"encoding/base64" "encoding/base64"
"encoding/binary"
"log" "log"
"strconv"
"strings" "strings"
"sync" "sync"
"time"
) )
var imageFilenames map[string]string var imageFilenames map[string]string
type Image struct { type Image struct {
updateIdx int updateIdx int
userid string lastChange time.Time
mimetype string lastChangeId string
data []byte userid string
mimetype string
data []byte
} }
type ImageCache interface { 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) { if mimetype != img.mimetype || !bytes.Equal(img.data, decoded) {
img.updateIdx++ 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.mimetype = mimetype
img.data = decoded img.data = decoded
} }
result += "/" + strconv.Itoa(img.updateIdx) result += "/" + img.lastChangeId
filename, ok := imageFilenames[mimetype] filename, ok := imageFilenames[mimetype]
if ok { if ok {
result += "/" + filename result += "/" + filename

Loading…
Cancel
Save