forked from galetahub/ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ContentTypeDetector, Bump Version 5.1.4
- Loading branch information
Peter Kim
authored and
Peter Kim
committed
Feb 23, 2022
1 parent
e5a84d4
commit 28a4d21
Showing
5 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# encoding: utf-8 | ||
require 'cocaine' | ||
|
||
module Ckeditor | ||
module Utils | ||
class ContentTypeDetector | ||
EMPTY_CONTENT_TYPE = 'inode/x-empty'.freeze | ||
DEFAULT_CONTENT_TYPE = 'application/octet-stream'.freeze | ||
|
||
def initialize(file_path) | ||
@file_path = file_path | ||
end | ||
|
||
# content type detection strategy: | ||
# | ||
# 1. empty file: returns 'inode/x-empty' | ||
# 2. nonempty file: if the file is not empty then returns the content type using file command | ||
# 3. invalid file: file command raises error and returns 'application/octet-stream' | ||
|
||
def detect | ||
empty_file? ? EMPTY_CONTENT_TYPE : content_type_from_file_command | ||
end | ||
|
||
private | ||
|
||
def empty_file? | ||
return true if @file_path.blank? | ||
File.exist?(@file_path) && File.size(@file_path).zero? | ||
end | ||
|
||
def content_type_from_file_command | ||
Cocaine::CommandLine.new('file', '-b --mime-type :file').run(file: @file_path).strip | ||
rescue Cocaine::CommandLineError | ||
DEFAULT_CONTENT_TYPE | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
module Ckeditor | ||
module Version | ||
GEM = '5.1.3' | ||
GEM = '5.1.4' | ||
EDITOR = '4.17.0' | ||
end | ||
end |