froala-editor-sdk 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c51a689daf99ec97c6ccebbb452f66e3c0c217b8
4
- data.tar.gz: 4dc43249a447e483c3463103d4e8cebd755ff4a5
2
+ SHA256:
3
+ metadata.gz: 495ecf38df41fef4489d7ce5608ad8c0b809b2c930ad54bcc29aa9f796eeea55
4
+ data.tar.gz: 0bb5137357c2dba0cd1e3c71b3b4730970b03047307e19104cd0e2679b28d7ec
5
5
  SHA512:
6
- metadata.gz: 642103cf3c5b322c4e7d9664c9619ef86503b720b9a1f3827a1bc94544862fce3cabd16cff1ca53045fe6145e3b60d3b0326337b109b10194daa8d7fba1c3e29
7
- data.tar.gz: 5b429455276179d3a3dc96ef5f0158ce9b5ebc70afb606a8a47546f304f74f960b9c3f25819f55b8ed3d9cda5d4fdb1bd5f951bbcfb8ce71094d6ed852513b7e
6
+ metadata.gz: 8bb73be9904214fecc2ba0844f2714345d553d033f00a5dd99794d4a8537351e159f9e6db46d7bbb71955cf055071cfbb4761d7e990f9ab431af3f4fbe050e4b
7
+ data.tar.gz: e30bd14ba369410e8023d320ad549c619d0554399a60c74801a87e3deacfb968a5d0585745105f8aef8495f4692ad4b087765405308ef8c0b36e11c867ee5430
@@ -12,7 +12,8 @@ module FroalaEditorSDK
12
12
  allowedExts: [".txt", ".pdf", ".doc", ".json", ".html"],
13
13
  allowedMimeTypes: [ "text/plain", "application/msword", "application/x-pdf", "application/pdf", "application/json","text/html" ]
14
14
  },
15
- resize: nil
15
+ resize: nil,
16
+ file_access_path: '/uploads/'
16
17
  }
17
18
 
18
19
  # Default upload path.
@@ -41,7 +42,7 @@ module FroalaEditorSDK
41
42
  path = Rails.root.join(upload_path, file_name)
42
43
 
43
44
  # Saves the file on the server and returns the path.
44
- serve_url = save(file, path)
45
+ serve_url = save(file, path, options[:file_access_path])
45
46
 
46
47
  resize(options, path) if !options[:resize].nil?
47
48
 
@@ -55,7 +56,7 @@ module FroalaEditorSDK
55
56
  # Params:
56
57
  # +file+:: The uploaded file that will be saved on the server.
57
58
  # +path+:: The path where the file will be saved.
58
- def self.save (file, path)
59
+ def self.save (file, path, file_access_path)
59
60
 
60
61
  # Create directory if it doesn't exist.
61
62
  dirname = ::File.dirname(path)
@@ -66,7 +67,7 @@ module FroalaEditorSDK
66
67
  if ::File.open(path, "wb") {|f| f.write(file.read)}
67
68
 
68
69
  # Returns a public accessible server path.
69
- return "#{"/uploads/"}#{Utils.get_file_name(path)}"
70
+ return "#{file_access_path}#{Utils.get_file_name(path)}"
70
71
  else
71
72
  return "error"
72
73
  end
@@ -80,9 +81,13 @@ module FroalaEditorSDK
80
81
  def self.delete(file = params[:file], path)
81
82
 
82
83
  file_path = Rails.root.join(path, ::File.basename(file))
83
- if ::File.delete(file_path)
84
- return true
85
- else
84
+ begin
85
+ if ::File.delete(file_path)
86
+ return true
87
+ else
88
+ return false
89
+ end
90
+ rescue => exception
86
91
  return false
87
92
  end
88
93
  end
@@ -95,7 +100,7 @@ module FroalaEditorSDK
95
100
  def self.resize (options, path)
96
101
  image = MiniMagick::Image.new(path)
97
102
  image.path
98
- image.resize("#{options[:resize][:height]}x#{options[:resize][:width]}")
103
+ image.resize("#{options[:resize][:width]}x#{options[:resize][:height]}")
99
104
  end
100
105
 
101
106
  class << self
@@ -9,7 +9,8 @@ module FroalaEditorSDK
9
9
  allowedExts: [".gif", ".jpeg", ".jpg", ".png", ".svg", ".blob"],
