Support Crystal 0.35.0

pull/1247/head
Omar Roth 4 years ago
parent 338dc3223c
commit d30a972a90
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2

@ -11,13 +11,13 @@ targets:
dependencies: dependencies:
pg: pg:
github: will/crystal-pg github: will/crystal-pg
version: ~> 0.21.0 version: ~> 0.21.1
sqlite3: sqlite3:
github: crystal-lang/crystal-sqlite3 github: crystal-lang/crystal-sqlite3
version: ~> 0.16.0 version: ~> 0.16.0
kemal: kemal:
github: kemalcr/kemal github: kemalcr/kemal
version: ~> 0.26.1 branch: master
pool: pool:
github: ysbaddaden/pool github: ysbaddaden/pool
version: ~> 0.2.3 version: ~> 0.2.3
@ -28,6 +28,6 @@ dependencies:
github: omarroth/lsquic.cr github: omarroth/lsquic.cr
branch: dev branch: dev
crystal: 0.34.0 crystal: 0.35.0
license: AGPLv3 license: AGPLv3

@ -23,7 +23,7 @@ require "pg"
require "sqlite3" require "sqlite3"
require "xml" require "xml"
require "yaml" require "yaml"
require "zip" require "compress/zip"
require "protodec/utils" require "protodec/utils"
require "./invidious/helpers/*" require "./invidious/helpers/*"
require "./invidious/*" require "./invidious/*"
@ -2660,7 +2660,7 @@ post "/data_control" do |env|
PG_DB.exec("UPDATE users SET feed_needs_update = true, subscriptions = $1 WHERE email = $2", user.subscriptions, user.email) PG_DB.exec("UPDATE users SET feed_needs_update = true, subscriptions = $1 WHERE email = $2", user.subscriptions, user.email)
when "import_newpipe" when "import_newpipe"
Zip::Reader.open(IO::Memory.new(body)) do |file| Compress::Zip::Reader.open(IO::Memory.new(body)) do |file|
file.each_entry do |entry| file.each_entry do |entry|
if entry.filename == "newpipe.db" if entry.filename == "newpipe.db"
tempfile = File.tempfile(".db") tempfile = File.tempfile(".db")

@ -74,10 +74,10 @@ class FilteredCompressHandler < Kemal::Handler
if request_headers.includes_word?("Accept-Encoding", "gzip") if request_headers.includes_word?("Accept-Encoding", "gzip")
env.response.headers["Content-Encoding"] = "gzip" env.response.headers["Content-Encoding"] = "gzip"
env.response.output = Gzip::Writer.new(env.response.output, sync_close: true) env.response.output = Compress::Gzip::Writer.new(env.response.output, sync_close: true)
elsif request_headers.includes_word?("Accept-Encoding", "deflate") elsif request_headers.includes_word?("Accept-Encoding", "deflate")
env.response.headers["Content-Encoding"] = "deflate" env.response.headers["Content-Encoding"] = "deflate"
env.response.output = Flate::Writer.new(env.response.output, sync_close: true) env.response.output = Compress::Deflate::Writer.new(env.response.output, sync_close: true)
end end
call_next env call_next env

