@@ -50,24 +50,25 @@ module Invidious::HttpServer
50
50
51
51
range_header = context.request.headers[" Range" ]?
52
52
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
55
57
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)
65
68
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)
70
69
end
70
+
71
+ return flush_io_to_cache(retrieve_bytes_from, file_path, file_info)
71
72
end
72
73
73
74
# Writes file data to the cache
0 commit comments