froala-editor-sdk 1.1.0 → 3.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c86f7b8547036336a509a375e6c3cffe05b08158
4
- data.tar.gz: 4d1f1fc90cb5a151148fa22689f295f8466f0e09
2
+ SHA256:
3
+ metadata.gz: 13b94a775c6d8e23e099260ebd9104cabbf2621b498d7b08d7cfb4636b449ee5
4
+ data.tar.gz: 94032571c0de0b7466b059f5edc2bdd4ba81521100f6efd2651e60815b3cb85e
5
5
  SHA512:
6
- metadata.gz: 57d7ffbc0e31ea8147d636352811e828bd115687d44ab48e588c908d6f151b1b495f785e657b30fd029e8c0e6f70f67524459f95999bb30403229efa41950be8
7
- data.tar.gz: e47944bbf7c724d6f62d3c76ed1e8762dc757c7593355c7d756301d1544fac527f1b6b37e4e91e73f0620af6f3bbd4b09afb5d3a75fc4881281127d205580231
6
+ metadata.gz: 30426bd4f3bcc3d2cbc2a052caca7dcf5dcab896f7fa8b33cf1a80b169675b5545413688af3ba08acc019e760308982ea3e8e5e54e01c91c225d868b37df997c
7
+ data.tar.gz: 1822c18b99cd8570c2a06876f505bed4ddd0afa3a24e0a7feea100fe7f856251ccf9686a047a7d343285b380bef4a7b81c6b75ed6a89ea8d61de3e921bfb8e53
@@ -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,20 +61,35 @@ 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
- :signature => self.signature(options), # Defined signature
50
- :policy => self.policy(options), # Defined policy
51
- :bucket => options[:bucket], # Upload bucket
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 => {
52
86
  :acl => options[:acl], # ACL property 'public-read'
53
- :keyStart => options[:keyStart], # Start key/folder
54
- :accessKey => options[:accessKey], # Your Access key
55
- :region => options[:region] != 'us-east-1' ? "s3-#{options[:region]}" : 's3' # Upload region
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
+ }
56
93
  }
57
94
  end
58
95
  end
@@ -1,8 +1,8 @@
1
1
  module FroalaEditorSDK
2
2
  module Version
3
- Major = 1
4
- Minor = 1
5
- Tiny = 0
3
+ Major = 3
4
+ Minor = 2
5
+ Tiny = 7
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -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.1.0
4
+ version: 3.2.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: 2017-05-29 00:00:00.000000000 Z
11
+ date: 2021-05-19 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: 3.2.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: 2.6.0
40
+ version: 3.2.7
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.1.2
90
89
  signing_key:
91
90
  specification_version: 4
92
91
  summary: Ruby on Rails SDK for Froala WYSIWYG Editor.