. Licensed under the GNU Affero General Public License v3.0. // See the LICENCE file in the repository root for full licence text. namespace App\Http\Controllers; use App\Libraries\CommentBundle; use App\Models\NewsPost; /** * @group News */ class NewsController extends Controller { /** * Get News Listing * * Returns a list of news posts and related metadata. * * --- * * ### Response Format * * Field | Type | Notes * ------------------------- | ----------------------------- | ----- * cursor_string | [CursorString](#cursorstring) | | * news_posts | [NewsPost](#newspost)[] | Includes `preview`. * news_sidebar.current_year | integer | Year of the first post's publish time, or current year if no posts returned. * news_sidebar.news_posts | [NewsPost](#newspost)[] | All posts published during `current_year`. * news_sidebar.years | integer[] | All years during which posts have been published. * search.limit | integer | Clamped limit input. * search.sort | string | Always `published_desc`. * * * * @usesCursor * @queryParam limit integer Maximum number of posts (12 default, 1 minimum, 21 maximum). No-example * @queryParam year integer Year to return posts from. No-example * @response { * "news_posts": [ * { * "id": 964, * "author": "RockRoller", * "edit_url": "https://github.com/ppy/osu-wiki/tree/master/news/2021-05-27-skinning-contest-results.md", * "first_image": "https://i.ppy.sh/d431ff921955d5c8792dc9bae40ac082d4e53131/68747470733a2f2f6f73752e7070792e73682f77696b692f696d616765732f7368617265642f6e6577732f323032312d30352d32372d736b696e6e696e672d636f6e746573742d726573756c74732f736b696e6e696e675f636f6e746573745f62616e6e65722e6a7067", * "published_at": "2021-05-27T12:00:00+00:00", * "updated_at": "2021-05-28T17:11:35+00:00", * "slug": "2021-05-27-skinning-contest-results", * "title": "Skinning Contest: Results Out", * "preview": "The ship full of skins is now back with your votes. Check out the results for our first-ever official skinning contest right here!" * }, * // ... * ], * "news_sidebar": { * "current_year": 2021, * "news_posts": [ * { * "id": 964, * "author": "RockRoller", * "edit_url": "https://github.com/ppy/osu-wiki/tree/master/news/2021-05-27-skinning-contest-results.md", * "first_image": "https://i.ppy.sh/d431ff921955d5c8792dc9bae40ac082d4e53131/68747470733a2f2f6f73752e7070792e73682f77696b692f696d616765732f7368617265642f6e6577732f323032312d30352d32372d736b696e6e696e672d636f6e746573742d726573756c74732f736b696e6e696e675f636f6e746573745f62616e6e65722e6a7067", * "published_at": "2021-05-27T12:00:00+00:00", * "updated_at": "2021-05-28T17:11:35+00:00", * "slug": "2021-05-27-skinning-contest-results", * "title": "Skinning Contest: Results Out" * }, * // ... * ], * "years": [2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013] * }, * "search": { * "limit": 12, * "sort": "published_desc" * }, * "cursor_string": "WyJodHRwczpcL1wvd3d3LnlvdXR1YmUuY29tXC93YXRjaD92PWRRdzR3OVdnWGNRIl0" * } */ public function index() { $params = request()->all(); $format = $params['format'] ?? null; $isFeed = $format === 'atom' || $format === 'rss'; $limit = $isFeed ? 20 : 12; $search = NewsPost::search(array_merge(compact('limit'), $params)); [$posts, $hasMore] = $search['query']->getWithHasMore(); if ($isFeed) { return ext_view("news.index-{$format}", compact('posts'), $format); } $postsJson = [ 'news_posts' => json_collection($posts, 'NewsPost', ['preview']), 'news_sidebar' => $this->sidebarMeta($posts[0] ?? null), 'search' => $search['params'], ...cursor_for_response($search['cursorHelper']->next($posts, $hasMore)), ]; if (is_json_request()) { return $postsJson; } else { // force current year search parameter for html $postsJson['search']['year'] = $postsJson['news_sidebar']['current_year']; return ext_view('news.index', [ 'atom' => [ 'url' => route('news.index', ['format' => 'atom']), 'title' => 'osu!news Feed', ], 'postsJson' => $postsJson, ]); } } public function redirect($tumblrId) { $post = NewsPost::where('tumblr_id', $tumblrId)->firstOrFail(); return ujs_redirect(route('news.show', $post->slug)); } /** * Get News Post * * Returns details of the specified news post. * * --- * * ### Response Format * * Returns a [NewsPost](#newspost) with `content` and `navigation` included. * * @urlParam news string required News post slug or ID. Example: 2021-04-27-results-a-labour-of-love * @queryParam key string Unset to query by slug, or `id` to query by ID. No-example * @response { * "id": 943, * "author": "pishifat", * "edit_url": "https://github.com/ppy/osu-wiki/tree/master/news/2021-04-27-results-a-labour-of-love.md", * "first_image": "https://i.ppy.sh/65c9c2eb2f8d9bc6008b95aba7d0ef45e1414c1e/68747470733a2f2f6f73752e7070792e73682f77696b692f696d616765732f7368617265642f6e6577732f323032302d31312d33302d612d6c61626f75722d6f662d6c6f76652f616c6f6c5f636f7665722e6a7067", * "published_at": "2021-04-27T20:00:00+00:00", * "updated_at": "2021-04-27T20:25:57+00:00", * "slug": "2021-04-27-results-a-labour-of-love", * "title": "Results - A Labour of Love", * "content": "