Exemple #1
0
// serveNav serves some navigation links (prev, next, up) if the
// pr.subject is member of a collection (its parent has members).
// It is meant to be called from serveFile.
func (pr *publishRequest) serveNav() error {
	// first get the parent path and blob
	parentPath, parentbr, err := pr.parent()
	if err != nil {
		return fmt.Errorf("Errors building nav links for %s: %v", pr.subject, err)
	}
	parentNav := fmt.Sprintf("[<a href='%s'>up</a>]", strings.TrimSuffix(parentPath, resSeparator))

	// describe the parent so we get the siblings (members of the parent)
	dr := pr.ph.Search.NewDescribeRequest()
	dr.Describe(parentbr, 3)
	parentRes, err := dr.Result()
	if err != nil {
		return fmt.Errorf("Errors loading %s, permanode %s: %v, %#v", pr.req.URL, pr.subject, err, err)
	}
	members := parentRes[parentbr.String()].Members()
	if len(members) == 0 {
		pr.pf("<div class='camlifile'>[<a href='%s'>up</a>]</div>", parentNav)
		return nil
	}

	pos := 0
	var prev, next blob.Ref
	for k, member := range members {
		if member.BlobRef.String() == pr.subject.String() {
			pos = k
			break
		}
	}
	if pos > 0 {
		prev = members[pos-1].BlobRef
	}
	if pos < len(members)-1 {
		next = members[pos+1].BlobRef
	}
	if prev.Valid() || next.Valid() {
		var prevNav, nextNav string
		if prev.Valid() {
			prevNav = fmt.Sprintf("[<a href='%s/h%s'>prev</a>]",
				parentPath, prev.DigestPrefix(10))
		}
		if next.Valid() {
			nextNav = fmt.Sprintf("[<a href='%s/h%s'>next</a>]",
				parentPath, next.DigestPrefix(10))
		}
		pr.pf("<div class='camlifile'>%s %s %s</div>", parentNav, prevNav, nextNav)
	}

	return nil
}
Exemple #2
0
func (pr *publishRequest) fileNavigation() (*publish.Nav, error) {
	// first get the parent path and blob
	parentPath, parentbr, err := pr.parent()
	if err != nil {
		return nil, fmt.Errorf("Could not get subject %v's parent's info: %v", pr.subject, err)
	}
	parentNav := strings.TrimSuffix(parentPath, resSeparator)
	fileNav := &publish.Nav{
		ParentPath: parentNav,
	}

	// describe the parent so we get the siblings (members of the parent)
	dr := pr.ph.Search.NewDescribeRequest()
	dr.Describe(parentbr, 3)
	parentRes, err := dr.Result()
	if err != nil {
		return nil, fmt.Errorf("Could not \"deeply\" describe subject %v's parent %v: %v", pr.subject, parentbr, err)
	}
	members := parentRes[parentbr.String()].Members()
	if len(members) == 0 {
		return fileNav, nil
	}

	pos := 0
	var prev, next blob.Ref
	for k, member := range members {
		if member.BlobRef.String() == pr.subject.String() {
			pos = k
			break
		}
	}
	if pos > 0 {
		prev = members[pos-1].BlobRef
	}
	if pos < len(members)-1 {
		next = members[pos+1].BlobRef
	}
	if !prev.Valid() && !next.Valid() {
		return fileNav, nil
	}
	if prev.Valid() {
		fileNav.PrevPath = fmt.Sprintf("%s/%s%s", parentPath, digestPrefix, prev.DigestPrefix(10))
	}
	if next.Valid() {
		fileNav.NextPath = fmt.Sprintf("%s/%s%s", parentPath, digestPrefix, next.DigestPrefix(10))
	}
	return fileNav, nil
}
Exemple #3
0
func (pr *publishRequest) memberPath(member blob.Ref) string {
	return addPathComponent(pr.subjectBasePath, "/h"+member.DigestPrefix(10))
}