MCPcopy Index your code
hub / github.com/perkeep/perkeep / handleChangedoc

Method handleChangedoc

app/scanningcabinet/handler.go:580–636  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

578}
579
580func (h *handler) handleChangedoc(w http.ResponseWriter, r *http.Request) {
581 ctx := r.Context()
582 if r.Method != "POST" {
583 http.Error(w, "not a POST", http.StatusMethodNotAllowed)
584 return
585 }
586
587 docRef, ok := blob.Parse(r.FormValue("docref"))
588 if !ok {
589 httputil.ServeError(w, r, fmt.Errorf("invalid document blobRef %q", r.FormValue("docref")))
590 return
591 }
592
593 mode := r.FormValue("mode")
594 if mode == "break" {
595 if err := h.breakAndDeleteDoc(ctx, docRef); err != nil {
596 httputil.ServeError(w, r, fmt.Errorf("could not delete document %v: %v", docRef, err))
597 return
598 }
599 fmt.Fprintf(w, "<html><body>[&lt;&lt; <a href='%s'>Back</a>] Doc %s deleted and images broken out as un-annotated.</body></html>", baseURL(r), docRef)
600 return
601 }
602 if mode == "delete" {
603 if err := h.deleteDocAndImages(ctx, docRef); err != nil {
604 httputil.ServeError(w, r, fmt.Errorf("could not do full delete of %v: %v", docRef, err))
605 return
606 }
607 fmt.Fprintf(w, "<html><body>[&lt;&lt; <a href='%s'>Back</a>] Doc %s and its images deleted.</body></html>", baseURL(r), docRef)
608 return
609 }
610
611 document := &document{}
612 document.physicalLocation = r.FormValue("physical_location")
613 document.title = r.FormValue("title")
614 document.tags = newSeparatedString(r.FormValue("tags"))
615
616 docDate, err := dateOrZero(r.FormValue("date"), dateformatYyyyMmDd)
617 if err != nil {
618 httputil.ServeError(w, r, fmt.Errorf("could not assign new date to document: %v", err))
619 return
620 }
621 document.docDate = docDate
622
623 duedate, err := dateOrZero(r.FormValue("due_date"), dateformatYyyyMmDd)
624 if err != nil {
625 httputil.ServeError(w, r, fmt.Errorf("could not assign new due date to document: %v", err))
626 return
627 }
628 document.dueDate = duedate
629
630 if err := h.updateDocument(ctx, docRef, document); err != nil {
631 httputil.ServeError(w, r, fmt.Errorf("could not update document %v: %v", docRef, err))
632 return
633 }
634
635 http.Redirect(w, r, fmt.Sprintf("%s?saved_doc=%s", baseURL(r), docRef), http.StatusFound)
636}
637

Callers

nothing calls this directly

Calls 10

breakAndDeleteDocMethod · 0.95
deleteDocAndImagesMethod · 0.95
updateDocumentMethod · 0.95
ParseFunction · 0.92
ServeErrorFunction · 0.92
newSeparatedStringFunction · 0.85
dateOrZeroFunction · 0.85
ContextMethod · 0.80
baseURLFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected