(app *App, w http.ResponseWriter, r *http.Request)
| 698 | } |
| 699 | |
| 700 | func existingPost(app *App, w http.ResponseWriter, r *http.Request) error { |
| 701 | reqJSON := IsJSON(r) |
| 702 | vars := mux.Vars(r) |
| 703 | postID := vars["post"] |
| 704 | |
| 705 | p := AuthenticatedPost{ID: postID} |
| 706 | var err error |
| 707 | |
| 708 | if reqJSON { |
| 709 | // Decode JSON request |
| 710 | decoder := json.NewDecoder(r.Body) |
| 711 | err = decoder.Decode(&p) |
| 712 | if err != nil { |
| 713 | log.Error("Couldn't parse post update JSON request: %v\n", err) |
| 714 | return ErrBadJSON |
| 715 | } |
| 716 | } else { |
| 717 | err = r.ParseForm() |
| 718 | if err != nil { |
| 719 | log.Error("Couldn't parse post update form request: %v\n", err) |
| 720 | return ErrBadFormData |
| 721 | } |
| 722 | |
| 723 | // Can't decode to a nil SubmittedPost property, so create instance now |
| 724 | p.SubmittedPost = &SubmittedPost{} |
| 725 | err = app.formDecoder.Decode(&p, r.PostForm) |
| 726 | if err != nil { |
| 727 | log.Error("Couldn't decode post update form request: %v\n", err) |
| 728 | return ErrBadFormData |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | if p.Web { |
| 733 | p.IsRTL.Valid = true |
| 734 | } |
| 735 | |
| 736 | if p.SubmittedPost == nil { |
| 737 | return ErrPostNoUpdatableVals |
| 738 | } |
| 739 | |
| 740 | // Ensure an access token was given |
| 741 | accessToken := r.Header.Get("Authorization") |
| 742 | // Get user's cookie session if there's no token |
| 743 | var u *User |
| 744 | //var username string |
| 745 | if accessToken == "" { |
| 746 | u = getUserSession(app, r) |
| 747 | if u != nil { |
| 748 | //username = u.Username |
| 749 | } |
| 750 | } |
| 751 | if u == nil && accessToken == "" { |
| 752 | return ErrNoAccessToken |
| 753 | } |
| 754 | |
| 755 | // Get user ID from current session or given access token, if one was given. |
| 756 | var userID int64 |
| 757 | if u != nil { |
nothing calls this directly
no test coverage detected