MCPcopy Index your code
hub / github.com/writefreely/writefreely / dispersePost

Function dispersePost

posts.go:1015–1048  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1013}
1014
1015func dispersePost(app *App, w http.ResponseWriter, r *http.Request) error {
1016 var ownerID int64
1017
1018 // Authenticate user
1019 at := r.Header.Get("Authorization")
1020 if at != "" {
1021 ownerID = app.db.GetUserID(at)
1022 if ownerID == -1 {
1023 return ErrBadAccessToken
1024 }
1025 } else {
1026 u := getUserSession(app, r)
1027 if u == nil {
1028 return ErrNotLoggedIn
1029 }
1030 ownerID = u.ID
1031 }
1032
1033 // Parse posts in format:
1034 // ["..."]
1035 var postIDs []string
1036 decoder := json.NewDecoder(r.Body)
1037 err := decoder.Decode(&postIDs)
1038 if err != nil {
1039 return ErrBadJSONArray
1040 }
1041
1042 // Update all given posts
1043 res, err := app.db.DispersePosts(ownerID, postIDs)
1044 if err != nil {
1045 return err
1046 }
1047 return impart.WriteSuccess(w, res, http.StatusOK)
1048}
1049
1050type (
1051 PinPostResult struct {

Callers

nothing calls this directly

Calls 3

getUserSessionFunction · 0.85
GetUserIDMethod · 0.65
DispersePostsMethod · 0.65

Tested by

no test coverage detected