MCPcopy
hub / github.com/writefreely/writefreely / viewCollectionPost

Function viewCollectionPost

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

Source from the content-addressed store, hash-verified

1457}
1458
1459func viewCollectionPost(app *App, w http.ResponseWriter, r *http.Request) error {
1460 vars := mux.Vars(r)
1461 slug := vars["slug"]
1462
1463 // NOTE: until this is done better, be sure to keep this in parity with
1464 // isRaw() and handleViewPost()
1465 isJSON := strings.HasSuffix(slug, ".json")
1466 isXML := strings.HasSuffix(slug, ".xml")
1467 isMarkdown := strings.HasSuffix(slug, ".md")
1468 isRaw := strings.HasSuffix(slug, ".txt") || isJSON || isXML || isMarkdown
1469
1470 cr := &collectionReq{}
1471 err := processCollectionRequest(cr, vars, w, r)
1472 if err != nil {
1473 return err
1474 }
1475
1476 // Check for hellbanned users
1477 u, err := checkUserForCollection(app, cr, r, true)
1478 if err != nil {
1479 return err
1480 }
1481
1482 // Normalize the URL, redirecting user to consistent post URL
1483 if slug != strings.ToLower(slug) {
1484 loc := fmt.Sprintf("/%s", strings.ToLower(slug))
1485 if !app.cfg.App.SingleUser {
1486 loc = "/" + cr.alias + loc
1487 }
1488 return impart.HTTPError{http.StatusMovedPermanently, loc}
1489 }
1490
1491 // Display collection if this is a collection
1492 var c *Collection
1493 if app.cfg.App.SingleUser {
1494 c, err = app.db.GetCollectionByID(1)
1495 } else {
1496 c, err = app.db.GetCollection(cr.alias)
1497 }
1498 if err != nil {
1499 if err, ok := err.(impart.HTTPError); ok {
1500 if err.Status == http.StatusNotFound {
1501 // Redirect if necessary
1502 newAlias := app.db.GetCollectionRedirect(cr.alias)
1503 if newAlias != "" {
1504 return impart.HTTPError{http.StatusFound, "/" + newAlias + "/" + slug}
1505 }
1506 }
1507 }
1508 return err
1509 }
1510 c.hostName = app.cfg.App.Host
1511
1512 silenced, err := app.db.IsUserSilenced(c.OwnerID)
1513 if err != nil {
1514 log.Error("view collection post: %v", err)
1515 }
1516

Callers

nothing calls this directly

Calls 15

IsPrivateMethod · 0.95
IsProtectedMethod · 0.95
CanonicalURLMethod · 0.95
processPostMethod · 0.95
EmailSubsEnabledMethod · 0.95
HoneypotFieldNameFunction · 0.92
processCollectionRequestFunction · 0.85
checkUserForCollectionFunction · 0.85
NewCollectionObjFunction · 0.85
IsActivityPubRequestFunction · 0.85
setCacheControlFunction · 0.85

Tested by

no test coverage detected