feat: add support for mime-type

This commit is contained in:
Glenn Y. Rolland 2023-12-31 13:47:16 +01:00
parent fdab42f2b1
commit e0f7244db7
4 changed files with 18 additions and 9 deletions

6
shard.lock Normal file
View file

@ -0,0 +1,6 @@
version: 2.0
shards:
magic:
git: https://github.com/dscottboggs/magic.cr.git
version: 1.1.0

View file

@ -9,16 +9,15 @@ targets:
authors:
- Glenn Y. Rolland <glenux@glenux.net>
dependencies:
magic:
github: dscottboggs/magic.cr
# description: |
# Short description of chatgpt-preloader
# dependencies:
# pg:
# github: will/crystal-pg
# version: "~> 0.5"
# development_dependencies:
# webmock:
# github: manastech/webmock.cr
# license: MIT
license: LGPL-3.0-or-later

View file

@ -3,6 +3,7 @@
require "file"
require "option_parser"
require "magic"
require "./config"
@ -100,10 +101,13 @@ module CodePreloader
private def process_file(root_path : String, file_path : String, output_file : IO::FileDescriptor)
relative_file_path = file_path.sub(/^#{Regex.escape(root_path)}/, ".").lstrip
output_file.puts "@@ File \"#{relative_file_path}\""
fh = File.open(file_path)
mime = Magic.mime_type.of(fh)
output_file.puts "@@ File \"#{relative_file_path}\" (Mime-Type: #{mime.inspect})"
output_file.puts ""
output_file.puts(File.read(file_path))
output_file.puts(fh.gets_to_end)
output_file.puts ""
fh.close
end
end
end

View file

@ -54,7 +54,7 @@ module CodePreloader
end
private def validate_arguments
abort("Missing repository path.") if @repository_path.nil? || @repository_path.try(&.empty?)
abort("Missing repository path.") if @repository_path_list.empty?
abort("Missing repository path.") if
STDERR.puts("Output file path not specified (using STDOUT)") if @output_file_path.nil? || @output_file_path.try(&.empty?)
end