(w http.ResponseWriter, r *http.Request)
| 511 | } |
| 512 | |
| 513 | func (h *handler) handleDoc(w http.ResponseWriter, r *http.Request) { |
| 514 | urlFields := strings.Split(r.URL.Path, "/") |
| 515 | if len(urlFields) < 3 { |
| 516 | http.Error(w, "no document blobref", http.StatusBadRequest) |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | docRef, ok := blob.Parse(urlFields[2]) |
| 521 | if !ok { |
| 522 | http.Error(w, fmt.Sprintf("invalid document blobref: %q", urlFields[2]), http.StatusBadRequest) |
| 523 | return |
| 524 | } |
| 525 | document, err := h.fetchDocument(docRef) |
| 526 | if err != nil { |
| 527 | http.Redirect(w, r, fmt.Sprintf("%s?error_message=DocRef+%s+not+found", baseURL(r), docRef), http.StatusFound) |
| 528 | return |
| 529 | } |
| 530 | |
| 531 | var pages []mediaObject |
| 532 | for _, v := range document.pages { |
| 533 | // TODO(mpl): group fetch ? |
| 534 | page, err := h.fetchScan(v) |
| 535 | if err != nil { |
| 536 | httputil.ServeError(w, r, fmt.Errorf("could not fetch page %v for document %v: %v", v, document.permanode, err)) |
| 537 | return |
| 538 | } |
| 539 | pages = append(pages, page) |
| 540 | } |
| 541 | var size int |
| 542 | size = 1200 |
| 543 | if sizeParam := r.FormValue("size"); sizeParam != "" { |
| 544 | sizeint, err := strconv.Atoi(sizeParam) |
| 545 | if err != nil { |
| 546 | httputil.ServeError(w, r, fmt.Errorf("invalid size param %q: %v", sizeParam, err)) |
| 547 | return |
| 548 | } |
| 549 | size = sizeint |
| 550 | } |
| 551 | show_single_list := size > 600 |
| 552 | |
| 553 | allTags, err := h.fetchTags() |
| 554 | if err != nil { |
| 555 | httputil.ServeError(w, r, err) |
| 556 | return |
| 557 | } |
| 558 | |
| 559 | d := struct { |
| 560 | BaseURL string |
| 561 | Pages []MediaObjectVM |
| 562 | Doc DocumentVM |
| 563 | ShowSingleList bool |
| 564 | Size int |
| 565 | AllTags map[string]int |
| 566 | }{ |
| 567 | BaseURL: baseURL(r), |
| 568 | Pages: MakeMediaObjectViewModels(pages), |
| 569 | Doc: document.MakeViewModel(), |
| 570 | ShowSingleList: show_single_list, |
nothing calls this directly
no test coverage detected