コード例 #1
0
ファイル: handler.go プロジェクト: jakubbrzeski/camlistore
// returns a path relative to the UI handler.
//
// Locking: requires that DescribedRequest is done loading or that
// Request.mu is held (as it is from metaMap)
func (b *DescribedBlob) thumbnail(thumbSize int) (path string, width, height int, ok bool) {
	if thumbSize <= 0 || !b.isPermanode() {
		return
	}
	if b.Stub {
		return "node.png", thumbSize, thumbSize, true
	}
	pnAttr := b.Permanode.Attr

	if members := pnAttr["camliMember"]; len(members) > 0 {
		return "folder.png", thumbSize, thumbSize, true
	}

	if content, ok := b.ContentRef(); ok {
		peer := b.peerBlob(content)
		if peer.File != nil {
			if peer.File.IsImage() {
				image := fmt.Sprintf("thumbnail/%s/%s?mh=%d", peer.BlobRef,
					url.QueryEscape(peer.File.FileName), thumbSize)
				if peer.Image != nil {
					mw, mh := images.ScaledDimensions(
						peer.Image.Width, peer.Image.Height,
						MaxImageSize, thumbSize)
					return image, mw, mh, true
				}
				return image, thumbSize, thumbSize, true
			}

			// TODO: different thumbnails based on peer.File.MIMEType.
			const fileIconAspectRatio = 260.0 / 300.0
			var width = int(math.Floor(float64(thumbSize)*fileIconAspectRatio + 0.5))
			return "file.png", width, thumbSize, true
		}
		if peer.Dir != nil {
			return "folder.png", thumbSize, thumbSize, true
		}
	}

	return "node.png", thumbSize, thumbSize, true
}
コード例 #2
0
ファイル: handler.go プロジェクト: peterwatts/camlistore
// returns a path relative to the UI handler.
//
// Locking: requires that DescribedRequest is done loading or that
// Request.mu is held (as it is from metaMap)
func (b *DescribedBlob) thumbnail(thumbSize int) (path string, width, height int, ok bool) {
	if thumbSize <= 0 || !b.isPermanode() {
		return
	}
	if b.Stub {
		return "node.png", thumbSize, thumbSize, true
	}

	if b.Permanode.IsContainer() {
		return "folder.png", thumbSize, thumbSize, true
	}

	if content, ok := b.ContentRef(); ok {
		peer := b.peerBlob(content)
		if peer.File != nil {
			ii := peer.Image
			if peer.File.IsImage() && ii != nil && ii.Height > 0 && ii.Width > 0 {
				image := fmt.Sprintf("thumbnail/%s/%s?mh=%d&tv=%s", peer.BlobRef,
					url.QueryEscape(peer.File.FileName), thumbSize, images.ThumbnailVersion())
				mw, mh := images.ScaledDimensions(
					int(ii.Width), int(ii.Height),
					MaxImageSize, thumbSize)
				return image, mw, mh, true
			}

			// TODO: different thumbnails based on peer.File.MIMEType.
			const fileIconAspectRatio = 260.0 / 300.0
			var width = int(math.Floor(float64(thumbSize)*fileIconAspectRatio + 0.5))
			return "file.png", width, thumbSize, true
		}
		if peer.Dir != nil {
			return "folder.png", thumbSize, thumbSize, true
		}
	}

	return "node.png", thumbSize, thumbSize, true
}