Skip to content

Commit a49bfa7

Browse files
committed
Reduce indent in StaticAssetsHandler#serve_file
1 parent c012206 commit a49bfa7

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/invidious/http_server/static_assets_handler.cr

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,25 @@ module Invidious::HttpServer
5050

5151
range_header = context.request.headers["Range"]?
5252

53-
if !file_info.is_a? CachedFile
54-
retrieve_bytes_from = IO::Memory.new
53+
# If the file is cached we can just directly serve it
54+
if file_info.is_a? CachedFile
55+
return dispatch_serve(context, file_info.data, file_info, range_header)
56+
end
5557

56-
File.open(file_path) do |file|
57-
# We cannot cache partial data so we'll rewind and read from the start
58-
if range_header
59-
dispatch_serve(context, file, file_info, range_header)
60-
IO.copy(file.rewind, retrieve_bytes_from)
61-
else
62-
context.response.output = IO::MultiWriter.new(context.response.output, retrieve_bytes_from, sync_close: true)
63-
dispatch_serve(context, file, file_info, range_header)
64-
end
58+
# Otherwise we'll need to read from disk and cache it
59+
retrieve_bytes_from = IO::Memory.new
60+
File.open(file_path) do |file|
61+
# We cannot cache partial data so we'll rewind and read from the start
62+
if range_header
63+
dispatch_serve(context, file, file_info, range_header)
64+
IO.copy(file.rewind, retrieve_bytes_from)
65+
else
66+
context.response.output = IO::MultiWriter.new(context.response.output, retrieve_bytes_from, sync_close: true)
67+
dispatch_serve(context, file, file_info, range_header)
6568
end
66-
67-
return flush_io_to_cache(retrieve_bytes_from, file_path, file_info)
68-
else
69-
return dispatch_serve(context, file_info.data, file_info, range_header)
7069
end
70+
71+
return flush_io_to_cache(retrieve_bytes_from, file_path, file_info)
7172
end
7273

7374
# Writes file data to the cache

0 commit comments

Comments
 (0)