(app *App, w http.ResponseWriter, r *http.Request)
| 1457 | } |
| 1458 | |
| 1459 | func 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 |
nothing calls this directly
no test coverage detected