Beispiel #1
0
func (s *Storage) DeleteThumbnails(parentAttId string, blob tenpu.BlobStorage, meta tenpu.MetaStorage) (err error) {
	thumbs := s.ThumbnailByParentId(parentAttId)
	// log.Println("Delete thumbnail num:", len(thumbs))
	var thumbAttIds []string
	for _, thumb := range thumbs {
		thumbAttIds = append(thumbAttIds, thumb.BodyId)
	}

	for _, thumbAttId := range thumbAttIds {

		err = blob.Delete(thumbAttId)
		if err != nil && err != mgo.ErrNotFound {
			return
		}

		err = meta.Remove(thumbAttId)
		if err != nil {
			return
		}
	}
	err = s.RemoveAll(parentAttId)
	return
}
Beispiel #2
0
func resizeAndStore(storage tenpu.BlobStorage, meta tenpu.MetaStorage, thumbnailStorage *Storage, att *tenpu.Attachment, spec *ThumbnailSpec, thumbName string, id string) (thumb *Thumbnail, err error) {

	var buf bytes.Buffer
	storage.Copy(att, &buf)

	if buf.Len() == 0 {
		return
	}
	thumbAtt := &tenpu.Attachment{}

	body, width, height, err := resizeThumbnail(&buf, spec)

	if err != nil {
		return
	}

	err = storage.Put(att.Filename, att.ContentType, body, thumbAtt)
	if err != nil {
		return
	}

	err = meta.Put(thumbAtt)
	if err != nil {
		return
	}

	thumb = &Thumbnail{
		Name:     thumbName,
		ParentId: id,
		BodyId:   thumbAtt.Id,
		Width:    int64(width),
		Height:   int64(height),
	}
	err = thumbnailStorage.Put(thumb)
	return
}