forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatches_controller.rb
More file actions
159 lines (134 loc) · 4.7 KB
/
matches_controller.rb
File metadata and controls
159 lines (134 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
class MatchesController < ApplicationController
def show
@match = ESDB::Match.find(params[:id])
not_found and return if !@match
blob_url = "https://#{Rails.configuration.s3['matchblobs']['bucket']}.s3.amazonaws.com/#{@match.id}"
begin
blob_response = Curl.get(blob_url)
rescue Exception => e
# sometimes there are random problems retrieving from S3. we
# dont need to hear about each one.
# TODO complain if there are too many consecutive failures
end
# trying to deal better with nonsense like this: https://www.exceptional.io/exceptions/118713598
if !@match.ended_at
# TODO report this to a human or not? This is bad, but it can
# also happen if ESDB is temporarily down.
not_found and return
end
# If the match was requested via a md5 (as given out by sc2gears) redirect
# to the correct URL if it is found or display "we're still processing"
# message otherwise
unless params[:id].to_i.to_s == params[:id]
redirect_to(match_url(@match.id), status: 302) and return if @match # Moved!
render 'processing' and return
end
# How to do next/prev?!
#
#
# if any of
# match.entities.identity.id
# match any of
# current_user.accounts.esdb_id
#
# and there is only one match, then we are in business!
#
# then the prev match can be:
# ggtracker.com/matches/prev?identity=<esdb_identity_id>&match=<esdb_match_id>
# ggtracker.com/matches/next?identity=<esdb_identity_id>&match=<esdb_match_id>
# api.esdb.net/api/v1/matches/prev?identity=<esdb_identity_id>&match=<esdb_match_id>
# api.esdb.net/api/v1/matches/next?identity=<esdb_identity_id>&match=<esdb_match_id>
#
#
gon.match = @match.to_hash
if blob_response && blob_response.status[0] == '2'
gon.matchblob = blob_response.body_str
# else
# Rails.logger.warn("Got blob response status #{blob_response.status} for match #{@match.id}")
end
end
def index
end
def search
end
def userdelete
authenticate_user!
@match = ESDB::Match.find(params[:id])
not_found and return if !@match
not_found and return if !can_delete(@match)
response = @match.userdelete(current_user.id)
if response['status'] == 'success'
render :text => "OK", :status => 200
else
render :text => "Not OK", :status => 500
end
end
def can_delete(match)
if !current_user
return false
end
if current_user.id == 2830
return true
end
idents_in_match = match.entities.collect { |entity| entity['identity']['id'].to_i }
my_match = current_user.accounts.any? { |account| account.state == 'authed' && idents_in_match.include?(account.esdb_id) }
return my_match
end
def show_delete_link?
can_delete(@match)
end
def replay
@match = ESDB::Match.find(params[:id])
replay = @match.replays.first
bucketname = Rails.configuration.s3['replays']['bucket']
s3_filename = "#{replay.md5}.SC2Replay"
replay_url = "https://#{bucketname}.s3.amazonaws.com/#{s3_filename}"
replay_response = Curl.get(replay_url)
if replay_response.status[0] == '2'
user_filename = "ggtracker_#{@match.id}.SC2Replay"
send_data(replay_response.body_str, :filename => user_filename)
end
end
def wcsmatch
@match = ESDB::Match.find(1464)
blob_url = "https://#{Rails.configuration.s3['matchblobs']['bucket']}.s3.amazonaws.com/#{@match.id}"
begin
blob_response = Curl.get(blob_url)
rescue Exception => e
# sometimes there are random problems retrieving from S3. we
# dont need to hear about each one.
# TODO complain if there are too many consecutive failures
end
gon.match = @match.to_hash
if blob_response && blob_response.status[0] == '2'
gon.matchblob = blob_response.body_str
end
render :layout => 'wcs'
end
def wcsmatch2
@match = ESDB::Match.find(params[:id])
blob_url = "https://#{Rails.configuration.s3['matchblobs']['bucket']}.s3.amazonaws.com/#{@match.id}"
begin
blob_response = Curl.get(blob_url)
rescue Exception => e
# sometimes there are random problems retrieving from S3. we
# dont need to hear about each one.
# TODO complain if there are too many consecutive failures
end
gon.match = @match.to_hash
if blob_response && blob_response.status[0] == '2'
gon.matchblob = blob_response.body_str
end
render :layout => 'wcs2'
end
def cobrand?
return false if @match.nil?
# DJ 20130911 maybe this code should be revived for ESL refactor?
# Is cobrand passed through by the API?
#
# @match.cobrand.present?
replay = Replay.where(:esdb_id => @match.id.to_s).first
return false if replay.nil?
replay.channel == Rails.application.secret('wcs_cobrand')
end
end