-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM perl:5.38.0-bookworm | ||
|
||
WORKDIR /tmp | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get update && \ | ||
apt-get -y upgrade && \ | ||
apt-get install -y wget gcc g++ make sqlite3 locales locales-all && \ | ||
wget -q https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb && \ | ||
apt-get -y install ./mysql-apt-config_0.8.22-1_all.deb && \ | ||
apt-get -y update && \ | ||
apt-get -y install default-mysql-client | ||
|
||
RUN locale-gen en_US.UTF-8 | ||
RUN useradd --uid=1001 --create-home isucon | ||
USER isucon | ||
|
||
RUN mkdir -p /home/isucon/webapp/perl | ||
WORKDIR /home/isucon/webapp/perl | ||
|
||
COPY cpanfile ./ | ||
RUN cpm install | ||
|
||
COPY --chown=isucon:isucon ./ /home/isucon/webapp/perl/ | ||
ENV PERL5LIB=/home/isucon/webapp/perl/local/lib/perl5 | ||
ENV PATH=/home/isucon/webapp/perl/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | ||
|
||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
EXPOSE 8080 | ||
CMD ["./local/bin/plackup", "-s", "Starlet", "-p", "8080", "-Ilib", "app.psgi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use v5.38; | ||
|
||
use File::Basename; | ||
use Plack::Builder; | ||
use Isupipe::App; | ||
|
||
my $root_dir = File::Basename::dirname(__FILE__); | ||
|
||
my $app = Isupipe::App->psgi($root_dir); | ||
|
||
builder { | ||
enable 'ReverseProxy'; | ||
enable 'Session::Cookie', | ||
session_key => 'isupipe_perl', | ||
domain => 'u.isucon.dev', | ||
path => '/', | ||
expires => 3600, | ||
secret => $ENV{ISUCON13_SESSION_SECRETKEY} || 'defaultsecret'; | ||
$app; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
requires 'perl', '5.038'; | ||
|
||
requires 'Kossy', '0.62'; | ||
requires 'Plack::Middleware::Session', '0.33'; | ||
requires 'HTTP::Message', '6.45'; | ||
requires 'Cpanel::JSON::XS', '4.37'; | ||
requires 'Starlet', '0.31'; | ||
requires 'DBD::mysql', '4.050'; | ||
requires 'DBIx::Sunny', '0.9993'; | ||
requires 'Log::Minimal', '0.19'; | ||
requires 'Type::Tiny', '2.004000'; | ||
requires 'Crypt::Eksblowfish::Bcrypt', '0.009'; | ||
requires 'Crypt::OpenSSL::Random', '0.15'; | ||
requires 'Data::UUID', '1.226'; | ||
requires 'Data::Lock', '1.03'; | ||
|
||
# あとで消す | ||
requires 'Test2::V0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package Isupipe::App; | ||
use v5.38; | ||
use utf8; | ||
|
||
use Kossy; | ||
use HTTP::Status qw(:constants); | ||
use Cpanel::JSON::XS::Type; | ||
use Log::Minimal; | ||
use DBIx::Sunny; | ||
|
||
$Kossy::JSON_SERIALIZER = Cpanel::JSON::XS->new()->ascii(0)->convert_blessed; | ||
|
||
use Isupipe::App::TopHandler; | ||
use Isupipe::App::UserHandler; | ||
use Isupipe::App::LivestreamHandler; | ||
|
||
sub connect_db() { | ||
my $host = $ENV{ISUCON13_MYSQL_DIALCONFIG_ADDRESS} || '127.0.0.1'; | ||
my $port = $ENV{ISUCON13_MYSQL_DIALCONFIG_PORT} || '3306'; | ||
my $user = $ENV{ISUCON13_MYSQL_DIALCONFIG_USER} || 'isucon'; | ||
my $password = $ENV{ISUCON13_MYSQL_DIALCONFIG_PASSWORD} || 'isucon'; | ||
my $dbname = $ENV{ISUCON13_MYSQL_DIALCONFIG_DATABASE} || 'isupipe'; | ||
|
||
my $dsn = "dbi:mysql:database=$dbname;host=$host;port=$port"; | ||
my $dbh = DBIx::Sunny->connect($dsn, $user, $password, { | ||
mysql_enable_utf8mb4 => 1, | ||
mysql_auto_reconnect => 1, | ||
}); | ||
return $dbh; | ||
} | ||
|
||
sub dbh($self) { | ||
$self->{_dbh} //= connect_db(); | ||
} | ||
|
||
sub initialize_handler($self, $c) { | ||
my $e = system($self->root_dir . "/../init.sh"); | ||
if ($e) { | ||
warnf("init.sh failed with err=%s", $e); | ||
$c->halt(HTTP_INTERNAL_SERVER_ERROR, $e); | ||
} | ||
|
||
return $c->render_json({ | ||
advertise_level => 10, | ||
language => 'perl', | ||
}); | ||
} | ||
|
||
|
||
filter 'allow_json_request_filter' => sub ($cb) { | ||
return sub ($app, $c) { | ||
$c->env->{'kossy.request.parse_json_body'} = 1; | ||
$cb->($app, $c); | ||
}; | ||
}; | ||
|
||
# 初期化 | ||
post '/api/initialize', \&initialize_handler; | ||
|
||
# top | ||
get '/api/tag', Isupipe::App::TopHandler->can('get_tag_handler'); | ||
get '/api/user/:username/theme', Isupipe::App::TopHandler->can('get_streamer_theme_handler'); | ||
|
||
# livestream | ||
# reserve livestream | ||
post '/api/livestream/reservation', ['allow_json_request_filter'], Isupipe::App::LivestreamHandler->can('reserve_livestream_handler'); | ||
|
||
get '/search_livestream', Isupipe::App::TopHandler->can('search_livestreams_by_tag_handler'); | ||
# post '/livestream/reservation', \&reserve_livestream_handler; | ||
# # list livestream | ||
# get '/livestream', \&get_livestreams_handler; | ||
# # get livestream | ||
# get '/livestream/:livestream_id', \&get_livestream_handler; | ||
# # get polling livecomment timeline | ||
# get '/livestream/:livestream_id/livecomment', \&get_livecomments_handler; | ||
# # ライブコメント投稿 | ||
# post '/livestream/:livestream_id/livecomment', \&post_livecomment_handler; | ||
# post '/livestream/:livestream_id/reaction', \&post_reaction_handler; | ||
# get '/livestream/:livestream_id/reaction', \&get_reactions_handler; | ||
# | ||
# # (配信者向け)ライブコメント一覧取得API | ||
# get '/livestream/:livestream_id/report', \&get_livecomment_reports_handler; | ||
# # ライブコメント報告 | ||
# post '/livestream/:livestream_id/livecomment/:livecomment_id/report', \&report_livecomment_handler; | ||
# # 配信者によるモデレーション (NGワード登録) | ||
# post '/livestream/:livestream_id/moderate', \&moderate_ngword_handler; | ||
# | ||
# # livestream_viewersにINSERTするため必要 | ||
# # ユーザ視聴開始 (viewer) | ||
# post '/livestream/:livestream_id/enter', \&enter_livestream_handler; | ||
# | ||
# # ユーザ視聴終了 (viewer) | ||
# router 'DELETE' => '/livestream/:livestream_id/enter', \&leave_livestream_handler; | ||
# | ||
# # user | ||
#post '/user', \&user_register_handler; | ||
post '/api/login', ['allow_json_request_filter'], Isupipe::App::UserHandler->can('login_handler'); | ||
# get '/user', \&get_users_handler; | ||
# | ||
# # FIXME: ユーザ一覧を返すAPI | ||
# # フロントエンドで、配信予約のコラボレーターを指定する際に必要 | ||
# get '/user/:user_id', \&user_handler; | ||
# get '/user/:user_id/theme', \&get_user_theme_handler; | ||
# get '/user/:user_id/statistics', \&get_user_statistics_handler; | ||
# | ||
# # stats | ||
# # ライブコメント統計情報 | ||
# get '/livestream/:livestream_id/statistics', \&get_livestream_statistics_handler; | ||
|
Oops, something went wrong.