froala-editor-sdk 4.0.1 → 4.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/froala-editor-sdk/file.rb +113 -113
- data/lib/froala-editor-sdk/image.rb +37 -37
- data/lib/froala-editor-sdk/s3.rb +95 -95
- data/lib/froala-editor-sdk/utils/utils.rb +18 -18
- data/lib/froala-editor-sdk/utils/validation.rb +34 -34
- data/lib/froala-editor-sdk/version.rb +8 -8
- data/lib/froala-editor-sdk/video.rb +19 -19
- data/lib/froala-editor-sdk.rb +11 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7905f435740d5f294336f2f5a353491e3d9ea09232a9cbe2d8dd88e23dc4d931
|
4
|
+
data.tar.gz: e4720af35a7544758118433de50f5168348b4c4a7a1da1877093143e6ce46170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6db0067313e3ebc1dad66fe3f7b5a230a146b1dbfa395e7f7fddf943bcf2cac373e9a7ee363da188a278938efb0af2be18d6be162909e5c016a1a370d4cb4246
|
7
|
+
data.tar.gz: 9bfa4c335d301fd31de963a19801a890ba9ac018cbf13ea5328aa0359ffd2e097fb9eef7ef8d18815107db78201fcb6ebb919e91ed56271ced8c88a6baf2c230
|
@@ -1,114 +1,114 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
# File functionality.
|
6
|
-
class File
|
7
|
-
|
8
|
-
# Default options that are used if no options are passed to the upload function
|
9
|
-
@default_options = {
|
10
|
-
fieldname: 'file',
|
11
|
-
validation: {
|
12
|
-
allowedExts: [".txt", ".pdf", ".doc", ".json", ".html"],
|
13
|
-
allowedMimeTypes: [ "text/plain", "application/msword", "application/x-pdf", "application/pdf", "application/json","text/html" ]
|
14
|
-
},
|
15
|
-
resize: nil,
|
16
|
-
file_access_path: '/uploads/'
|
17
|
-
}
|
18
|
-
|
19
|
-
# Default upload path.
|
20
|
-
@default_upload_path = "public/uploads/files"
|
21
|
-
|
22
|
-
# Uploads a file to the server.
|
23
|
-
# Params:
|
24
|
-
# +params+:: File upload parameter mostly is "file".
|
25
|
-
# +upload_path+:: Server upload path, a storage path where the file will be stored.
|
26
|
-
# +options+:: Hash object that contains configuration parameters for uploading a file.
|
27
|
-
# Returns json object
|
28
|
-
def self.upload(params, upload_path = @default_upload_path, options = {})
|
29
|
-
|
30
|
-
# Merge options.
|
31
|
-
options = @default_options.merge(options)
|
32
|
-
|
33
|
-
file = params[options[:fieldname]]
|
34
|
-
|
35
|
-
if file
|
36
|
-
|
37
|
-
# Validates the file extension and mime type.
|
38
|
-
validation = Validation.check(file, options)
|
39
|
-
|
40
|
-
# Uses the Utlis name function to generate a random name for the file.
|
41
|
-
file_name = Utils.name(file)
|
42
|
-
path = Rails.root.join(upload_path, file_name)
|
43
|
-
|
44
|
-
# Saves the file on the server and returns the path.
|
45
|
-
serve_url = save(file, path, options[:file_access_path])
|
46
|
-
|
47
|
-
resize(options, path) if !options[:resize].nil?
|
48
|
-
|
49
|
-
return {:link => serve_url}.to_json
|
50
|
-
else
|
51
|
-
return nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Saves a file on the server.
|
56
|
-
# Params:
|
57
|
-
# +file+:: The uploaded file that will be saved on the server.
|
58
|
-
# +path+:: The path where the file will be saved.
|
59
|
-
def self.save (file, path, file_access_path)
|
60
|
-
|
61
|
-
# Create directory if it doesn't exist.
|
62
|
-
dirname = ::File.dirname(path)
|
63
|
-
unless ::File.directory?(dirname)
|
64
|
-
::FileUtils.mkdir_p(dirname)
|
65
|
-
end
|
66
|
-
|
67
|
-
if ::File.open(path, "wb") {|f| f.write(file.read)}
|
68
|
-
|
69
|
-
# Returns a public accessible server path.
|
70
|
-
return "#{file_access_path}#{Utils.get_file_name(path)}"
|
71
|
-
else
|
72
|
-
return "error"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Deletes a file found on the server.
|
77
|
-
# Params:
|
78
|
-
# +file+:: The file that will be deleted from the server.
|
79
|
-
# +path+:: The server path where the file resides.
|
80
|
-
# Returns true or false.
|
81
|
-
def self.delete(file = params[:file], path)
|
82
|
-
|
83
|
-
file_path = Rails.root.join(path, ::File.basename(file))
|
84
|
-
begin
|
85
|
-
if ::File.delete(file_path)
|
86
|
-
return true
|
87
|
-
else
|
88
|
-
return false
|
89
|
-
end
|
90
|
-
rescue => exception
|
91
|
-
return false
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Resizes an image based on the options provided.
|
96
|
-
# The function resizes the original file,
|
97
|
-
# Params:
|
98
|
-
# +options+:: The options that contain the resize hash
|
99
|
-
# +path+:: The path where the image is stored
|
100
|
-
def self.resize (options, path)
|
101
|
-
image = MiniMagick::Image.new(path)
|
102
|
-
image.path
|
103
|
-
image.resize("#{options[:resize][:width]}x#{options[:resize][:height]}")
|
104
|
-
end
|
105
|
-
|
106
|
-
class << self
|
107
|
-
attr_reader :var
|
108
|
-
end
|
109
|
-
|
110
|
-
def var
|
111
|
-
self.class.var
|
112
|
-
end
|
113
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
# File functionality.
|
6
|
+
class File
|
7
|
+
|
8
|
+
# Default options that are used if no options are passed to the upload function
|
9
|
+
@default_options = {
|
10
|
+
fieldname: 'file',
|
11
|
+
validation: {
|
12
|
+
allowedExts: [".txt", ".pdf", ".doc", ".json", ".html"],
|
13
|
+
allowedMimeTypes: [ "text/plain", "application/msword", "application/x-pdf", "application/pdf", "application/json","text/html" ]
|
14
|
+
},
|
15
|
+
resize: nil,
|
16
|
+
file_access_path: '/uploads/'
|
17
|
+
}
|
18
|
+
|
19
|
+
# Default upload path.
|
20
|
+
@default_upload_path = "public/uploads/files"
|
21
|
+
|
22
|
+
# Uploads a file to the server.
|
23
|
+
# Params:
|
24
|
+
# +params+:: File upload parameter mostly is "file".
|
25
|
+
# +upload_path+:: Server upload path, a storage path where the file will be stored.
|
26
|
+
# +options+:: Hash object that contains configuration parameters for uploading a file.
|
27
|
+
# Returns json object
|
28
|
+
def self.upload(params, upload_path = @default_upload_path, options = {})
|
29
|
+
|
30
|
+
# Merge options.
|
31
|
+
options = @default_options.merge(options)
|
32
|
+
|
33
|
+
file = params[options[:fieldname]]
|
34
|
+
|
35
|
+
if file
|
36
|
+
|
37
|
+
# Validates the file extension and mime type.
|
38
|
+
validation = Validation.check(file, options)
|
39
|
+
|
40
|
+
# Uses the Utlis name function to generate a random name for the file.
|
41
|
+
file_name = Utils.name(file)
|
42
|
+
path = Rails.root.join(upload_path, file_name)
|
43
|
+
|
44
|
+
# Saves the file on the server and returns the path.
|
45
|
+
serve_url = save(file, path, options[:file_access_path])
|
46
|
+
|
47
|
+
resize(options, path) if !options[:resize].nil?
|
48
|
+
|
49
|
+
return {:link => serve_url}.to_json
|
50
|
+
else
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Saves a file on the server.
|
56
|
+
# Params:
|
57
|
+
# +file+:: The uploaded file that will be saved on the server.
|
58
|
+
# +path+:: The path where the file will be saved.
|
59
|
+
def self.save (file, path, file_access_path)
|
60
|
+
|
61
|
+
# Create directory if it doesn't exist.
|
62
|
+
dirname = ::File.dirname(path)
|
63
|
+
unless ::File.directory?(dirname)
|
64
|
+
::FileUtils.mkdir_p(dirname)
|
65
|
+
end
|
66
|
+
|
67
|
+
if ::File.open(path, "wb") {|f| f.write(file.read)}
|
68
|
+
|
69
|
+
# Returns a public accessible server path.
|
70
|
+
return "#{file_access_path}#{Utils.get_file_name(path)}"
|
71
|
+
else
|
72
|
+
return "error"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Deletes a file found on the server.
|
77
|
+
# Params:
|
78
|
+
# +file+:: The file that will be deleted from the server.
|
79
|
+
# +path+:: The server path where the file resides.
|
80
|
+
# Returns true or false.
|
81
|
+
def self.delete(file = params[:file], path)
|
82
|
+
|
83
|
+
file_path = Rails.root.join(path, ::File.basename(file))
|
84
|
+
begin
|
85
|
+
if ::File.delete(file_path)
|
86
|
+
return true
|
87
|
+
else
|
88
|
+
return false
|
89
|
+
end
|
90
|
+
rescue => exception
|
91
|
+
return false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Resizes an image based on the options provided.
|
96
|
+
# The function resizes the original file,
|
97
|
+
# Params:
|
98
|
+
# +options+:: The options that contain the resize hash
|
99
|
+
# +path+:: The path where the image is stored
|
100
|
+
def self.resize (options, path)
|
101
|
+
image = MiniMagick::Image.new(path)
|
102
|
+
image.path
|
103
|
+
image.resize("#{options[:resize][:width]}x#{options[:resize][:height]}")
|
104
|
+
end
|
105
|
+
|
106
|
+
class << self
|
107
|
+
attr_reader :var
|
108
|
+
end
|
109
|
+
|
110
|
+
def var
|
111
|
+
self.class.var
|
112
|
+
end
|
113
|
+
end
|
114
114
|
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
# Image functionality.
|
3
|
-
class Image < File
|
4
|
-
|
5
|
-
# Default options that are used if no options are passed to the upload function.
|
6
|
-
@default_options = {
|
7
|
-
fieldname: 'file',
|
8
|
-
validation: {
|
9
|
-
allowedExts: [".gif", ".jpeg", ".jpg", ".png", ".svg", ".blob"],
|
10
|
-
allowedMimeTypes: [ "image/gif", "image/jpeg", "image/pjpeg", "image/x-png", "image/png", "image/svg+xml" ]
|
11
|
-
},
|
12
|
-
resize: nil,
|
13
|
-
file_access_path: '/uploads/'
|
14
|
-
}
|
15
|
-
|
16
|
-
# Default upload path.
|
17
|
-
@default_upload_path = "public/uploads/images"
|
18
|
-
|
19
|
-
# Loads the images from a specific path
|
20
|
-
# Params:
|
21
|
-
# +path+:: The server path where the images are saved
|
22
|
-
# Returns Json object
|
23
|
-
def self.load_images(path, options = {})
|
24
|
-
|
25
|
-
# Merge options.
|
26
|
-
options = @default_options.merge(options)
|
27
|
-
|
28
|
-
images = Dir["#{path}*"]
|
29
|
-
all_images = []
|
30
|
-
|
31
|
-
images.each do |img|
|
32
|
-
all_images.push({url: "#{options[:file_access_path]}#{Utils.get_file_name(img)}"})
|
33
|
-
end
|
34
|
-
|
35
|
-
return all_images.to_json
|
36
|
-
end
|
37
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
# Image functionality.
|
3
|
+
class Image < File
|
4
|
+
|
5
|
+
# Default options that are used if no options are passed to the upload function.
|
6
|
+
@default_options = {
|
7
|
+
fieldname: 'file',
|
8
|
+
validation: {
|
9
|
+
allowedExts: [".gif", ".jpeg", ".jpg", ".png", ".svg", ".blob"],
|
10
|
+
allowedMimeTypes: [ "image/gif", "image/jpeg", "image/pjpeg", "image/x-png", "image/png", "image/svg+xml" ]
|
11
|
+
},
|
12
|
+
resize: nil,
|
13
|
+
file_access_path: '/uploads/'
|
14
|
+
}
|
15
|
+
|
16
|
+
# Default upload path.
|
17
|
+
@default_upload_path = "public/uploads/images"
|
18
|
+
|
19
|
+
# Loads the images from a specific path
|
20
|
+
# Params:
|
21
|
+
# +path+:: The server path where the images are saved
|
22
|
+
# Returns Json object
|
23
|
+
def self.load_images(path, options = {})
|
24
|
+
|
25
|
+
# Merge options.
|
26
|
+
options = @default_options.merge(options)
|
27
|
+
|
28
|
+
images = Dir["#{path}*"]
|
29
|
+
all_images = []
|
30
|
+
|
31
|
+
images.each do |img|
|
32
|
+
all_images.push({url: "#{options[:file_access_path]}#{Utils.get_file_name(img)}"})
|
33
|
+
end
|
34
|
+
|
35
|
+
return all_images.to_json
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
data/lib/froala-editor-sdk/s3.rb
CHANGED
@@ -1,96 +1,96 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
|
3
|
-
# Uploads files to S3/AWS
|
4
|
-
class S3
|
5
|
-
|
6
|
-
# Builds a signature based on the options.
|
7
|
-
# Params:
|
8
|
-
# +options+:: The configuration params that are needed to compute the signature.
|
9
|
-
def self.signature (options = nil)
|
10
|
-
OpenSSL::HMAC.hexdigest(
|
11
|
-
"SHA256",
|
12
|
-
self.sign(
|
13
|
-
self.sign(
|
14
|
-
self.sign(
|
15
|
-
self.sign(
|
16
|
-
("AWS4" + options[:secretKey]).force_encoding(Encoding::UTF_8),
|
17
|
-
options[:'date-string']
|
18
|
-
),
|
19
|
-
options[:region]
|
20
|
-
),
|
21
|
-
"s3"
|
22
|
-
),
|
23
|
-
"aws4_request"
|
24
|
-
),
|
25
|
-
self.policy(options)
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Builds a HMAC-SHA256 digest using key and data
|
30
|
-
# Params:
|
31
|
-
# +key+:: Key to use for creating the digest
|
32
|
-
# +data+:: Data to be used for creating the digest
|
33
|
-
def self.sign(key, data)
|
34
|
-
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, data.force_encoding(Encoding::UTF_8))
|
35
|
-
end
|
36
|
-
|
37
|
-
# Encodes to Base64 the policy data and replaces new lines chars.
|
38
|
-
# Params:
|
39
|
-
# +options+:: The configuration params that are needed to compute the signature.
|
40
|
-
def self.policy (options = nil)
|
41
|
-
Base64.encode64(self.policy_data(options).to_json).gsub("\n", "")
|
42
|
-
end
|
43
|
-
|
44
|
-
# Sets policy params, bucket that will be used max file size and other params.
|
45
|
-
# Params:
|
46
|
-
# +options+:: Configuration params that are needed to set the policy
|
47
|
-
def self.policy_data (options = nil)
|
48
|
-
{
|
49
|
-
expiration: 10.hours.from_now.utc.iso8601,
|
50
|
-
conditions: [
|
51
|
-
["starts-with", "$key", options[:keyStart]], # Start key/folder
|
52
|
-
["starts-with", "$Content-type", ""], # Content type
|
53
|
-
{"x-requested-with": "xhr"}, # Request type
|
54
|
-
{"x-amz-algorithm": options[:'x-amz-algorithm']}, # Encrytion Algorithm
|
55
|
-
{"x-amz-date": options[:'x-amz-date']}, # Current Date
|
56
|
-
{"x-amz-credential": options[:'x-amz-credential']}, # Encrypted Credentials
|
57
|
-
{bucket: options[:bucket]}, # Bucket name
|
58
|
-
{acl: options[:acl]}, # ACL property
|
59
|
-
{success_action_status: "201"} # Response status 201 'file created'
|
60
|
-
]
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
# Builds the amazon credential by appending access key, x-amz-date, region and 's3/aws4_request'
|
65
|
-
# Params:
|
66
|
-
# +options+:: Configuration params to generate the AWS response
|
67
|
-
def self.getXamzCredential(options = nil)
|
68
|
-
"#{options[:accessKey]}#{"/"}#{options[:'date-string']}#{"/"}#{options[:region]}#{"/"}#{"s3/aws4_request"}"
|
69
|
-
end
|
70
|
-
|
71
|
-
# Makes all the request in order and returns AWS hash response
|
72
|
-
# Params:
|
73
|
-
# +options+:: Configuration params to generate the AWS response.
|
74
|
-
def self.data_hash (options = nil)
|
75
|
-
options[:region] = 'us-east-1' if options[:region].nil? || options[:region] == 's3'
|
76
|
-
options[:'date-string'] = Time.now.strftime("%Y%m%d")
|
77
|
-
options[:'x-amz-algorithm'] = "AWS4-HMAC-SHA256"
|
78
|
-
options[:'x-amz-credential'] = self.getXamzCredential(options)
|
79
|
-
options[:'x-amz-date'] = options[:'date-string'] + "T000000Z"
|
80
|
-
|
81
|
-
{
|
82
|
-
:bucket => options[:bucket], # Upload bucket
|
83
|
-
:region => options[:region] != 'us-east-1' ? "s3-#{options[:region]}" : 's3', # Upload region
|
84
|
-
:keyStart => options[:keyStart], # Start key/folder
|
85
|
-
:params => {
|
86
|
-
:acl => options[:acl], # ACL property 'public-read'
|
87
|
-
:policy => self.policy(options), # Defined policy
|
88
|
-
:'x-amz-algorithm' => options[:'x-amz-algorithm'], # Encrytion Algorithm
|
89
|
-
:'x-amz-credential' => options[:'x-amz-credential'], # Encrypted Credentials
|
90
|
-
:'x-amz-date' => options[:'x-amz-date'], # Current Date
|
91
|
-
:'x-amz-signature' => self.signature(options), # Defined signature
|
92
|
-
}
|
93
|
-
}
|
94
|
-
end
|
95
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
|
3
|
+
# Uploads files to S3/AWS
|
4
|
+
class S3
|
5
|
+
|
6
|
+
# Builds a signature based on the options.
|
7
|
+
# Params:
|
8
|
+
# +options+:: The configuration params that are needed to compute the signature.
|
9
|
+
def self.signature (options = nil)
|
10
|
+
OpenSSL::HMAC.hexdigest(
|
11
|
+
"SHA256",
|
12
|
+
self.sign(
|
13
|
+
self.sign(
|
14
|
+
self.sign(
|
15
|
+
self.sign(
|
16
|
+
("AWS4" + options[:secretKey]).force_encoding(Encoding::UTF_8),
|
17
|
+
options[:'date-string']
|
18
|
+
),
|
19
|
+
options[:region]
|
20
|
+
),
|
21
|
+
"s3"
|
22
|
+
),
|
23
|
+
"aws4_request"
|
24
|
+
),
|
25
|
+
self.policy(options)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Builds a HMAC-SHA256 digest using key and data
|
30
|
+
# Params:
|
31
|
+
# +key+:: Key to use for creating the digest
|
32
|
+
# +data+:: Data to be used for creating the digest
|
33
|
+
def self.sign(key, data)
|
34
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, data.force_encoding(Encoding::UTF_8))
|
35
|
+
end
|
36
|
+
|
37
|
+
# Encodes to Base64 the policy data and replaces new lines chars.
|
38
|
+
# Params:
|
39
|
+
# +options+:: The configuration params that are needed to compute the signature.
|
40
|
+
def self.policy (options = nil)
|
41
|
+
Base64.encode64(self.policy_data(options).to_json).gsub("\n", "")
|
42
|
+
end
|
43
|
+
|
44
|
+
# Sets policy params, bucket that will be used max file size and other params.
|
45
|
+
# Params:
|
46
|
+
# +options+:: Configuration params that are needed to set the policy
|
47
|
+
def self.policy_data (options = nil)
|
48
|
+
{
|
49
|
+
expiration: 10.hours.from_now.utc.iso8601,
|
50
|
+
conditions: [
|
51
|
+
["starts-with", "$key", options[:keyStart]], # Start key/folder
|
52
|
+
["starts-with", "$Content-type", ""], # Content type
|
53
|
+
{"x-requested-with": "xhr"}, # Request type
|
54
|
+
{"x-amz-algorithm": options[:'x-amz-algorithm']}, # Encrytion Algorithm
|
55
|
+
{"x-amz-date": options[:'x-amz-date']}, # Current Date
|
56
|
+
{"x-amz-credential": options[:'x-amz-credential']}, # Encrypted Credentials
|
57
|
+
{bucket: options[:bucket]}, # Bucket name
|
58
|
+
{acl: options[:acl]}, # ACL property
|
59
|
+
{success_action_status: "201"} # Response status 201 'file created'
|
60
|
+
]
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# Builds the amazon credential by appending access key, x-amz-date, region and 's3/aws4_request'
|
65
|
+
# Params:
|
66
|
+
# +options+:: Configuration params to generate the AWS response
|
67
|
+
def self.getXamzCredential(options = nil)
|
68
|
+
"#{options[:accessKey]}#{"/"}#{options[:'date-string']}#{"/"}#{options[:region]}#{"/"}#{"s3/aws4_request"}"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Makes all the request in order and returns AWS hash response
|
72
|
+
# Params:
|
73
|
+
# +options+:: Configuration params to generate the AWS response.
|
74
|
+
def self.data_hash (options = nil)
|
75
|
+
options[:region] = 'us-east-1' if options[:region].nil? || options[:region] == 's3'
|
76
|
+
options[:'date-string'] = Time.now.strftime("%Y%m%d")
|
77
|
+
options[:'x-amz-algorithm'] = "AWS4-HMAC-SHA256"
|
78
|
+
options[:'x-amz-credential'] = self.getXamzCredential(options)
|
79
|
+
options[:'x-amz-date'] = options[:'date-string'] + "T000000Z"
|
80
|
+
|
81
|
+
{
|
82
|
+
:bucket => options[:bucket], # Upload bucket
|
83
|
+
:region => options[:region] != 'us-east-1' ? "s3-#{options[:region]}" : 's3', # Upload region
|
84
|
+
:keyStart => options[:keyStart], # Start key/folder
|
85
|
+
:params => {
|
86
|
+
:acl => options[:acl], # ACL property 'public-read'
|
87
|
+
:policy => self.policy(options), # Defined policy
|
88
|
+
:'x-amz-algorithm' => options[:'x-amz-algorithm'], # Encrytion Algorithm
|
89
|
+
:'x-amz-credential' => options[:'x-amz-credential'], # Encrypted Credentials
|
90
|
+
:'x-amz-date' => options[:'x-amz-date'], # Current Date
|
91
|
+
:'x-amz-signature' => self.signature(options), # Defined signature
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
96
96
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
|
3
|
-
# Basic utility functionality.
|
4
|
-
class Utils
|
5
|
-
|
6
|
-
# Generates a random name that will be used as name for files.
|
7
|
-
def self.name (file)
|
8
|
-
name = SecureRandom.urlsafe_base64
|
9
|
-
ext = ::File.extname(file.original_filename)
|
10
|
-
|
11
|
-
return "#{name}#{ext}"
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns file name from an file path
|
15
|
-
def self.get_file_name(path)
|
16
|
-
return ::File.basename(path)
|
17
|
-
end
|
18
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
|
3
|
+
# Basic utility functionality.
|
4
|
+
class Utils
|
5
|
+
|
6
|
+
# Generates a random name that will be used as name for files.
|
7
|
+
def self.name (file)
|
8
|
+
name = SecureRandom.urlsafe_base64
|
9
|
+
ext = ::File.extname(file.original_filename)
|
10
|
+
|
11
|
+
return "#{name}#{ext}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns file name from an file path
|
15
|
+
def self.get_file_name(path)
|
16
|
+
return ::File.basename(path)
|
17
|
+
end
|
18
|
+
end
|
19
19
|
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
|
3
|
-
# Image Validation class.
|
4
|
-
# Checks if image is matching the allowed extensions and mime types.
|
5
|
-
class Validation
|
6
|
-
require "mime-types"
|
7
|
-
|
8
|
-
def self.ext(ext, options)
|
9
|
-
raise "Not allowed" unless options[:validation][:allowedExts].include?(ext)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.mime(mime, options)
|
13
|
-
raise "Invalid mime type" unless options[:validation][:allowedMimeTypes].include?(mime)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Checks an image with the options.
|
17
|
-
# Params:
|
18
|
-
# +file+:: The image that will be validated.
|
19
|
-
# +options+:: The image options that contain allowed extensions and mime types.
|
20
|
-
# Raises exception if the image has not passed the validation
|
21
|
-
def self.check(file, options = nil)
|
22
|
-
|
23
|
-
mime = file.content_type
|
24
|
-
ext = ::File.extname(file.original_filename)
|
25
|
-
|
26
|
-
# Check if there is custom validation.
|
27
|
-
if options[:validation].class != Proc
|
28
|
-
ext(ext, options) && mime(mime, options)
|
29
|
-
else
|
30
|
-
options[:validation].call(file.path, mime)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
|
3
|
+
# Image Validation class.
|
4
|
+
# Checks if image is matching the allowed extensions and mime types.
|
5
|
+
class Validation
|
6
|
+
require "mime-types"
|
7
|
+
|
8
|
+
def self.ext(ext, options)
|
9
|
+
raise "Not allowed" unless options[:validation][:allowedExts].include?(ext)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.mime(mime, options)
|
13
|
+
raise "Invalid mime type" unless options[:validation][:allowedMimeTypes].include?(mime)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Checks an image with the options.
|
17
|
+
# Params:
|
18
|
+
# +file+:: The image that will be validated.
|
19
|
+
# +options+:: The image options that contain allowed extensions and mime types.
|
20
|
+
# Raises exception if the image has not passed the validation
|
21
|
+
def self.check(file, options = nil)
|
22
|
+
|
23
|
+
mime = file.content_type
|
24
|
+
ext = ::File.extname(file.original_filename)
|
25
|
+
|
26
|
+
# Check if there is custom validation.
|
27
|
+
if options[:validation].class != Proc
|
28
|
+
ext(ext, options) && mime(mime, options)
|
29
|
+
else
|
30
|
+
options[:validation].call(file.path, mime)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
35
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
module Version
|
3
|
-
Major = 4
|
4
|
-
Minor = 0
|
5
|
-
Tiny =
|
6
|
-
|
7
|
-
String = "#{Major}.#{Minor}.#{Tiny}"
|
8
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
module Version
|
3
|
+
Major = 4
|
4
|
+
Minor = 0
|
5
|
+
Tiny = 7
|
6
|
+
|
7
|
+
String = "#{Major}.#{Minor}.#{Tiny}"
|
8
|
+
end
|
9
9
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
module FroalaEditorSDK
|
2
|
-
|
3
|
-
# Video functionality.
|
4
|
-
class Video < File
|
5
|
-
|
6
|
-
# Default options that are used if no options are passed to the upload function
|
7
|
-
@default_options = {
|
8
|
-
fieldname: 'file',
|
9
|
-
validation: {
|
10
|
-
allowedExts: [".mp4", ".webm", ".ogg"],
|
11
|
-
allowedMimeTypes: [ "video/mp4", "video/webm", "video/ogg" ]
|
12
|
-
},
|
13
|
-
resize: nil,
|
14
|
-
file_access_path: '/uploads/'
|
15
|
-
}
|
16
|
-
|
17
|
-
# Default upload path.
|
18
|
-
@default_upload_path = "public/uploads/videos"
|
19
|
-
end
|
1
|
+
module FroalaEditorSDK
|
2
|
+
|
3
|
+
# Video functionality.
|
4
|
+
class Video < File
|
5
|
+
|
6
|
+
# Default options that are used if no options are passed to the upload function
|
7
|
+
@default_options = {
|
8
|
+
fieldname: 'file',
|
9
|
+
validation: {
|
10
|
+
allowedExts: [".mp4", ".webm", ".ogg"],
|
11
|
+
allowedMimeTypes: [ "video/mp4", "video/webm", "video/ogg" ]
|
12
|
+
},
|
13
|
+
resize: nil,
|
14
|
+
file_access_path: '/uploads/'
|
15
|
+
}
|
16
|
+
|
17
|
+
# Default upload path.
|
18
|
+
@default_upload_path = "public/uploads/videos"
|
19
|
+
end
|
20
20
|
end
|
data/lib/froala-editor-sdk.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'mime-types'
|
2
|
-
require 'mini_magick'
|
3
|
-
require 'froala-editor-sdk/utils/validation'
|
4
|
-
require 'froala-editor-sdk/utils/utils'
|
5
|
-
|
6
|
-
|
7
|
-
require 'froala-editor-sdk/file'
|
8
|
-
require 'froala-editor-sdk/image'
|
9
|
-
require 'froala-editor-sdk/s3'
|
10
|
-
require 'froala-editor-sdk/version'
|
11
|
-
require 'froala-editor-sdk/video'
|
1
|
+
require 'mime-types'
|
2
|
+
require 'mini_magick'
|
3
|
+
require 'froala-editor-sdk/utils/validation'
|
4
|
+
require 'froala-editor-sdk/utils/utils'
|
5
|
+
|
6
|
+
|
7
|
+
require 'froala-editor-sdk/file'
|
8
|
+
require 'froala-editor-sdk/image'
|
9
|
+
require 'froala-editor-sdk/s3'
|
10
|
+
require 'froala-editor-sdk/version'
|
11
|
+
require 'froala-editor-sdk/video'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: froala-editor-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Froala Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.0.
|
33
|
+
version: 4.0.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.0.
|
40
|
+
version: 4.0.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mini_magick
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
rubygems_version: 3.
|
88
|
+
rubygems_version: 3.2.22
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: Ruby on Rails SDK for Froala WYSIWYG Editor.
|