diff --git a/.gitignore b/.gitignore index 0ccd925..b994b06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ local/* files/* lufi.conf -lufi.db +*.db +*.db-shm +*.db-wal +*.bak *.swp script/hypnotoad.pid stop-upload diff --git a/CHANGELOG b/CHANGELOG index 2c9740b..acebc26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ Revision history for Lufi +0.03 2018-??-?? + - Use Mojo::SQLite instead of ORLite + 0.02.2 2017-09-18 - Fix cron tasks bug diff --git a/Makefile b/Makefile index d56ddf4..8b75700 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ podcheck: podchecker lib/Lufi/DB/File.pm lib/Lufi/DB/Slice.pm test: - $(CARTON) $(REAL_LUFI) test + $(CARTON) prove -l -f -o t/basic.t clean: rm -rf lufi.db files/ diff --git a/cpanfile b/cpanfile index ce9893b..3ab3ad7 100644 --- a/cpanfile +++ b/cpanfile @@ -28,5 +28,5 @@ feature 'postgresql', 'PostgreSQL support' => sub { requires 'Mojolicious::Plugin::PgURLHelper'; }; feature 'sqlite', 'SQLite support' => sub { - requires 'ORLite'; + requires 'Mojo::SQLite', '>= 3.000'; } diff --git a/cpanfile.snapshot b/cpanfile.snapshot index 19226ce..423a1de 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -36,21 +36,6 @@ DISTRIBUTIONS Canary::Stability 2012 requirements: ExtUtils::MakeMaker 0 - Capture-Tiny-0.46 - pathname: D/DA/DAGOLDEN/Capture-Tiny-0.46.tar.gz - provides: - Capture::Tiny 0.46 - requirements: - Carp 0 - Exporter 0 - ExtUtils::MakeMaker 6.17 - File::Spec 0 - File::Temp 0 - IO::Handle 0 - Scalar::Util 0 - perl 5.006 - strict 0 - warnings 0 Class-Method-Modifiers-2.12 pathname: E/ET/ETHER/Class-Method-Modifiers-2.12.tar.gz provides: @@ -64,13 +49,14 @@ DISTRIBUTIONS perl 5.006 strict 0 warnings 0 - Clone-0.39 - pathname: G/GA/GARU/Clone-0.39.tar.gz + Clone-Choose-0.010 + pathname: H/HE/HERMES/Clone-Choose-0.010.tar.gz provides: - Clone 0.39 + Clone::Choose 0.010 requirements: ExtUtils::MakeMaker 0 - Test::More 0 + Storable 0 + perl 5.008001 Convert-ASN1-0.27 pathname: G/GB/GBARR/Convert-ASN1-0.27.tar.gz provides: @@ -105,24 +91,24 @@ DISTRIBUTIONS ExtUtils::MakeMaker 6.30 Test::Fatal 0 Test::More 0 - DBD-Pg-3.6.2 - pathname: T/TU/TURNSTEP/DBD-Pg-3.6.2.tar.gz + DBD-Pg-3.7.4 + pathname: T/TU/TURNSTEP/DBD-Pg-3.7.4.tar.gz provides: - Bundle::DBD::Pg v3.6.2 - DBD::Pg v3.6.2 + Bundle::DBD::Pg v3.7.4 + DBD::Pg v3.7.4 requirements: DBI 1.614 ExtUtils::MakeMaker 6.11 Test::More 0.88 Time::HiRes 0 version 0 - DBD-SQLite-1.54 - pathname: I/IS/ISHIGAKI/DBD-SQLite-1.54.tar.gz + DBD-SQLite-1.58 + pathname: I/IS/ISHIGAKI/DBD-SQLite-1.58.tar.gz provides: - DBD::SQLite 1.54 + DBD::SQLite 1.58 DBD::SQLite::Constants undef - DBD::SQLite::VirtualTable 1.54 - DBD::SQLite::VirtualTable::Cursor 1.54 + DBD::SQLite::VirtualTable 1.58 + DBD::SQLite::VirtualTable::Cursor 1.58 DBD::SQLite::VirtualTable::FileContent undef DBD::SQLite::VirtualTable::FileContent::Cursor undef DBD::SQLite::VirtualTable::PerlData undef @@ -135,8 +121,8 @@ DISTRIBUTIONS Test::More 0.47 Tie::Hash 0 perl 5.006 - DBI-1.636 - pathname: T/TI/TIMB/DBI-1.636.tar.gz + DBI-1.641 + pathname: T/TI/TIMB/DBI-1.641.tar.gz provides: Bundle::DBI 12.008696 DBD::DBM 0.08 @@ -171,6 +157,13 @@ DISTRIBUTIONS DBD::Gofer::db 0.015327 DBD::Gofer::dr 0.015327 DBD::Gofer::st 0.015327 + DBD::Mem 0.001 + DBD::Mem::DataSource 0.001 + DBD::Mem::Statement 0.001 + DBD::Mem::Table 0.001 + DBD::Mem::db 0.001 + DBD::Mem::dr 0.001 + DBD::Mem::st 0.001 DBD::NullP 12.014715 DBD::NullP::db 12.014715 DBD::NullP::dr 12.014715 @@ -185,7 +178,7 @@ DISTRIBUTIONS DBD::Sponge::dr 12.010003 DBD::Sponge::st 12.010003 DBDI 12.015129 - DBI 1.636 + DBI 1.641 DBI::Const::GetInfo::ANSI 2.008697 DBI::Const::GetInfo::ODBC 2.011374 DBI::Const::GetInfoReturn 2.008697 @@ -225,7 +218,7 @@ DISTRIBUTIONS DBI::SQL::Nano::Table_ 1.015544 DBI::Util::CacheMemory 0.010315 DBI::Util::_accessor 0.009479 - DBI::common 1.636 + DBI::common 1.641 requirements: ExtUtils::MakeMaker 6.48 Test::Simple 0.90 @@ -257,10 +250,10 @@ DISTRIBUTIONS perl 5.006 strict 0 warnings 0 - Data-Float-0.012 - pathname: Z/ZE/ZEFRAM/Data-Float-0.012.tar.gz + Data-Float-0.013 + pathname: Z/ZE/ZEFRAM/Data-Float-0.013.tar.gz provides: - Data::Float 0.012 + Data::Float 0.013 requirements: Carp 0 Exporter 0 @@ -317,6 +310,7 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 0 Mail::Address 0 + Net::DNS 0 Scalar::Util 0 Test::More 0 perl 5.006 @@ -329,6 +323,45 @@ DISTRIBUTIONS Encode::Alias 0 ExtUtils::MakeMaker 0 perl 5.008 + ExtUtils-Config-0.008 + pathname: L/LE/LEONT/ExtUtils-Config-0.008.tar.gz + provides: + ExtUtils::Config 0.008 + requirements: + Data::Dumper 0 + ExtUtils::MakeMaker 6.30 + strict 0 + warnings 0 + ExtUtils-Helpers-0.026 + pathname: L/LE/LEONT/ExtUtils-Helpers-0.026.tar.gz + provides: + ExtUtils::Helpers 0.026 + ExtUtils::Helpers::Unix 0.026 + ExtUtils::Helpers::VMS 0.026 + ExtUtils::Helpers::Windows 0.026 + requirements: + Carp 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + File::Basename 0 + File::Copy 0 + File::Spec::Functions 0 + Text::ParseWords 3.24 + perl 5.006 + strict 0 + warnings 0 + ExtUtils-InstallPaths-0.012 + pathname: L/LE/LEONT/ExtUtils-InstallPaths-0.012.tar.gz + provides: + ExtUtils::InstallPaths 0.012 + requirements: + Carp 0 + ExtUtils::Config 0.002 + ExtUtils::MakeMaker 0 + File::Spec 0 + perl 5.006 + strict 0 + warnings 0 File-Listing-6.04 pathname: G/GA/GAAS/File-Listing-6.04.tar.gz provides: @@ -342,16 +375,17 @@ DISTRIBUTIONS ExtUtils::MakeMaker 0 HTTP::Date 6 perl 5.006002 - File-Remove-1.57 - pathname: S/SH/SHLOMIF/File-Remove-1.57.tar.gz + File-Remove-1.58 + pathname: S/SH/SHLOMIF/File-Remove-1.58.tar.gz provides: - File::Remove 1.57 + File::Remove 1.58 requirements: Cwd 3.29 ExtUtils::MakeMaker 0 File::Glob 0 File::Path 0 File::Spec 3.29 + Module::Build 0.28 constant 0 perl 5.006 strict 0 @@ -363,10 +397,10 @@ DISTRIBUTIONS Filesys::DfPortable 0.85 requirements: ExtUtils::MakeMaker 0 - Filesys-DiskUsage-0.10 - pathname: M/MA/MANWAR/Filesys-DiskUsage-0.10.tar.gz + Filesys-DiskUsage-0.11 + pathname: M/MA/MANWAR/Filesys-DiskUsage-0.11.tar.gz provides: - Filesys::DiskUsage 0.10 + Filesys::DiskUsage 0.11 requirements: ExtUtils::MakeMaker 0 File::Basename 0 @@ -396,12 +430,12 @@ DISTRIBUTIONS HTML::Tagset 3.20 requirements: ExtUtils::MakeMaker 0 - HTTP-Cookies-6.03 - pathname: O/OA/OALDERS/HTTP-Cookies-6.03.tar.gz + HTTP-Cookies-6.04 + pathname: O/OA/OALDERS/HTTP-Cookies-6.04.tar.gz provides: - HTTP::Cookies 6.03 - HTTP::Cookies::Microsoft 6.03 - HTTP::Cookies::Netscape 6.03 + HTTP::Cookies 6.04 + HTTP::Cookies::Microsoft 6.04 + HTTP::Cookies::Netscape 6.04 requirements: Carp 0 ExtUtils::MakeMaker 0 @@ -447,19 +481,19 @@ DISTRIBUTIONS perl 5.005 strict 0 warnings 0 - HTTP-Message-6.13 - pathname: O/OA/OALDERS/HTTP-Message-6.13.tar.gz - provides: - HTTP::Config 6.13 - HTTP::Headers 6.13 - HTTP::Headers::Auth 6.13 - HTTP::Headers::ETag 6.13 - HTTP::Headers::Util 6.13 - HTTP::Message 6.13 - HTTP::Request 6.13 - HTTP::Request::Common 6.13 - HTTP::Response 6.13 - HTTP::Status 6.13 + HTTP-Message-6.18 + pathname: O/OA/OALDERS/HTTP-Message-6.18.tar.gz + provides: + HTTP::Config 6.18 + HTTP::Headers 6.18 + HTTP::Headers::Auth 6.18 + HTTP::Headers::ETag 6.18 + HTTP::Headers::Util 6.18 + HTTP::Message 6.18 + HTTP::Request 6.18 + HTTP::Request::Common 6.18 + HTTP::Response 6.18 + HTTP::Status 6.18 requirements: Carp 0 Compress::Raw::Zlib 0 @@ -493,13 +527,14 @@ DISTRIBUTIONS ExtUtils::MakeMaker 0 HTTP::Headers 6 perl 5.008001 - Hash-Merge-0.200 - pathname: R/RE/REHSACK/Hash-Merge-0.200.tar.gz + Hash-Merge-0.300 + pathname: R/RE/REHSACK/Hash-Merge-0.300.tar.gz provides: - Hash::Merge 0.200 + Hash::Merge 0.300 requirements: - Clone 0 - ExtUtils::MakeMaker 0 + Clone::Choose 0.008 + ExtUtils::MakeMaker 6.64 + Scalar::Util 0 perl 5.008001 IO-HTML-1.001 pathname: C/CJ/CJM/IO-HTML-1.001.tar.gz @@ -510,28 +545,36 @@ DISTRIBUTIONS Encode 2.10 Exporter 5.57 ExtUtils::MakeMaker 6.30 - IO-Socket-SSL-2.049 - pathname: S/SU/SULLR/IO-Socket-SSL-2.049.tar.gz + IO-Socket-IP-0.39 + pathname: P/PE/PEVANS/IO-Socket-IP-0.39.tar.gz + provides: + IO::Socket::IP 0.39 + requirements: + IO::Socket 0 + Socket 1.97 + Test::More 0.88 + IO-Socket-SSL-2.060 + pathname: S/SU/SULLR/IO-Socket-SSL-2.060.tar.gz provides: - IO::Socket::SSL 2.049 - IO::Socket::SSL::Intercept 2.014 - IO::Socket::SSL::OCSP_Cache 2.049 - IO::Socket::SSL::OCSP_Resolver 2.049 + IO::Socket::SSL 2.060 + IO::Socket::SSL::Intercept 2.056 + IO::Socket::SSL::OCSP_Cache 2.060 + IO::Socket::SSL::OCSP_Resolver 2.060 IO::Socket::SSL::PublicSuffix undef - IO::Socket::SSL::SSL_Context 2.049 - IO::Socket::SSL::SSL_HANDLE 2.049 - IO::Socket::SSL::Session_Cache 2.049 + IO::Socket::SSL::SSL_Context 2.060 + IO::Socket::SSL::SSL_HANDLE 2.060 + IO::Socket::SSL::Session_Cache 2.060 IO::Socket::SSL::Utils 2.014 requirements: ExtUtils::MakeMaker 0 Mozilla::CA 0 Net::SSLeay 1.46 Scalar::Util 0 - JSON-2.94 - pathname: I/IS/ISHIGAKI/JSON-2.94.tar.gz + JSON-2.97001 + pathname: I/IS/ISHIGAKI/JSON-2.97001.tar.gz provides: - JSON 2.94 - JSON::Backend::PP 2.94 + JSON 2.97001 + JSON::Backend::PP 2.97001 requirements: ExtUtils::MakeMaker 0 Test::More 0 @@ -606,12 +649,12 @@ DISTRIBUTIONS File::Basename 0 File::Spec 0 MIME::Types 1.28 - MIME-Types-2.13 - pathname: M/MA/MARKOV/MIME-Types-2.13.tar.gz + MIME-Types-2.17 + pathname: M/MA/MARKOV/MIME-Types-2.17.tar.gz provides: - MIME::Type 2.13 - MIME::Types 2.13 - MojoX::MIME::Types 2.13 + MIME::Type 2.17 + MIME::Types 2.17 + MojoX::MIME::Types 2.17 requirements: ExtUtils::MakeMaker 0 File::Basename 0 @@ -625,31 +668,31 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 0 perl 5.006 - MailTools-2.18 - pathname: M/MA/MARKOV/MailTools-2.18.tar.gz - provides: - Mail undef - Mail::Address 2.18 - Mail::Cap 2.18 - Mail::Field 2.18 - Mail::Field::AddrList 2.18 - Mail::Field::Date 2.18 - Mail::Field::Generic 2.18 - Mail::Filter 2.18 - Mail::Header 2.18 - Mail::Internet 2.18 - Mail::Mailer 2.18 - Mail::Mailer::qmail 2.18 - Mail::Mailer::rfc822 2.18 - Mail::Mailer::sendmail 2.18 - Mail::Mailer::smtp 2.18 - Mail::Mailer::smtp::pipe 2.18 - Mail::Mailer::smtps 2.18 - Mail::Mailer::smtps::pipe 2.18 - Mail::Mailer::testfile 2.18 - Mail::Mailer::testfile::pipe 2.18 - Mail::Send 2.18 - Mail::Util 2.18 + MailTools-2.20 + pathname: M/MA/MARKOV/MailTools-2.20.tar.gz + provides: + Mail::Address 2.20 + Mail::Cap 2.20 + Mail::Field 2.20 + Mail::Field::AddrList 2.20 + Mail::Field::Date 2.20 + Mail::Field::Generic 2.20 + Mail::Filter 2.20 + Mail::Header 2.20 + Mail::Internet 2.20 + Mail::Mailer 2.20 + Mail::Mailer::qmail 2.20 + Mail::Mailer::rfc822 2.20 + Mail::Mailer::sendmail 2.20 + Mail::Mailer::smtp 2.20 + Mail::Mailer::smtp::pipe 2.20 + Mail::Mailer::smtps 2.20 + Mail::Mailer::smtps::pipe 2.20 + Mail::Mailer::testfile 2.20 + Mail::Mailer::testfile::pipe 2.20 + Mail::Send 2.20 + Mail::Util 2.20 + MailTools 2.20 requirements: Date::Format 0 Date::Parse 0 @@ -708,33 +751,151 @@ DISTRIBUTIONS Text::ParseWords 0 perl 5.006001 version 0.87 - Module-Runtime-0.015 - pathname: Z/ZE/ZEFRAM/Module-Runtime-0.015.tar.gz + Module-Build-Tiny-0.039 + pathname: L/LE/LEONT/Module-Build-Tiny-0.039.tar.gz provides: - Module::Runtime 0.015 + Module::Build::Tiny 0.039 + requirements: + CPAN::Meta 0 + DynaLoader 0 + Exporter 5.57 + ExtUtils::CBuilder 0 + ExtUtils::Config 0.003 + ExtUtils::Helpers 0.020 + ExtUtils::Install 0 + ExtUtils::InstallPaths 0.002 + ExtUtils::ParseXS 0 + File::Basename 0 + File::Find 0 + File::Path 0 + File::Spec::Functions 0 + Getopt::Long 2.36 + JSON::PP 2 + Pod::Man 0 + TAP::Harness::Env 0 + perl 5.006 + strict 0 + warnings 0 + Module-Install-1.19 + pathname: E/ET/ETHER/Module-Install-1.19.tar.gz + provides: + Module::AutoInstall 1.19 + Module::Install 1.19 + Module::Install::Admin 1.19 + Module::Install::Admin::Bundle 1.19 + Module::Install::Admin::Compiler 1.19 + Module::Install::Admin::Find 1.19 + Module::Install::Admin::Include 1.19 + Module::Install::Admin::Makefile 1.19 + Module::Install::Admin::Manifest 1.19 + Module::Install::Admin::Metadata 1.19 + Module::Install::Admin::ScanDeps 1.19 + Module::Install::Admin::WriteAll 1.19 + Module::Install::AutoInstall 1.19 + Module::Install::Base 1.19 + Module::Install::Base::FakeAdmin 1.19 + Module::Install::Bundle 1.19 + Module::Install::Can 1.19 + Module::Install::Compiler 1.19 + Module::Install::DSL 1.19 + Module::Install::Deprecated 1.19 + Module::Install::External 1.19 + Module::Install::Fetch 1.19 + Module::Install::Include 1.19 + Module::Install::Inline 1.19 + Module::Install::MakeMaker 1.19 + Module::Install::Makefile 1.19 + Module::Install::Metadata 1.19 + Module::Install::PAR 1.19 + Module::Install::Run 1.19 + Module::Install::Scripts 1.19 + Module::Install::Share 1.19 + Module::Install::Win32 1.19 + Module::Install::With 1.19 + Module::Install::WriteAll 1.19 + inc::Module::Install 1.19 + inc::Module::Install::DSL 1.19 + requirements: + Devel::PPPort 3.16 + ExtUtils::Install 1.52 + ExtUtils::MakeMaker 6.59 + ExtUtils::ParseXS 2.19 + File::Path 0 + File::Remove 1.42 + File::Spec 3.28 + Module::Build 0.29 + Module::CoreList 2.17 + Module::ScanDeps 1.09 + Parse::CPAN::Meta 1.4413 + Test::Harness 3.13 + Test::More 0.86 + YAML::Tiny 1.38 + autodie 0 + perl 5.006 + Module-Runtime-0.016 + pathname: Z/ZE/ZEFRAM/Module-Runtime-0.016.tar.gz + provides: + Module::Runtime 0.016 requirements: Module::Build 0 Test::More 0.41 perl 5.006 strict 0 warnings 0 - Mojo-Pg-4.0 - pathname: S/SR/SRI/Mojo-Pg-4.0.tar.gz + Module-ScanDeps-1.25 + pathname: R/RS/RSCHUPP/Module-ScanDeps-1.25.tar.gz + provides: + Module::ScanDeps 1.25 + requirements: + ExtUtils::MakeMaker 0 + File::Spec 0 + File::Temp 0 + Getopt::Long 0 + Module::Metadata 0 + Text::ParseWords 0 + perl 5.008001 + version 0 + Mojo-Pg-4.11 + pathname: S/SR/SRI/Mojo-Pg-4.11.tar.gz provides: - Mojo::Pg 4.0 + Mojo::Pg 4.11 Mojo::Pg::Database undef Mojo::Pg::Migrations undef Mojo::Pg::PubSub undef Mojo::Pg::Results undef Mojo::Pg::Transaction undef + SQL::Abstract::Pg undef requirements: DBD::Pg 3.005001 ExtUtils::MakeMaker 0 + Mojolicious 8.03 + SQL::Abstract 1.86 + perl 5.010001 + Mojo-SQLite-3.001 + pathname: D/DB/DBOOK/Mojo-SQLite-3.001.tar.gz + provides: + Mojo::SQLite 3.001 + Mojo::SQLite::Database 3.001 + Mojo::SQLite::Migrations 3.001 + Mojo::SQLite::PubSub 3.001 + Mojo::SQLite::Results 3.001 + Mojo::SQLite::Transaction 3.001 + requirements: + Carp 0 + DBD::SQLite 1.54 + DBI 1.627 + File::Spec::Functions 0 + File::Temp 0 + Module::Build::Tiny 0.034 Mojolicious 7.32 SQL::Abstract 1.81 + Scalar::Util 0 + URI 1.69 + URI::db 0.15 + URI::file 4.21 perl 5.010001 - Mojolicious-7.36 - pathname: S/SR/SRI/Mojolicious-7.36.tar.gz + Mojolicious-8.03 + pathname: S/SR/SRI/Mojolicious-8.03.tar.gz provides: Mojo undef Mojo::Asset undef @@ -776,6 +937,7 @@ DISTRIBUTIONS Mojo::Message::Response undef Mojo::Parameters undef Mojo::Path undef + Mojo::Promise undef Mojo::Reactor undef Mojo::Reactor::EV undef Mojo::Reactor::Poll undef @@ -802,23 +964,22 @@ DISTRIBUTIONS Mojo::UserAgent::Transactor undef Mojo::Util undef Mojo::WebSocket undef - Mojolicious 7.36 + Mojolicious 8.03 Mojolicious::Command undef + Mojolicious::Command::Author::cpanify undef + Mojolicious::Command::Author::generate undef + Mojolicious::Command::Author::generate::app undef + Mojolicious::Command::Author::generate::lite_app undef + Mojolicious::Command::Author::generate::makefile undef + Mojolicious::Command::Author::generate::plugin undef + Mojolicious::Command::Author::inflate undef Mojolicious::Command::cgi undef - Mojolicious::Command::cpanify undef Mojolicious::Command::daemon undef Mojolicious::Command::eval undef - Mojolicious::Command::generate undef - Mojolicious::Command::generate::app undef - Mojolicious::Command::generate::lite_app undef - Mojolicious::Command::generate::makefile undef - Mojolicious::Command::generate::plugin undef Mojolicious::Command::get undef - Mojolicious::Command::inflate undef Mojolicious::Command::prefork undef Mojolicious::Command::psgi undef Mojolicious::Command::routes undef - Mojolicious::Command::test undef Mojolicious::Command::version undef Mojolicious::Commands undef Mojolicious::Controller undef @@ -851,13 +1012,14 @@ DISTRIBUTIONS ExtUtils::MakeMaker 0 IO::Socket::IP 0.37 JSON::PP 2.27103 + List::Util 1.41 Pod::Simple 3.09 Time::Local 1.2 perl 5.010001 - Mojolicious-Plugin-Authentication-1.32 - pathname: J/JJ/JJATRIA/Mojolicious-Plugin-Authentication-1.32.tar.gz + Mojolicious-Plugin-Authentication-1.33 + pathname: J/JJ/JJATRIA/Mojolicious-Plugin-Authentication-1.33.tar.gz provides: - Mojolicious::Plugin::Authentication 1.32 + Mojolicious::Plugin::Authentication 1.33 requirements: ExtUtils::MakeMaker 0 Mojo::Base 0 @@ -899,20 +1061,20 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 0 Mojolicious 7.23 - Moo-2.003002 - pathname: H/HA/HAARG/Moo-2.003002.tar.gz + Moo-2.003004 + pathname: H/HA/HAARG/Moo-2.003004.tar.gz provides: Method::Generate::Accessor undef Method::Generate::BuildAll undef Method::Generate::Constructor undef Method::Generate::DemolishAll undef - Moo 2.003002 + Moo 2.003004 Moo::HandleMoose undef Moo::HandleMoose::FakeConstructor undef Moo::HandleMoose::FakeMetaClass undef Moo::HandleMoose::_TypeMap undef Moo::Object undef - Moo::Role 2.003002 + Moo::Role 2.003004 Moo::_Utils undef Moo::_mro undef Moo::_strictures undef @@ -929,21 +1091,137 @@ DISTRIBUTIONS Sub::Defer 2.003001 Sub::Quote 2.003001 perl 5.006 - Mozilla-CA-20160104 - pathname: A/AB/ABH/Mozilla-CA-20160104.tar.gz + Mozilla-CA-20180117 + pathname: A/AB/ABH/Mozilla-CA-20180117.tar.gz provides: - Mozilla::CA 20160104 + Mozilla::CA 20180117 requirements: ExtUtils::MakeMaker 0 Test 0 perl 5.006 - Net-HTTP-6.16 - pathname: O/OA/OALDERS/Net-HTTP-6.16.tar.gz + Net-DNS-1.18 + pathname: N/NL/NLNETLABS/Net-DNS-1.18.tar.gz + provides: + Net::DNS 1.18 + Net::DNS::Domain 1698 + Net::DNS::DomainName 1605 + Net::DNS::DomainName1035 1605 + Net::DNS::DomainName2535 1605 + Net::DNS::Header 1709 + Net::DNS::Mailbox 1605 + Net::DNS::Mailbox1035 1605 + Net::DNS::Mailbox2535 1605 + Net::DNS::Nameserver 1692 + Net::DNS::Packet 1714 + Net::DNS::Parameters 1714 + Net::DNS::Question 1714 + Net::DNS::RR 1714 + Net::DNS::RR::A 1597 + Net::DNS::RR::AAAA 1597 + Net::DNS::RR::AFSDB 1597 + Net::DNS::RR::APL 1597 + Net::DNS::RR::APL::Item 1597 + Net::DNS::RR::CAA 1597 + Net::DNS::RR::CDNSKEY 1586 + Net::DNS::RR::CDS 1586 + Net::DNS::RR::CERT 1597 + Net::DNS::RR::CNAME 1597 + Net::DNS::RR::CSYNC 1597 + Net::DNS::RR::DHCID 1597 + Net::DNS::RR::DLV 1528 + Net::DNS::RR::DNAME 1597 + Net::DNS::RR::DNSKEY 1597 + Net::DNS::RR::DS 1597 + Net::DNS::RR::EUI48 1597 + Net::DNS::RR::EUI64 1597 + Net::DNS::RR::GPOS 1528 + Net::DNS::RR::HINFO 1597 + Net::DNS::RR::HIP 1597 + Net::DNS::RR::IPSECKEY 1597 + Net::DNS::RR::ISDN 1597 + Net::DNS::RR::KEY 1528 + Net::DNS::RR::KX 1597 + Net::DNS::RR::L32 1597 + Net::DNS::RR::L64 1597 + Net::DNS::RR::LOC 1597 + Net::DNS::RR::LP 1597 + Net::DNS::RR::MB 1528 + Net::DNS::RR::MG 1528 + Net::DNS::RR::MINFO 1597 + Net::DNS::RR::MR 1528 + Net::DNS::RR::MX 1597 + Net::DNS::RR::NAPTR 1597 + Net::DNS::RR::NID 1597 + Net::DNS::RR::NS 1597 + Net::DNS::RR::NSEC 1696 + Net::DNS::RR::NSEC3 1694 + Net::DNS::RR::NSEC3PARAM 1597 + Net::DNS::RR::NULL 1528 + Net::DNS::RR::OPENPGPKEY 1597 + Net::DNS::RR::OPT 1605 + Net::DNS::RR::OPT::CHAIN 1605 + Net::DNS::RR::OPT::CLIENT_SUBNET 1605 + Net::DNS::RR::OPT::COOKIE 1605 + Net::DNS::RR::OPT::DAU 1605 + Net::DNS::RR::OPT::DHU 1605 + Net::DNS::RR::OPT::EXPIRE 1605 + Net::DNS::RR::OPT::KEY_TAG 1605 + Net::DNS::RR::OPT::N3U 1605 + Net::DNS::RR::OPT::PADDING 1605 + Net::DNS::RR::OPT::TCP_KEEPALIVE 1605 + Net::DNS::RR::PTR 1597 + Net::DNS::RR::PX 1597 + Net::DNS::RR::RP 1597 + Net::DNS::RR::RRSIG 1709 + Net::DNS::RR::RT 1597 + Net::DNS::RR::SIG 1709 + Net::DNS::RR::SMIMEA 1597 + Net::DNS::RR::SOA 1597 + Net::DNS::RR::SPF 1593 + Net::DNS::RR::SRV 1597 + Net::DNS::RR::SSHFP 1597 + Net::DNS::RR::TKEY 1528 + Net::DNS::RR::TLSA 1597 + Net::DNS::RR::TSIG 1597 + Net::DNS::RR::TXT 1597 + Net::DNS::RR::URI 1597 + Net::DNS::RR::X25 1597 + Net::DNS::Resolver 1714 + Net::DNS::Resolver::Base 1709 + Net::DNS::Resolver::MSWin32 1568 + Net::DNS::Resolver::Recurse 1709 + Net::DNS::Resolver::UNIX 1573 + Net::DNS::Resolver::android 1568 + Net::DNS::Resolver::cygwin 1568 + Net::DNS::Resolver::os2 1568 + Net::DNS::Resolver::os390 1579 + Net::DNS::Text 1698 + Net::DNS::Update 1714 + Net::DNS::ZoneFile 1709 + Net::DNS::ZoneFile::Generator 1709 + Net::DNS::ZoneFile::Text 1709 + requirements: + Digest::HMAC 1.03 + Digest::MD5 2.13 + Digest::SHA 5.23 + ExtUtils::MakeMaker 0 + File::Spec 0.86 + IO::File 1.08 + IO::Select 1.14 + IO::Socket::IP 0.38 + MIME::Base64 2.11 + PerlIO 1.05 + Scalar::Util 1.25 + Test::More 0.52 + Time::Local 1.19 + perl 5.006 + Net-HTTP-6.18 + pathname: O/OA/OALDERS/Net-HTTP-6.18.tar.gz provides: - Net::HTTP 6.16 - Net::HTTP::Methods 6.16 - Net::HTTP::NB 6.16 - Net::HTTPS 6.16 + Net::HTTP 6.18 + Net::HTTP::Methods 6.18 + Net::HTTP::NB 6.18 + Net::HTTPS 6.18 requirements: Carp 0 Compress::Raw::Zlib 0 @@ -956,10 +1234,10 @@ DISTRIBUTIONS strict 0 vars 0 warnings 0 - Net-SSLeay-1.81 - pathname: M/MI/MIKEM/Net-SSLeay-1.81.tar.gz + Net-SSLeay-1.85 + pathname: M/MI/MIKEM/Net-SSLeay-1.85.tar.gz provides: - Net::SSLeay 1.81 + Net::SSLeay 1.85 Net::SSLeay::Handle 0.61 requirements: ExtUtils::MakeMaker 6.36 @@ -975,29 +1253,12 @@ DISTRIBUTIONS ExtUtils::MakeMaker 0 POSIX 0 Test::More 0 - ORLite-1.98 - pathname: A/AD/ADAMK/ORLite-1.98.tar.gz - provides: - ORLite 1.98 - requirements: - DBD::SQLite 1.27 - DBI 1.607 - ExtUtils::MakeMaker 6.59 - File::Path 2.08 - File::Remove 1.40 - File::Spec 0.80 - File::Temp 0.20 - Params::Util 1.00 - Test::More 0.47 - Test::Script 1.06 - perl 5.006 - Params-Classify-0.013 - pathname: Z/ZE/ZEFRAM/Params-Classify-0.013.tar.gz + Params-Classify-0.015 + pathname: Z/ZE/ZEFRAM/Params-Classify-0.015.tar.gz provides: - Params::Classify 0.013 + Params::Classify 0.015 requirements: Exporter 0 - ExtUtils::ParseXS 2.2006 Module::Build 0 Scalar::Util 1.01 Test::More 0 @@ -1005,38 +1266,18 @@ DISTRIBUTIONS perl 5.006001 strict 0 warnings 0 - Params-Util-1.07 - pathname: A/AD/ADAMK/Params-Util-1.07.tar.gz - provides: - Params::Util 1.07 - requirements: - ExtUtils::CBuilder 0.27 - ExtUtils::MakeMaker 6.52 - File::Spec 0.80 - Scalar::Util 1.18 - Test::More 0.42 - perl 5.00503 - Probe-Perl-0.03 - pathname: K/KW/KWILLIAMS/Probe-Perl-0.03.tar.gz - provides: - Probe::Perl 0.03 - requirements: - Config 0 - ExtUtils::MakeMaker 6.30 - File::Spec 0 - strict 0 - Role-Tiny-2.000005 - pathname: H/HA/HAARG/Role-Tiny-2.000005.tar.gz + Role-Tiny-2.000006 + pathname: H/HA/HAARG/Role-Tiny-2.000006.tar.gz provides: - Role::Tiny 2.000005 - Role::Tiny::With 2.000005 + Role::Tiny 2.000006 + Role::Tiny::With 2.000006 requirements: Exporter 5.57 perl 5.006 - SQL-Abstract-1.84 - pathname: I/IL/ILMARI/SQL-Abstract-1.84.tar.gz + SQL-Abstract-1.86 + pathname: I/IL/ILMARI/SQL-Abstract-1.86.tar.gz provides: - SQL::Abstract 1.84 + SQL::Abstract 1.86 SQL::Abstract::Test undef SQL::Abstract::Tree undef requirements: @@ -1049,17 +1290,18 @@ DISTRIBUTIONS Scalar::Util 0 Sub::Quote 2.000001 Text::Balanced 2.00 + perl 5.006 Sub-Exporter-Progressive-0.001013 pathname: F/FR/FREW/Sub-Exporter-Progressive-0.001013.tar.gz provides: Sub::Exporter::Progressive 0.001013 requirements: ExtUtils::MakeMaker 0 - Sub-Quote-2.004000 - pathname: H/HA/HAARG/Sub-Quote-2.004000.tar.gz + Sub-Quote-2.005001 + pathname: H/HA/HAARG/Sub-Quote-2.005001.tar.gz provides: - Sub::Defer 2.004000 - Sub::Quote 2.004000 + Sub::Defer 2.005001 + Sub::Quote 2.005001 requirements: ExtUtils::MakeMaker 0 Scalar::Util 0 @@ -1097,24 +1339,10 @@ DISTRIBUTIONS Try::Tiny 0.07 strict 0 warnings 0 - Test-Script-1.20 - pathname: P/PL/PLICEASE/Test-Script-1.20.tar.gz - provides: - Test::Script 1.20 - requirements: - Capture::Tiny 0 - ExtUtils::MakeMaker 0 - File::Spec 0.80 - IO::Handle 0 - Probe::Perl 0.01 - Test::Builder 0.32 - Test::More 0.96 - perl 5.008001 - Test-Warn-0.32 - pathname: B/BI/BIGJ/Test-Warn-0.32.tar.gz + Test-Warn-0.36 + pathname: B/BI/BIGJ/Test-Warn-0.36.tar.gz provides: - Test::Warn 0.32 - Test::Warn::Categorization 0.32 + Test::Warn 0.36 requirements: Carp 1.22 ExtUtils::MakeMaker 0 @@ -1172,10 +1400,10 @@ DISTRIBUTIONS Time::Zone 2.24 requirements: ExtUtils::MakeMaker 0 - Try-Tiny-0.28 - pathname: E/ET/ETHER/Try-Tiny-0.28.tar.gz + Try-Tiny-0.30 + pathname: E/ET/ETHER/Try-Tiny-0.30.tar.gz provides: - Try::Tiny 0.28 + Try::Tiny 0.30 requirements: Carp 0 Exporter 5.57 @@ -1184,70 +1412,129 @@ DISTRIBUTIONS perl 5.006 strict 0 warnings 0 - URI-1.71 - pathname: E/ET/ETHER/URI-1.71.tar.gz + URI-1.74 + pathname: E/ET/ETHER/URI-1.74.tar.gz provides: - URI 1.71 + URI 1.74 URI::Escape 3.31 URI::Heuristic 4.20 - URI::IRI 1.71 - URI::QueryParam 1.71 - URI::Split 1.71 + URI::IRI 1.74 + URI::QueryParam 1.74 + URI::Split 1.74 URI::URL 5.04 URI::WithBase 2.20 - URI::_foreign 1.71 - URI::_generic 1.71 - URI::_idna 1.71 - URI::_ldap 1.71 - URI::_login 1.71 - URI::_punycode 1.71 - URI::_query 1.71 - URI::_segment 1.71 - URI::_server 1.71 - URI::_userpass 1.71 - URI::data 1.71 + URI::data 1.74 URI::file 4.21 - URI::file::Base 1.71 - URI::file::FAT 1.71 - URI::file::Mac 1.71 - URI::file::OS2 1.71 - URI::file::QNX 1.71 - URI::file::Unix 1.71 - URI::file::Win32 1.71 - URI::ftp 1.71 - URI::gopher 1.71 - URI::http 1.71 - URI::https 1.71 - URI::ldap 1.71 - URI::ldapi 1.71 - URI::ldaps 1.71 - URI::mailto 1.71 - URI::mms 1.71 - URI::news 1.71 - URI::nntp 1.71 - URI::pop 1.71 - URI::rlogin 1.71 - URI::rsync 1.71 - URI::rtsp 1.71 - URI::rtspu 1.71 - URI::sftp 1.71 - URI::sip 1.71 - URI::sips 1.71 - URI::snews 1.71 - URI::ssh 1.71 - URI::telnet 1.71 - URI::tn3270 1.71 - URI::urn 1.71 - URI::urn::isbn undef - URI::urn::oid 1.71 + URI::file::Base 1.74 + URI::file::FAT 1.74 + URI::file::Mac 1.74 + URI::file::OS2 1.74 + URI::file::QNX 1.74 + URI::file::Unix 1.74 + URI::file::Win32 1.74 + URI::ftp 1.74 + URI::gopher 1.74 + URI::http 1.74 + URI::https 1.74 + URI::ldap 1.74 + URI::ldapi 1.74 + URI::ldaps 1.74 + URI::mailto 1.74 + URI::mms 1.74 + URI::news 1.74 + URI::nntp 1.74 + URI::pop 1.74 + URI::rlogin 1.74 + URI::rsync 1.74 + URI::rtsp 1.74 + URI::rtspu 1.74 + URI::sftp 1.74 + URI::sip 1.74 + URI::sips 1.74 + URI::snews 1.74 + URI::ssh 1.74 + URI::telnet 1.74 + URI::tn3270 1.74 + URI::urn 1.74 + URI::urn::isbn 1.74 + URI::urn::oid 1.74 requirements: + Carp 0 + Cwd 0 + Data::Dumper 0 + Encode 0 Exporter 5.57 ExtUtils::MakeMaker 0 MIME::Base64 2 + Net::Domain 0 Scalar::Util 0 + constant 0 + integer 0 + overload 0 parent 0 perl 5.008001 + strict 0 utf8 0 + warnings 0 + URI-Nested-0.10 + pathname: D/DW/DWHEELER/URI-Nested-0.10.tar.gz + provides: + URI::Nested 0.10 + requirements: + Module::Build 0.30 + Test::More 0.88 + URI 1.40 + perl 5.008001 + URI-db-0.19 + pathname: D/DW/DWHEELER/URI-db-0.19.tar.gz + provides: + URI::cassandra 0.19 + URI::couch 0.19 + URI::couchdb 0.19 + URI::cubrid 0.19 + URI::db 0.19 + URI::db2 0.19 + URI::derby 0.19 + URI::exasol 0.19 + URI::firebird 0.19 + URI::hive 0.19 + URI::impala 0.19 + URI::informix 0.19 + URI::ingres 0.19 + URI::interbase 0.19 + URI::ldapdb 0.19 + URI::maria 0.19 + URI::mariadb 0.19 + URI::max 0.19 + URI::maxdb 0.19 + URI::monet 0.19 + URI::monetdb 0.19 + URI::mongo 0.19 + URI::mongodb 0.19 + URI::mssql 0.19 + URI::mysql 0.19 + URI::oracle 0.19 + URI::pg 0.19 + URI::pgsql 0.19 + URI::pgxc 0.19 + URI::postgres 0.19 + URI::postgresql 0.19 + URI::postgresxc 0.19 + URI::redshift 0.19 + URI::snowflake 0.19 + URI::sqlite 0.19 + URI::sqlite3 0.19 + URI::sqlserver 0.19 + URI::sybase 0.19 + URI::teradata 0.19 + URI::unify 0.19 + URI::vertica 0.19 + requirements: + Module::Build 0.30 + Test::More 0.88 + URI 1.40 + URI::Nested 0.10 + perl 5.008001 WWW-RobotRules-6.02 pathname: G/GA/GAAS/WWW-RobotRules-6.02.tar.gz provides: @@ -1260,53 +1547,55 @@ DISTRIBUTIONS Fcntl 0 URI 1.10 perl 5.008001 - XML-SAX-Base-1.09 - pathname: G/GR/GRANTM/XML-SAX-Base-1.09.tar.gz + YAML-Tiny-1.73 + pathname: E/ET/ETHER/YAML-Tiny-1.73.tar.gz provides: - XML::SAX::Base 1.09 - XML::SAX::Base::NoHandler 1.09 - XML::SAX::Exception 1.09 + YAML::Tiny 1.73 requirements: + B 0 + Carp 0 + Exporter 0 ExtUtils::MakeMaker 0 - perl 5.008 + Fcntl 0 + Scalar::Util 0 + perl 5.008001 + strict 0 + warnings 0 common-sense-3.74 pathname: M/ML/MLEHMANN/common-sense-3.74.tar.gz provides: common::sense 3.74 requirements: ExtUtils::MakeMaker 0 - libwww-perl-6.26 - pathname: O/OA/OALDERS/libwww-perl-6.26.tar.gz - provides: - LWP 6.26 - LWP::Authen::Basic 6.26 - LWP::Authen::Digest 6.26 - LWP::Authen::Ntlm 6.26 - LWP::ConnCache 6.26 - LWP::Debug 6.26 - LWP::Debug::TraceHTTP 6.26 - LWP::Debug::TraceHTTP::Socket 6.26 - LWP::DebugFile 6.26 - LWP::MemberMixin 6.26 - LWP::Protocol 6.26 - LWP::Protocol::MyFTP 6.26 - LWP::Protocol::cpan 6.26 - LWP::Protocol::data 6.26 - LWP::Protocol::file 6.26 - LWP::Protocol::ftp 6.26 - LWP::Protocol::gopher 6.26 - LWP::Protocol::http 6.26 - LWP::Protocol::http::Socket 6.26 - LWP::Protocol::http::SocketMethods 6.26 - LWP::Protocol::loopback 6.26 - LWP::Protocol::mailto 6.26 - LWP::Protocol::nntp 6.26 - LWP::Protocol::nogo 6.26 - LWP::RobotUA 6.26 - LWP::Simple 6.26 - LWP::UserAgent 6.26 + libwww-perl-6.36 + pathname: E/ET/ETHER/libwww-perl-6.36.tar.gz + provides: + LWP 6.36 + LWP::Authen::Basic 6.36 + LWP::Authen::Digest 6.36 + LWP::Authen::Ntlm 6.36 + LWP::ConnCache 6.36 + LWP::Debug 6.36 + LWP::Debug::TraceHTTP 6.36 + LWP::DebugFile 6.36 + LWP::MemberMixin 6.36 + LWP::Protocol 6.36 + LWP::Protocol::cpan 6.36 + LWP::Protocol::data 6.36 + LWP::Protocol::file 6.36 + LWP::Protocol::ftp 6.36 + LWP::Protocol::gopher 6.36 + LWP::Protocol::http 6.36 + LWP::Protocol::loopback 6.36 + LWP::Protocol::mailto 6.36 + LWP::Protocol::nntp 6.36 + LWP::Protocol::nogo 6.36 + LWP::RobotUA 6.36 + LWP::Simple 6.36 + LWP::UserAgent 6.36 libwww::perl undef requirements: + CPAN::Meta::Requirements 2.120620 Digest::MD5 0 Encode 2.12 Encode::Locale 0 @@ -1323,11 +1612,12 @@ DISTRIBUTIONS HTTP::Request 6 HTTP::Request::Common 6 HTTP::Response 6 - HTTP::Status 6 + HTTP::Status 6.18 IO::Select 0 IO::Socket 0 LWP::MediaTypes 6 MIME::Base64 2.1 + Module::Metadata 0 Net::FTP 2.58 Net::HTTP 6.07 Scalar::Util 0 @@ -1419,5 +1709,4 @@ DISTRIBUTIONS Text::Soundex 0 Time::Local 0 URI::ldap 1.1 - XML::SAX::Base 0 perl 5.008001 diff --git a/lib/Lufi.pm b/lib/Lufi.pm index c046529..bb7103e 100644 --- a/lib/Lufi.pm +++ b/lib/Lufi.pm @@ -31,6 +31,7 @@ sub startup { session_duration => 3600, allow_pwd_on_files => 0, dbtype => 'sqlite', + db_path => 'lufi.db', } }); diff --git a/lib/Lufi/DB/File.pm b/lib/Lufi/DB/File.pm index d323b9e..6ffc001 100644 --- a/lib/Lufi/DB/File.pm +++ b/lib/Lufi/DB/File.pm @@ -1,7 +1,9 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lufi::DB::File; use Mojo::Base -base; -use Mojo::Collection; +use Mojo::File; +use Mojo::Collection 'c'; +use Lufi::DB::Slice; has 'short'; has 'deleted' => 0; @@ -23,6 +25,7 @@ has 'slices' => sub { return Mojo::Collection->new(); }; has 'passwd'; +has 'record' => 0; has 'app'; =head1 NAME @@ -160,6 +163,21 @@ sub delete { =back +=cut + +sub write { + my $c = shift; + + if ($c->record) { + $c->app->dbi->db->query('UPDATE files SET short = ?, deleted = ?, mediatype = ?, filename = ?, filesize = ?, counter = ?, delete_at_first_view = ?, delete_at_day = ?, created_at = ?, created_by = ?, last_access_at = ?, mod_token = ?, nbslices = ?, complete = ?, passwd = ? WHERE short = ?', $c->short, $c->deleted, $c->mediatype, $c->filename, $c->filesize, $c->counter, $c->delete_at_first_view, $c->delete_at_day, $c->created_at, $c->created_by, $c->last_access_at, $c->mod_token, $c->nbslices, $c->complete, $c->passwd, $c->short); + } else { + $c->app->dbi->db->query('INSERT INTO files (short, deleted, mediatype, filename, filesize, counter, delete_at_first_view, delete_at_day, created_at, created_by, last_access_at, mod_token, nbslices, complete, passwd) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $c->short, $c->deleted, $c->mediatype, $c->filename, $c->filesize, $c->counter, $c->delete_at_first_view, $c->delete_at_day, $c->created_at, $c->created_by, $c->last_access_at, $c->mod_token, $c->nbslices, $c->complete, $c->passwd); + $c->record(1); + } + + return $c; +} + =head2 count_empty =over 1 @@ -174,6 +192,14 @@ sub delete { =back +=cut + +sub count_empty { + my $c = shift; + + return $c->app->dbi->db->query('SELECT count(short) AS count FROM files WHERE created_at IS NULL')->hashes->first->{count}; +} + =head2 already_exists =over 1 @@ -188,6 +214,15 @@ sub delete { =back +=cut + +sub already_exists { + my $c = shift; + my $short = shift; + + return $c->app->dbi->db->query('SELECT count(short) AS count FROM files WHERE short = ?', $short)->hashes->first->{count}; +} + =head2 get_empty =over 1 @@ -202,6 +237,16 @@ sub delete { =back +=cut + +sub get_empty { + my $c = shift; + + my $r = $c->app->dbi->db->query('SELECT * FROM files WHERE created_at IS NULL')->hashes->shuffle->first; + + return $c->_slurp($r)->created_at(time)->write; +} + =head2 get_stats =over 1 @@ -216,6 +261,18 @@ sub delete { =back +=cut + +sub get_stats { + my $c = shift; + + my $files = $c->app->dbi->db->query('SELECT count(short) AS count FROM files WHERE created_at IS NOT null AND deleted = ?', 0)->hashes->first->{count}; + my $deleted = $c->app->dbi->db->query('SELECT count(short) AS count FROM files WHERE created_at IS NOT null AND deleted = ?', 1)->hashes->first->{count}; + my $empty = $c->app->dbi->db->query('SELECT count(short) AS count FROM files WHERE created_at IS null')->hashes->first->{count}; + + return { files => $files, deleted => $deleted, empty => $empty }; +} + =head2 from_short =over 1 @@ -230,6 +287,21 @@ sub delete { =back +=cut + +sub from_short { + my $c = shift; + my $short = shift; + + my $r = $c->app->dbi->db->query('SELECT * FROM files WHERE short = ?', $short)->hashes; + + if ($r->size) { + return $c->_slurp($r->first)->record(1); + } else { + return undef; + } +} + =head2 get_oldest_undeleted_files =over 1 @@ -244,6 +316,26 @@ sub delete { =back +=cut + +sub get_oldest_undeleted_files { + my $c = shift; + my $num = shift; + + my @files; + my $records = $c->app->dbi->db->query('SELECT * FROM files WHERE deleted = ? ORDER BY created_at ASC LIMIT ?', 0, $num)->hashes; + $records->each( + sub { + my ($e, $num) = @_; + my $i = Lufi::DB::File->new(app => $c->app); + + push @files, $i->_slurp($e); + } + ); + + return c(@files); +} + =head2 get_expired =over 1 @@ -258,6 +350,27 @@ sub delete { =back +=cut + +sub get_expired { + my $c = shift; + my $time = shift; + + my @files; + ## Select only files expired since two days, to be sure that nobody is still downloading it + my $records = $c->app->dbi->db->query('SELECT * FROM files WHERE deleted = ? AND ((delete_at_day + 2) * 86400) < (? - created_at) AND delete_at_day != 0', 0, $time)->hashes; + $records->each( + sub { + my ($e, $num) = @_; + my $i = Lufi::DB::File->new(app => $c->app); + + push @files, $i->_slurp($e); + } + ); + + return c(@files); +} + =head2 get_no_longer_viewed =over 1 @@ -272,6 +385,26 @@ sub delete { =back +=cut + +sub get_no_longer_viewed { + my $c = shift; + my $time = shift; + + my @files; + my $records = $c->app->dbi->db->query('SELECT * FROM files WHERE deleted = ? AND last_access_at < ?', 0, $time)->hashes; + $records->each( + sub { + my ($e, $num) = @_; + my $i = Lufi::DB::File->new(app => $c->app); + + push @files, $i->_slurp($e); + } + ); + + return c(@files); +} + =head2 delete_creator_before =over 1 @@ -288,4 +421,67 @@ sub delete { =cut +sub delete_creator_before { + my $c = shift; + my $separation = shift; + + $c->app->dbi->db->query('UPDATE files SET created_by = NULL WHERE created_by IS NOT NULL AND created_at < ?', $separation); +} + +=head2 _slurp + +=over 1 + +=item B : C<$c-E_slurp> + +=item B : none + +=item B : put a database record's columns into the Lufi::DB::File object's attributes + +=item B : the Lufi::DB::File object + +=back + +=cut + +sub _slurp { + my $c = shift; + my $r = shift; + + my $file; + if (defined $r) { + $file = $r; + } else { + my $files = $c->app->dbi->db->query('SELECT * FROM files WHERE short = ?', $c->short)->hashes; + + if ($files->size) { + $file = $files->first; + } + } + + if ($file) { + $c->short($file->{short}); + $c->deleted($file->{deleted}); + $c->mediatype($file->{mediatype}); + $c->filename($file->{filename}); + $c->filesize($file->{filesize}); + $c->counter($file->{counter}); + $c->delete_at_first_view($file->{delete_at_first_view}); + $c->delete_at_day($file->{delete_at_day}); + $c->created_at($file->{created_at}); + $c->created_by($file->{created_by}); + $c->last_access_at($file->{last_access_at}); + $c->mod_token($file->{mod_token}); + $c->nbslices($file->{nbslices}); + $c->complete($file->{complete}); + $c->passwd($file->{passwd}); + + $c->record(1) unless $c->record; + } + + $c->slices(Lufi::DB::Slice->new(app => $c->app)->get_slices_of_file($c->short)); + + return $c; +} + 1; diff --git a/lib/Lufi/DB/File/Pg.pm b/lib/Lufi/DB/File/Pg.pm index 62967f7..925c9e2 100644 --- a/lib/Lufi/DB/File/Pg.pm +++ b/lib/Lufi/DB/File/Pg.pm @@ -1,11 +1,6 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lufi::DB::File::Pg; use Mojo::Base 'Lufi::DB::File'; -use Mojo::File; -use Mojo::Collection 'c'; -use Lufi::DB::Slice; - -has 'record' => 0; sub new { my $c = shift; @@ -15,163 +10,4 @@ sub new { return $c; } -sub write { - my $c = shift; - - if ($c->record) { - $c->app->pg->db->query('UPDATE files SET short = ?, deleted = ?, mediatype = ?, filename = ?, filesize = ?, counter = ?, delete_at_first_view = ?, delete_at_day = ?, created_at = ?, created_by = ?, last_access_at = ?, mod_token = ?, nbslices = ?, complete = ?, passwd = ? WHERE short = ?', $c->short, $c->deleted, $c->mediatype, $c->filename, $c->filesize, $c->counter, $c->delete_at_first_view, $c->delete_at_day, $c->created_at, $c->created_by, $c->last_access_at, $c->mod_token, $c->nbslices, $c->complete, $c->passwd, $c->short); - } else { - $c->app->pg->db->query('INSERT INTO files (short, deleted, mediatype, filename, filesize, counter, delete_at_first_view, delete_at_day, created_at, created_by, last_access_at, mod_token, nbslices, complete, passwd) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $c->short, $c->deleted, $c->mediatype, $c->filename, $c->filesize, $c->counter, $c->delete_at_first_view, $c->delete_at_day, $c->created_at, $c->created_by, $c->last_access_at, $c->mod_token, $c->nbslices, $c->complete, $c->passwd); - $c->record(1); - } - - return $c; -} - -sub count_empty { - my $c = shift; - - return $c->app->pg->db->query('SELECT count(short) FROM files WHERE created_at IS NULL')->hashes->first->{count}; -} - -sub already_exists { - my $c = shift; - my $short = shift; - - return $c->app->pg->db->query('SELECT count(short) FROM files WHERE short = ?', $short)->hashes->first->{count}; -} - -sub get_empty { - my $c = shift; - - my $r = $c->app->pg->db->query('SELECT * FROM files WHERE created_at IS NULL')->hashes->shuffle->first; - - return $c->_slurp($r)->created_at(time)->write; -} - -sub get_stats { - my $c = shift; - - my $files = $c->app->pg->db->query('SELECT count(short) FROM files WHERE created_at IS NOT null AND deleted = false')->hashes->first->{count}; - my $deleted = $c->app->pg->db->query('SELECT count(short) FROM files WHERE created_at IS NOT null AND deleted = true')->hashes->first->{count}; - my $empty = $c->app->pg->db->query('SELECT count(short) FROM files WHERE created_at IS null')->hashes->first->{count}; - - return { files => $files, deleted => $deleted, empty => $empty }; -} - -sub from_short { - my $c = shift; - my $short = shift; - - my $r = $c->app->pg->db->query('SELECT * FROM files WHERE short = ?', $short)->hashes; - - if ($r->size) { - return $c->_slurp($r->first)->record(1); - } else { - return undef; - } -} - -sub get_oldest_undeleted_files { - my $c = shift; - my $num = shift; - - my @files; - my $records = $c->app->pg->db->query('SELECT * FROM files WHERE deleted = false ORDER BY created_at ASC LIMIT ?', $num)->hashes; - $records->each( - sub { - my ($e, $num) = @_; - my $i = Lufi::DB::File->new(app => $c->app); - - push @files, $i->_slurp($e); - } - ); - - return c(@files); -} - -sub get_expired { - my $c = shift; - my $time = shift; - - my @files; - ## Select only files expired since two days, to be sure that nobody is still downloading it - my $records = $c->app->pg->db->query('SELECT * FROM files WHERE deleted = false AND ((delete_at_day + 2) * 86400) < (? - created_at) AND delete_at_day != 0', $time)->hashes; - $records->each( - sub { - my ($e, $num) = @_; - my $i = Lufi::DB::File->new(app => $c->app); - - push @files, $i->_slurp($e); - } - ); - - return c(@files); -} - -sub get_no_longer_viewed { - my $c = shift; - my $time = shift; - - my @files; - my $records = $c->app->pg->db->query('SELECT * FROM files WHERE deleted = false AND last_access_at < ?', $time)->hashes; - $records->each( - sub { - my ($e, $num) = @_; - my $i = Lufi::DB::File->new(app => $c->app); - - push @files, $i->_slurp($e); - } - ); - - return c(@files); -} - -sub delete_creator_before { - my $c = shift; - my $separation = shift; - - $c->app->pg->db->query('UPDATE files SET created_by = NULL WHERE created_by IS NOT NULL AND created_at < ?', $separation); -} - -sub _slurp { - my $c = shift; - my $r = shift; - - my $file; - if (defined $r) { - $file = $r; - } else { - my $files = $c->app->pg->db->query('SELECT * FROM files WHERE short = ?', $c->short)->hashes; - - if ($files->size) { - $file = $files->first; - } - } - - if ($file) { - $c->short($file->{short}); - $c->deleted($file->{deleted}); - $c->mediatype($file->{mediatype}); - $c->filename($file->{filename}); - $c->filesize($file->{filesize}); - $c->counter($file->{counter}); - $c->delete_at_first_view($file->{delete_at_first_view}); - $c->delete_at_day($file->{delete_at_day}); - $c->created_at($file->{created_at}); - $c->created_by($file->{created_by}); - $c->last_access_at($file->{last_access_at}); - $c->mod_token($file->{mod_token}); - $c->nbslices($file->{nbslices}); - $c->complete($file->{complete}); - $c->passwd($file->{passwd}); - - $c->record(1) unless $c->record; - } - - $c->slices(Lufi::DB::Slice->new(app => $c->app)->get_slices_of_file($c->short)); - - return $c; -} - 1; diff --git a/lib/Lufi/DB/File/SQLite.pm b/lib/Lufi/DB/File/SQLite.pm index 47eface..4a896a8 100644 --- a/lib/Lufi/DB/File/SQLite.pm +++ b/lib/Lufi/DB/File/SQLite.pm @@ -1,12 +1,7 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lufi::DB::File::SQLite; use Mojo::Base 'Lufi::DB::File'; -use Mojo::File; use Mojo::Collection 'c'; -use Lufi::DB::SQLite; -use Lufi::DB::Slice; - -has 'record'; sub new { my $c = shift; @@ -17,172 +12,4 @@ sub new { return $c; } -sub write { - my $c = shift; - - if (defined $c->record) { - $c->record->update( - short => $c->short, - deleted => $c->deleted, - mediatype => $c->mediatype, - filename => $c->filename, - filesize => $c->filesize, - counter => $c->counter, - delete_at_first_view => $c->delete_at_first_view, - delete_at_day => $c->delete_at_day, - created_at => $c->created_at, - created_by => $c->created_by, - last_access_at => $c->last_access_at, - mod_token => $c->mod_token, - nbslices => $c->nbslices, - complete => $c->complete, - passwd => $c->passwd, - ); - } else { - my $record = Lufi::DB::SQLite::Files->create( - short => $c->short, - deleted => $c->deleted, - mediatype => $c->mediatype, - filename => $c->filename, - filesize => $c->filesize, - counter => $c->counter, - delete_at_first_view => $c->delete_at_first_view, - delete_at_day => $c->delete_at_day, - created_at => $c->created_at, - created_by => $c->created_by, - last_access_at => $c->last_access_at, - mod_token => $c->mod_token, - nbslices => $c->nbslices, - complete => $c->complete, - passwd => $c->passwd, - ); - $c->record($record); - } - - return $c; -} - -sub count_empty { - my $c = shift; - - return Lufi::DB::SQLite::Files->count('WHERE created_at IS NULL'); -} - -sub already_exists { - my $c = shift; - my $short = shift; - - return Lufi::DB::SQLite::Files->count('WHERE short = ?', $short); -} - -sub get_empty { - my $c = shift; - - my @records = Lufi::DB::SQLite::Files->select('WHERE created_at IS NULL LIMIT 1'); - - return $c->record($records[0])->_slurp->created_at(time)->write; -} - -sub get_stats { - my $c = shift; - - my $files = Lufi::DB::SQLite::Files->count('WHERE created_at IS NOT null AND deleted = 0'); - my $deleted = Lufi::DB::SQLite::Files->count('WHERE created_at IS NOT null AND deleted = 1'); - my $empty = Lufi::DB::SQLite::Files->count('WHERE created_at IS null'); - - return { files => $files, deleted => $deleted, empty => $empty }; -} - -sub from_short { - my $c = shift; - my $short = shift; - - my @records = Lufi::DB::SQLite::Files->select('WHERE short = ?', $short); - - if (scalar @records) { - $c->record($records[0]); - $c->_slurp; - - return $c; - } else { - return undef; - } -} - -sub get_oldest_undeleted_files { - my $c = shift; - my $num = shift; - - my @files = Lufi::DB::SQLite::Files->select('WHERE deleted = 0 ORDER BY created_at ASC LIMIT ?', $num); - - return c(map { Lufi::DB::File->new(app => $c->app, record => $_) } @files); -} - -sub get_expired { - my $c = shift; - my $time = shift; - - ## Select only files expired since two days, to be sure that nobody is still downloading it - my @files = Lufi::DB::SQLite::Files->select('WHERE deleted = 0 AND ((delete_at_day + 2) * 86400) < (? - created_at) AND delete_at_day != 0', $time); - - return c(map { Lufi::DB::File->new(app => $c->app, record => $_) } @files); -} - -sub get_no_longer_viewed { - my $c = shift; - my $time = shift; - - my @files = Lufi::DB::SQLite::Files->select('WHERE deleted = 0 AND last_access_at < ?', $time); - - return c(map { Lufi::DB::File->new(app => $c->app, record => $_) } @files); -} - -sub delete_creator_before { - my $c = shift; - my $separation = shift; - - Lufi::DB::SQLite->do( - 'UPDATE files SET created_by = NULL WHERE created_by IS NOT NULL AND created_at < ?', - {}, - $separation - ); -} - -sub _slurp { - my $c = shift; - - my @files; - if ($c->record) { - @files = ($c->record); - } elsif ($c->short) { - @files = Lufi::DB::SQLite::Files->select('WHERE short = ?', $c->short); - } - - if (scalar @files) { - my $file = $files[0]; - - $c->short($file->short); - $c->deleted($file->deleted) if defined $file->deleted; - $c->mediatype($file->mediatype) if defined $file->mediatype; - $c->filename($file->filename) if defined $file->filename; - $c->filesize($file->filesize) if defined $file->filesize; - $c->counter($file->counter) if defined $file->counter; - $c->delete_at_first_view($file->delete_at_first_view) if defined $file->delete_at_first_view; - $c->delete_at_day($file->delete_at_day) if defined $file->delete_at_day; - $c->created_at($file->created_at) if defined $file->created_at; - $c->created_by($file->created_by) if defined $file->created_by; - $c->last_access_at($file->last_access_at) if defined $file->last_access_at; - $c->mod_token($file->mod_token) if defined $file->mod_token; - $c->nbslices($file->nbslices) if defined $file->nbslices; - $c->complete($file->complete) if defined $file->complete; - $c->passwd($file->passwd) if defined $file->passwd; - - $c->record($file) unless $c->record; - } - - $c->slices(Lufi::DB::Slice->new(app => $c->app)->get_slices_of_file($c->short)); - - return $c; -} - 1; diff --git a/lib/Lufi/DB/SQLite.pm b/lib/Lufi/DB/SQLite.pm deleted file mode 100644 index 4553f56..0000000 --- a/lib/Lufi/DB/SQLite.pm +++ /dev/null @@ -1,64 +0,0 @@ -# vim:set sw=4 ts=4 sts=4 ft=perl expandtab: -package Lufi::DB::SQLite; -use Mojolicious; -use Mojo::File; -use FindBin qw($Bin); - -BEGIN { - my $m = Mojolicious->new; - my $cfile = Mojo::File->new($Bin, '..' , 'lufi.conf'); - if (defined $ENV{MOJO_CONFIG}) { - $cfile = Mojo::File->new($ENV{MOJO_CONFIG}); - unless (-e $cfile->to_abs) { - $cfile = Mojo::File->new($Bin, '..', $ENV{MOJO_CONFIG}); - } - } - our $config = $m->plugin('Config' => - { - file => $cfile->to_abs->to_string, - default => { - db_path => 'lufi.db' - } - } - ); -} - -# Create database -use ORLite { - file => $config->{db_path}, - unicode => 1, - create => sub { - my $dbh = shift; - $dbh->do( - 'CREATE TABLE files ( - short TEXT PRIMARY KEY, - deleted INTEGER, - mediatype TEXT, - filename TEXT, - filesize INTEGER, - counter INTEGER, - delete_at_first_view INTEGER, - delete_at_day INTEGER, - created_at INTEGER, - created_by TEXT, - last_access_at INTEGER, - mod_token TEXT, - nbslices INTEGER, - complete INTEGER, - passwd TEXT)' - ); - $dbh->do( - 'CREATE TABLE slices ( - short TEXT, - j INTEGER, - path TEXT, - FOREIGN KEY (short) REFERENCES files(short))' - ); - $dbh->do( - 'CREATE INDEX slices_idx ON slices(short)' - ); - return 1; - } -}; - -1; diff --git a/lib/Lufi/DB/Slice.pm b/lib/Lufi/DB/Slice.pm index b350071..cf3d136 100644 --- a/lib/Lufi/DB/Slice.pm +++ b/lib/Lufi/DB/Slice.pm @@ -1,10 +1,12 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lufi::DB::Slice; use Mojo::Base -base; +use Mojo::Collection 'c'; has 'short'; has 'j'; has 'path'; +has 'record' => 0; has 'app'; =head1 NAME @@ -85,6 +87,21 @@ sub new { =back +=cut + +sub write { + my $c = shift; + + if ($c->record) { + $c->app->dbi->db->query('UPDATE slices SET short = ?, j = ?, path = ? WHERE short = ? AND j = ?', $c->short, $c->j, $c->path, $c->short, $c->j); + } else { + $c->app->dbi->db->query('INSERT INTO slices (short, j, path) VALUES (?, ?, ?)', $c->short, $c->j, $c->path); + $c->record(1); + } + + return $c; +} + =head2 get_slices_of_file =over 1 @@ -101,4 +118,64 @@ sub new { =cut +sub get_slices_of_file { + my $c = shift; + my $short = shift; + + my @slices; + my $records = $c->app->dbi->db->query('SELECT * FROM slices WHERE short = ? ORDER BY j ASC', $short)->hashes; + $records->each( + sub { + my ($e, $num) = @_; + my $i = Lufi::DB::Slice->new(app => $c->app); + + push @slices, $i->_slurp($e); + } + ); + + return c(@slices); +} + +=head2 _slurp + +=over 1 + +=item B : C<$c-E_slurp> + +=item B : none + +=item B : put a database record's columns into the Lufi::DB::Slice object's attributes + +=item B : the Lufi::DB::Slice object + +=back + +=cut + +sub _slurp { + my $c = shift; + my $r = shift; + + my $slice; + if (defined $r) { + $slice = $r; + } else { + my $slices = $c->app->dbi->db->query('SELECT * FROM slices WHERE short = ? AND j = ?', $c->short, $c->j)->hashes; + + if ($slices->size) { + $slice = $slices->first; + } + } + + if ($slice) { + $c->short($slice->{short}); + $c->j($slice->{j}); + $c->path($slice->{path}); + + $c->record(1); + } + + return $c; +} + 1; diff --git a/lib/Lufi/DB/Slice/Pg.pm b/lib/Lufi/DB/Slice/Pg.pm index 5744b49..defdf27 100644 --- a/lib/Lufi/DB/Slice/Pg.pm +++ b/lib/Lufi/DB/Slice/Pg.pm @@ -1,9 +1,6 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lufi::DB::Slice::Pg; use Mojo::Base 'Lufi::DB::Slice'; -use Mojo::Collection 'c'; - -has 'record' => 0; sub new { my $c = shift; @@ -13,61 +10,4 @@ sub new { return $c; } -sub write { - my $c = shift; - - if ($c->record) { - $c->app->pg->db->query('UPDATE slices SET short = ?, j = ?, path = ? WHERE short = ? AND j = ?', $c->short, $c->j, $c->path, $c->short, $c->j); - } else { - $c->app->pg->db->query('INSERT INTO slices (short, j, path) VALUES (?, ?, ?)', $c->short, $c->j, $c->path); - $c->record(1); - } - - return $c; -} - -sub get_slices_of_file { - my $c = shift; - my $short = shift; - - my @slices; - my $records = $c->app->pg->db->query('SELECT * FROM slices WHERE short = ? ORDER BY j ASC', $short)->hashes; - $records->each( - sub { - my ($e, $num) = @_; - my $i = Lufi::DB::Slice->new(app => $c->app); - - push @slices, $i->_slurp($e); - } - ); - - return c(@slices); -} - -sub _slurp { - my $c = shift; - my $r = shift; - - my $slice; - if (defined $r) { - $slice = $r; - } else { - my $slices = $c->app->pg->db->query('SELECT * FROM slices WHERE short = ? AND j = ?', $c->short, $c->j)->hashes; - - if ($slices->size) { - $slice = $slices->first; - } - } - - if ($slice) { - $c->short($slice->{short}); - $c->j($slice->{j}); - $c->path($slice->{path}); - - $c->record(1); - } - - return $c; -} - 1; diff --git a/lib/Lufi/DB/Slice/SQLite.pm b/lib/Lufi/DB/Slice/SQLite.pm index 5927f9b..d65ed26 100644 --- a/lib/Lufi/DB/Slice/SQLite.pm +++ b/lib/Lufi/DB/Slice/SQLite.pm @@ -1,10 +1,6 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lufi::DB::Slice::SQLite; use Mojo::Base 'Lufi::DB::Slice'; -use Lufi::DB::SQLite; -use Mojo::Collection 'c'; - -has 'record'; sub new { my $c = shift; @@ -16,44 +12,4 @@ sub new { return $c; } -sub write { - my $c = shift; - - if (defined $c->record) { - $c->record->update( - short => $c->short, - j => $c->j, - path => $c->path - ); - } else { - my $record = Lufi::DB::SQLite::Slices->create( - short => $c->short, - j => $c->j, - path => $c->path - ); - $c->record($record); - } - - return $c; -} - -sub get_slices_of_file { - my $c = shift; - my $short = shift; - - my @slices = Lufi::DB::SQLite::Slices->select('WHERE short = ? ORDER BY j ASC', $short); - - return c(map { Lufi::DB::Slice->new(app => $c->app, record => $_) } @slices); -} - -sub _slurp { - my $c = shift; - - $c->short($c->record->short) if defined $c->record->short; - $c->j($c->record->j) if defined $c->record->j; - $c->path($c->record->path) if defined $c->record->path; - - return $c; -} - 1; diff --git a/lib/Lufi/Plugin/Helpers.pm b/lib/Lufi/Plugin/Helpers.pm index 518f3fe..55ebcdf 100644 --- a/lib/Lufi/Plugin/Helpers.pm +++ b/lib/Lufi/Plugin/Helpers.pm @@ -7,49 +7,66 @@ use Data::Entropy qw(entropy_source); sub register { my ($self, $app) = @_; - $app->plugin('PgURLHelper'); + # PgURL helper + if ($app->config('dbtype') eq 'postgresql' || $app->config('dbtype') eq 'mysql') { + $app->plugin('PgURLHelper'); + } + if ($app->config('dbtype') eq 'postgresql') { - use Mojo::Pg; - $app->helper(pg => \&_pg); + require Mojo::Pg; + $app->helper(dbi => \&_pg); # Database migration - my $migrations = Mojo::Pg::Migrations->new(pg => $app->pg); + my $migrations = Mojo::Pg::Migrations->new(pg => $app->dbi); if ($app->mode eq 'development' && $ENV{LUFI_DEV}) { - $migrations->from_file('utilities/migrations_pg.sql')->migrate(0)->migrate(1); + $migrations->from_file('utilities/migrations/pg.sql')->migrate(0)->migrate(1); } else { - $migrations->from_file('utilities/migrations_pg.sql')->migrate(1); + $migrations->from_file('utilities/migrations/pg.sql')->migrate(1); } } elsif ($app->config('dbtype') eq 'sqlite') { - # SQLite database migration if needed - use Lufi::DB::SQLite; - my $columns = Lufi::DB::SQLite::Files->table_info; - my $pwd_col = 0; - foreach my $col (@{$columns}) { - $pwd_col = 1 if $col->{name} eq 'passwd'; + require Mojo::SQLite; + $app->helper(dbi => \&_sqlite); + + # Database migration + # Have to create $sql before using its migrations attribute, otherwise, it won't work + my $sql = $app->dbi; + my $migrations = $sql->migrations; + if ($app->mode eq 'development' && $ENV{LUFI_DEV}) { + $migrations->from_file('utilities/migrations/sqlite.sql')->migrate(0)->migrate(1); + } else { + $migrations->from_file('utilities/migrations/sqlite.sql')->migrate(1); } - unless ($pwd_col) { - Lufi::DB::SQLite->do('ALTER TABLE files ADD COLUMN passwd TEXT;'); + my $columns = $app->dbi->db->query('PRAGMA table_info(files)')->hashes; + if ($columns->size == 14) { # Missing passwd column + $app->dbi->db->query('ALTER TABLE files ADD COLUMN passwd TEXT'); } } - $app->helper(provisioning => \&_provisioning); - $app->helper(get_empty => \&_get_empty); - $app->helper(shortener => \&_shortener); - $app->helper(ip => \&_ip); + $app->helper(provisioning => \&_provisioning); + $app->helper(get_empty => \&_get_empty); + $app->helper(shortener => \&_shortener); + $app->helper(ip => \&_ip); $app->helper(default_delay => \&_default_delay); - $app->helper(max_delay => \&_max_delay); - $app->helper(is_selected => \&_is_selected); - $app->helper(stop_upload => \&_stop_upload); + $app->helper(max_delay => \&_max_delay); + $app->helper(is_selected => \&_is_selected); + $app->helper(stop_upload => \&_stop_upload); } sub _pg { - my $c = shift; + my $c = shift; state $pg = Mojo::Pg->new($c->app->pg_url($c->app->config('pgdb'))); return $pg; } +sub _sqlite { + my $c = shift; + + state $sqlite = Mojo::SQLite->new('sqlite:'.$c->app->config('db_path')); + return $sqlite; +} + sub _provisioning { my $c = shift; diff --git a/lib/Mounter.pm b/lib/Mounter.pm index dce85a0..7b172ec 100644 --- a/lib/Mounter.pm +++ b/lib/Mounter.pm @@ -23,6 +23,24 @@ sub startup { prefix => '/', theme => 'default', dbtype => 'sqlite', + prefix => '/', + provisioning => 100, + provis_step => 5, + length => 10, + token_length => 32, + secrets => ['hfudsifdsih'], + default_delay => 0, + max_delay => 0, + mail => { + how => 'sendmail' + }, + mail_sender => 'no-reply@lufi.io', + theme => 'default', + upload_dir => 'files', + session_duration => 3600, + allow_pwd_on_files => 0, + dbtype => 'sqlite', + db_path => 'lufi.db', } } ); diff --git a/lufi.conf.template b/lufi.conf.template index 64df2be..86a779a 100644 --- a/lufi.conf.template +++ b/lufi.conf.template @@ -7,7 +7,7 @@ hypnotoad => { # array of IP addresses and ports you want to listen to listen => ['http://127.0.0.1:8081'], - # if you use Lufi behind a reverse proxy like Nginx, you want ro set proxy to 1 + # if you use Lufi behind a reverse proxy like Nginx, you want to set proxy to 1 # if you use Lufi directly, let it commented #proxy => 1, diff --git a/themes/default/lib/Lufi/I18N/ca.po b/themes/default/lib/Lufi/I18N/ca.po index 4e45272..a90ace2 100644 --- a/themes/default/lib/Lufi/I18N/ca.po +++ b/themes/default/lib/Lufi/I18N/ca.po @@ -304,7 +304,7 @@ msgstr "Si us plau contacteu amb l'administrador: %1" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "Si us plau, espereu mentre obtenim el fitxer. Abans que el tingueu disponible primer cal descarregar i desxifrar tots els trossos." -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "" @@ -345,7 +345,7 @@ msgstr "Compartiu fitxers amb total privacitat a %1" msgid "Signin" msgstr "Autenticació" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "" diff --git a/themes/default/lib/Lufi/I18N/en.po b/themes/default/lib/Lufi/I18N/en.po index 92915a0..faaaf12 100644 --- a/themes/default/lib/Lufi/I18N/en.po +++ b/themes/default/lib/Lufi/I18N/en.po @@ -300,7 +300,7 @@ msgstr "" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "" -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "" @@ -341,7 +341,7 @@ msgstr "" msgid "Signin" msgstr "" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "" diff --git a/themes/default/lib/Lufi/I18N/fr.po b/themes/default/lib/Lufi/I18N/fr.po index d2c24d2..63c74db 100644 --- a/themes/default/lib/Lufi/I18N/fr.po +++ b/themes/default/lib/Lufi/I18N/fr.po @@ -302,7 +302,7 @@ msgstr "Veuillez contacter l’administrateur : %1" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "Veuillez patientez pendant la récupération de votre fichier. Nous devons d’abord récupérer et déchiffrer tous les fragments avant que vous puissiez le télécharger." -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "Veuillez vérifier vos identifiants : impossible de vous authentifier." @@ -343,7 +343,7 @@ msgstr "Partagez vos fichiers en toute confidentialité sur %1" msgid "Signin" msgstr "Connexion" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "Désolé, vous n’êtes pas autorisé à utiliser ce service. Contactez votre administrateur si vous pensez qu’il s’agit d’une erreur." diff --git a/themes/default/lib/Lufi/I18N/it.po b/themes/default/lib/Lufi/I18N/it.po index 6030a39..1eec9b8 100644 --- a/themes/default/lib/Lufi/I18N/it.po +++ b/themes/default/lib/Lufi/I18N/it.po @@ -302,7 +302,7 @@ msgstr "Contattare l'amministratore : %1" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "Attendere mentre otteniamo il vostro file. Dobbiamo prima scaricare e decifrare tutte le parti prima che possiate averlo." -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "" @@ -347,7 +347,7 @@ msgstr "Condividi tutti i file in totale riservatezza su %1" msgid "Signin" msgstr "Autenticazione" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "" diff --git a/themes/default/lib/Lufi/I18N/nl.po b/themes/default/lib/Lufi/I18N/nl.po index d3099da..c00216f 100644 --- a/themes/default/lib/Lufi/I18N/nl.po +++ b/themes/default/lib/Lufi/I18N/nl.po @@ -289,7 +289,7 @@ msgstr "Neem contact op met administrator: %1" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "Een ogenblik geduld, we pakken je bestand er bij. We moeten alle delen downloaden en decrypten voordat je het kan downloaden." -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "" @@ -334,7 +334,7 @@ msgstr "Deel je bestanden met volledige privacy op %1" msgid "Signin" msgstr "Inloggen" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "" diff --git a/themes/default/lib/Lufi/I18N/oc.po b/themes/default/lib/Lufi/I18N/oc.po index aa6867c..18394d7 100644 --- a/themes/default/lib/Lufi/I18N/oc.po +++ b/themes/default/lib/Lufi/I18N/oc.po @@ -302,7 +302,7 @@ msgstr "Mercés de contactar l’administrator : %1" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "Mercés d’esperar pendent la recuperacion de vòstre fichièr. Nos cal d’en primièr recuperar e deschifrar totes los fragaments abans que poscatz o telecargar." -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "Mercés de verificar vòstres identificants : impossible de vos autentificar." @@ -343,7 +343,7 @@ msgstr "Partejatz vòstres fichièrs en tota confidencialitat sus %1" msgid "Signin" msgstr "Connexion" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "O planhèm collèga, sètz pas autorizat a utilizar aqueste servici. Contactatz vòstre administrator sistèma se pensatz que i a un problèma." diff --git a/themes/default/lib/Lufi/I18N/pt.po b/themes/default/lib/Lufi/I18N/pt.po index c87e965..ce69143 100644 --- a/themes/default/lib/Lufi/I18N/pt.po +++ b/themes/default/lib/Lufi/I18N/pt.po @@ -311,7 +311,7 @@ msgstr "Contacte o administrador: %1" msgid "Please wait while we are getting your file. We first need to download and decrypt all parts before you can get it." msgstr "Por favor aguarde durante a recuperação do seu ficheiro. Primeiro devemos recuperar e descodificar todos os fragmentos e depois poderá descarregar o ficheiro." -#: lib/Lufi.pm:199 +#: lib/Lufi.pm:200 msgid "Please, check your credentials: unable to authenticate." msgstr "" @@ -352,7 +352,7 @@ msgstr "Partilhe os seus ficheiros com toda a privacidade em %1" msgid "Signin" msgstr "Conexão" -#: lib/Lufi.pm:202 +#: lib/Lufi.pm:203 msgid "Sorry mate, you are not authorised to use that service. Contact your sysadmin if you think there's a glitch in the matrix." msgstr "" diff --git a/utilities/migrations/pg.sql b/utilities/migrations/pg.sql new file mode 100644 index 0000000..5406a18 --- /dev/null +++ b/utilities/migrations/pg.sql @@ -0,0 +1,28 @@ +-- 1 up +CREATE TABLE IF NOT EXISTS files ( + short text PRIMARY KEY, + deleted boolean default false, + mediatype text, + filename text, + filesize integer, + counter integer default 0, + delete_at_first_view boolean, + delete_at_day integer, + created_at integer, + created_by text, + last_access_at integer, + mod_token text, + nbslices integer, + complete boolean default false, + passwd text +); + +CREATE TABLE IF NOT EXISTS slices ( + short text NOT NULL REFERENCES files(short) ON DELETE CASCADE, + j integer NOT NULL, + path text unique NOT NULL, + constraint slice_short_j UNIQUE (short, j) +); +-- 1 down +DROP TABLE slices; +DROP TABLE files; diff --git a/utilities/migrations/sqlite.sql b/utilities/migrations/sqlite.sql new file mode 100644 index 0000000..90584f1 --- /dev/null +++ b/utilities/migrations/sqlite.sql @@ -0,0 +1,28 @@ +-- 1 up +CREATE TABLE IF NOT EXISTS files ( + short TEXT PRIMARY KEY, + deleted INTEGER, + mediatype TEXT, + filename TEXT, + filesize INTEGER, + counter INTEGER, + delete_at_first_view INTEGER, + delete_at_day INTEGER, + created_at INTEGER, + created_by TEXT, + last_access_at INTEGER, + mod_token TEXT, + nbslices INTEGER, + complete INTEGER +); +CREATE TABLE IF NOT EXISTS slices ( + short TEXT, + j INTEGER, + path TEXT, + FOREIGN KEY (short) REFERENCES files(short) +); +CREATE INDEX IF NOT EXISTS slices_idx ON slices(short); +-- 1 down +DROP INDEX slices_idx ON slices(short); +DROP TABLE slices; +DROP TABLE files; diff --git a/utilities/migrations_pg.sql b/utilities/migrations_pg.sql deleted file mode 100644 index 3ceeef9..0000000 --- a/utilities/migrations_pg.sql +++ /dev/null @@ -1,28 +0,0 @@ --- 1 up -CREATE TABLE IF NOT EXISTS files ( - short text PRIMARY KEY, - deleted boolean default false, - mediatype text, - filename text, - filesize integer, - counter integer default 0, - delete_at_first_view boolean, - delete_at_day integer, - created_at integer, - created_by text, - last_access_at integer, - mod_token text, - nbslices integer, - complete boolean default false, - passwd text -); - -CREATE TABLE IF NOT EXISTS slices ( - short text NOT NULL REFERENCES files(short) ON DELETE CASCADE, - j integer NOT NULL, - path text unique NOT NULL, - constraint slice_short_j UNIQUE (short, j) -); --- 1 down -DROP TABLE slices; -DROP TABLE files;