@ -625,6 +625,7 @@ def extract_shelf_items(nodeset, ucid = nil, author_name = nil)
end end
def check_enum(db, logger, enum_name, struct_type = nil) def check_enum(db, logger, enum_name, struct_type = nil)
return # TODO
if !db.query_one?("SELECT true FROM pg_type WHERE typname = $1", enum_name, as: Bool) if !db.query_one?("SELECT true FROM pg_type WHERE typname = $1", enum_name, as: Bool)
logger.puts("CREATE TYPE #{enum_name}") logger.puts("CREATE TYPE #{enum_name}")
@ -646,18 +647,14 @@ def check_table(db, logger, table_name, struct_type = nil)
end end
end end
if !struct_type return if !struct_type
return
end
struct_array = struct_type.to_type_tuple struct_array = struct_type.to_type_tuple
column_array = get_column_array(db, table_name) column_array = get_column_array(db, table_name)
column_types = File.read("config/sql/#{table_name}.sql").match(/CREATE TABLE public\.#{table_name}\n\((?<types>[\d\D]*?)\);/) column_types = File.read("config/sql/#{table_name}.sql").match(/CREATE TABLE public\.#{table_name}\n\((?<types>[\d\D]*?)\);/)
.try &.["types"].split(",").map { |line| line.strip } .try &.["types"].split(",").map { |line| line.strip }.reject &.starts_with?("CONSTRAINT")
if !column_types return if !column_types
return
end
struct_array.each_with_index do |name, i| struct_array.each_with_index do |name, i|
if name != column_array[i]? if name != column_array[i]?
@ -708,6 +705,15 @@ def check_table(db, logger, table_name, struct_type = nil)
end end
end end
end end
return if column_array.size <= struct_array.size
# column_array.each do |column|
# if !struct_array.includes? column
# logger.puts("ALTER TABLE #{table_name} DROP COLUMN #{column} CASCADE")
# db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column} CASCADE")
# end
# end
end end
class PG::ResultSet class PG::ResultSet
@ -897,15 +903,35 @@ end
def proxy_file(response, env) def proxy_file(response, env)
if response.headers.includes_word?("Content-Encoding", "gzip") if response.headers.includes_word?("Content-Encoding", "gzip")
Gzip::Writer.open(env.response) do |deflate| Compress::Gzip::Writer.open(env.response) do |deflate|
response.pipe(deflate) IO.copy response.body_io, deflate
end end
elsif response.headers.includes_word?("Content-Encoding", "deflate") elsif response.headers.includes_word?("Content-Encoding", "deflate")
Flate::Writer.open(env.response) do |deflate| Compress::Deflate::Writer.open(env.response) do |deflate|
response.pipe(deflate) IO.copy response.body_io, deflate
end end
else else
response.pipe(env.response) IO.copy response.body_io, env.response
end
end
# See https://github.com/kemalcr/kemal/pull/576
class HTTP::Server::Response::Output
def close
return if closed?
unless response.wrote_headers?
response.content_length = @out_count
end
ensure_headers_written
super
if @chunked
@io << "0\r\n\r\n"
@io.flush
end
end end
end end

@ -81,12 +81,12 @@ def send_file(env : HTTP::Server::Context, file_path : String, data : Slice(UInt
condition = config.is_a?(Hash) && config["gzip"]? == true && filesize > minsize && Kemal::Utils.zip_types(file_path) condition = config.is_a?(Hash) && config["gzip"]? == true && filesize > minsize && Kemal::Utils.zip_types(file_path)
if condition && request_headers.includes_word?("Accept-Encoding", "gzip") if condition && request_headers.includes_word?("Accept-Encoding", "gzip")
env.response.headers["Content-Encoding"] = "gzip" env.response.headers["Content-Encoding"] = "gzip"
Gzip::Writer.open(env.response) do |deflate| Compress::Gzip::Writer.open(env.response) do |deflate|
IO.copy(file, deflate) IO.copy(file, deflate)
end end
elsif condition && request_headers.includes_word?("Accept-Encoding", "deflate") elsif condition && request_headers.includes_word?("Accept-Encoding", "deflate")
env.response.headers["Content-Encoding"] = "deflate" env.response.headers["Content-Encoding"] = "deflate"
Flate::Writer.open(env.response) do |deflate| Compress::Deflate::Writer.open(env.response) do |deflate|
IO.copy(file, deflate) IO.copy(file, deflate)
end end
else else

@ -332,7 +332,7 @@ end
def sha256(text) def sha256(text)
digest = OpenSSL::Digest.new("SHA256") digest = OpenSSL::Digest.new("SHA256")
digest << text digest << text
return digest.hexdigest return digest.final.hexstring
end end
def subscribe_pubsub(topic, key, config) def subscribe_pubsub(topic, key, config)

Loading…
Cancel
Save