annotate app/controllers/tweets_controller.rb @ 253:d726e8b92dd1

Support animated gif (same as video)
author nanaya <me@nanaya.net>
date Mon, 25 Mar 2024 02:49:50 +0900
parents 4222343d9433
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
1 class TweetsController < ApplicationController
38
9e03bbbb1d43 Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents: 28
diff changeset
2 def index
234
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
3 return redirect if params[:name].present?
38
9e03bbbb1d43 Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents: 28
diff changeset
4 end
9e03bbbb1d43 Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents: 28
diff changeset
5
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
6 def show
233
0f0cc55ff11b Character class, not literal D
nanaya <me@nanaya.net>
parents: 207
diff changeset
7 return redirect if params[:id][/\D/].present?
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
8
234
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
9 @user = CachedFetch.user_by_id params[:id]
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
10
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
11 if @user.nil?
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
12 head :not_found
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
13 return
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
14 end
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
15
235
4222343d9433 No access to protected user
nanaya <me@nanaya.net>
parents: 234
diff changeset
16 if @user[:protected]
4222343d9433 No access to protected user
nanaya <me@nanaya.net>
parents: 234
diff changeset
17 head :forbidden
4222343d9433 No access to protected user
nanaya <me@nanaya.net>
parents: 234
diff changeset
18 return
4222343d9433 No access to protected user
nanaya <me@nanaya.net>
parents: 234
diff changeset
19 end
4222343d9433 No access to protected user
nanaya <me@nanaya.net>
parents: 234
diff changeset
20
203
af84c9f23263 Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents: 166
diff changeset
21 return redirect if normalized_screen_name != params[:name]
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
22
234
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
23 @tweets = CachedFetch.timeline params[:id]
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
24
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
25 head :not_found if @tweets.nil?
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
26 end
55
8f68ca606099 Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents: 48
diff changeset
27
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
28 def redirect
234
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
29 @user ||= CachedFetch.user_by_username(params[:name])
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
30
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
31 if @user.nil?
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
32 head :not_found
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
33 else
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
34 redirect_to tweet_path(@user[:id], normalized_screen_name)
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
35 end
55
8f68ca606099 Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents: 48
diff changeset
36 end
203
af84c9f23263 Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents: 166
diff changeset
37
af84c9f23263 Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents: 166
diff changeset
38 private
205
8190fa511e35 Fix some code style
nanaya <me@nanaya.pro>
parents: 203
diff changeset
39
203
af84c9f23263 Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents: 166
diff changeset
40 def normalized_screen_name
234
7a773720d81f Totally legit client
nanaya <me@nanaya.net>
parents: 233
diff changeset
41 @user[:username].presence || '_'
203
af84c9f23263 Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents: 166
diff changeset
42 end
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
43 end