10
10
  allowedMimeTypes: [ "image/gif", "image/jpeg", "image/pjpeg", "image/x-png", "image/png", "image/svg+xml" ]
11
11
  },
12
- resize: nil
12
+ resize: nil,
13
+ file_access_path: '/uploads/'
13
14
  }
14
15
 
15
16
  # Default upload path.
@@ -19,13 +20,16 @@ module FroalaEditorSDK
19
20
  # Params:
20
21
  # +path+:: The server path where the images are saved
21
22
  # Returns Json object
22
- def self.load_images(path)
23
+ def self.load_images(path, options = {})
24
+
25
+ # Merge options.
26
+ options = @default_options.merge(options)
23
27
 
24
28
  images = Dir["#{path}*"]
25
29
  all_images = []
26
30
 
27
31
  images.each do |img|
28
- all_images.push({url: "#{"/uploads/"}#{Utils.get_file_name(img)}"})
32
+ all_images.push({url: "#{options[:file_access_path]}#{Utils.get_file_name(img)}"})
29
33
  end
30
34
 
31
35
  return all_images.to_json
@@ -7,12 +7,31 @@ module FroalaEditorSDK
7
7
  # Params:
8
8
  # +options+:: The configuration params that are needed to compute the signature.
9
9
  def self.signature (options = nil)
10
- Base64.encode64(
11
- OpenSSL::HMAC.digest(
12
- OpenSSL::Digest.new('sha1'),
13
- options[:secretKey], self.policy(options)
14
- )
15
- ).gsub("\n", "")
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))
16
35
  end
17
36
 
18
37
  # Encodes to Base64 the policy data and replaces new lines chars.
@@ -30,8 +49,11 @@ module FroalaEditorSDK
30
49
  expiration: 10.hours.from_now.utc.iso8601,
31
50
  conditions: [
32
51
  ["starts-with", "$key", options[:keyStart]], # Start key/folder
33
- ["starts-with", "$x-requested-with", "xhr"], # Request type
34
- ["starts-with", "$content-type", ""], # Content type
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
35
57
  {bucket: options[:bucket]}, # Bucket name
36
58
  {acl: options[:acl]}, # ACL property
37
59
  {success_action_status: "201"} # Response status 201 'file created'
@@ -39,21 +61,34 @@ module FroalaEditorSDK
39
61
  }
40
62
  end
41
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
+
42
71
  # Makes all the request in order and returns AWS hash response
43
72
  # Params:
44
73
  # +options+:: Configuration params to generate the AWS response.
45
74
  def self.data_hash (options = nil)
46
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"
47
80
 
48
81
  {
49
82
  :bucket => options[:bucket], # Upload bucket
50
83
  :region => options[:region] != 'us-east-1' ? "s3-#{options[:region]}" : 's3', # Upload region
51
84
  :keyStart => options[:keyStart], # Start key/folder
52
85
  :params => {
53
- :signature => self.signature(options), # Defined signature
54
- :AWSAccessKeyId => options[:accessKey], # Your Access key
86
+ :acl => options[:acl], # ACL property 'public-read'
55
87
  :policy => self.policy(options), # Defined policy
56
- :acl => options[:acl] # ACL property 'public-read'
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
57
92
  }
58
93
  }
59
94
  end
@@ -1,7 +1,7 @@
1
1
  module FroalaEditorSDK
2
2
  module Version
3
3
  Major = 1
4
- Minor = 2
4
+ Minor = 3
5
5
  Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -10,7 +10,8 @@ module FroalaEditorSDK
10
10
  allowedExts: [".mp4", ".webm", ".ogg"],
11
11
  allowedMimeTypes: [ "video/mp4", "video/webm", "video/ogg" ]
12
12
  },
13
- resize: nil
13
+ resize: nil,
14
+ file_access_path: '/uploads/'
14
15
  }
15
16
 
16
17
  # Default upload path.
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: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Froala Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.6.0
33
+ version: '2.9'
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: 2.6.0
40
+ version: '2.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mini_magick
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.5.0
47
+ version: '4.5'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.5.0
54
+ version: '4.5'
55
55
  description: Ruby SDK for Froala Editor
56
56
  email:
57
57
  executables: []
@@ -85,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.6.10
88
+ rubygems_version: 3.0.3
90
89
  signing_key:
91
90
  specification_version: 4
92
91
  summary: Ruby on Rails SDK for Froala WYSIWYG Editor.