Example #1
0
// serveFile serves the relevant view when the subject in serveSubject
// is a permanode with some content cref. It is meant to be called
// from serveSubject.
func (pr *publishRequest) serveFile(cref blob.Ref) error {
	des, err := pr.dr.DescribeSync(cref)
	if err != nil {
		pr.pf("<p>Error serving file</p>")
		return fmt.Errorf("Could not describe %v: %v", cref, err)
	}
	if des.File != nil {
		path := []blob.Ref{pr.subject, cref}
		downloadURL := pr.SubresFileURL(path, des.File.FileName)
		pr.pf("<div>File: %s, %d bytes, type %s</div>",
			html.EscapeString(des.File.FileName),
			des.File.Size,
			des.File.MIMEType)
		if des.File.IsImage() {
			pr.pf("<a href='%s'><img src='%s'></a>",
				downloadURL,
				pr.SubresThumbnailURL(path, des.File.FileName, 600))
		}
		pr.pf("<div id='%s' class='camlifile'>[<a href='%s'>download</a>]</div>",
			cref.DomID(),
			downloadURL)
	}
	if strings.Contains(pr.subjectBasePath, resSeparator) {
		// this permanode has a "parent" collection.
		// so we send a deep request on the parent in order to get some info
		// about the siblings and build some "prev" and "next" nav links.
		// TODO(mpl): nav links everywhere, not just when showing a permanode
		// with some content.
		err := pr.serveNav()
		if err != nil {
			pr.pf("<p>Error building navs links</p>")
			return err
		}
	}
	return nil
}