Skip to content

Commit 57c7a55

Browse files
Merge pull request #6 from froala-labs/review
First review.
2 parents 636c39e + c56ffd1 commit 57c7a55

File tree

8 files changed

+69
-268
lines changed

8 files changed

+69
-268
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2016 Froala Labs
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 14 additions & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -1,263 +1,37 @@
1-
# Node.js SDK for Froala Editor
1+
# Froala WYSIWYG Editor Node.JS SDK
22

3-
Easing the [Froala WYSIWYG HTML Editor](https://github.com/froala/wysiwyg-editor) inclusion in Node.js projects
3+
Easing the [Froala WYSIWYG HTML Editor](https://github.com/froala/wysiwyg-editor) server side integration in Node.JS projects.
44

55
## Installation
66

77
1. Clone this repo or download the zip.
88

9-
2. Run `npm install`
9+
2. Run `npm install`.
1010

11-
3. Load `lib` directory in your project and import it: `var FroalaEditor = require('path/to/lib/froalaEditor.js');`
11+
3. (Optional) Run `bower install` to install the editor JS.
1212

13-
4. To run examples:
14-
* `npm start` to start a nodejs server form `examples` directory at `http://localhost:3000/`
13+
3. Load `lib` directory in your project and import it: `var FroalaEditor = require('path/to/lib/froalaEditor.js');`
1514

16-
## Usage
15+
4. To run examples:
16+
* `npm start` to start a nodejs server form `examples` directory at `http://localhost:3000/`
1717

18-
### Import lib
18+
## Import lib
1919
```javascript
2020
var FroalaEditor = require('path/to/lib/froalaEditor.js');
2121
```
2222

23-
### Upload image to disk
24-
25-
`FroalaEditor.Image.upload(req, options, callback);`
26-
27-
* `req` http multipart request stream
28-
29-
* `options` object (can be `null`)
30-
31-
Properties:
32-
33-
`fileRoute`: default is '/uploads/'. It represents the public location where your files will be stored, eg: www.site.com/uploads/.
34-
35-
`validation`: default is null and it verifies if the image extension is 'gif', 'jpeg', 'jpg', 'png' or 'blob' and if the mimetype is 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png' or 'image/png'.
36-
37-
It can be a function with filename, mimetype and a callback as parameters:
38-
39-
```javascript
40-
function isImageValid(filepath, mimetype, callback) {
41-
// Call callback(null, true) if the image is valid, callback(null, false) otherwise.
42-
// Call callback(err) if some error occurred.
43-
}
44-
```
45-
46-
* `callback` function(err, data):
47-
48-
`err` is `null` if no error occured
49-
50-
`data` is the object that needs to be sent back to the editor: `{link: 'link/to/image'}`.
51-
52-
* If fileRoute is '/uploads/' and image name is image.png then the link will be '/uploads/image.png'.
53-
54-
The link should be public in your server so you can access it. With express you can achieve it like this:
55-
56-
```javascript
57-
var express = require('express');
58-
var app = express();
59-
app.use(express.static(__dirname + '/uploads/'));
60-
```
61-
62-
Example:
63-
```javascript
64-
FroalaEditor.Image.upload(req, null, function(err, data) {
65-
66-
if (err) {
67-
return res.send(err);
68-
}
69-
res.send(data);
70-
});
71-
```
72-
73-
### Upload file to disk
74-
75-
`FroalaEditor.File.upload(req, options, callback);`
76-
77-
* `req` http multipart request stream
78-
79-
* `options` object (can be `null`)
80-
81-
Properties:
82-
83-
`fileRoute`: default is '/uploads/'. It represents the public location where your files will be stored, eg: www.site.com/uploads/.
84-
85-
`validation`: default is null and it verifies if the file extension is 'txt', 'pdf' or 'doc' and if the mimetype is 'text/plain', 'application/msword', 'application/x-pdf' or 'application/pdf'.
86-
87-
It can be a function with filename, mimetype and a callback as parameters:
88-
89-
```javascript
90-
function isFileValid(filepath, mimetype, callback) {
91-
// Call callback(null, true) if the file is valid, callback(null, false) otherwise.
92-
// Call callback(err) if some error occurred.
93-
}
94-
```
95-
96-
* `callback` function(err, data):
97-
98-
`err` is `null` if no error occured
99-
100-
`data` is the object that needs to be sent back to the editor: `{link: 'link/to/file'}`.
101-
102-
* If fileRoute is '/uploads/' and file name is file.pdf then the link will be '/uploads/file.pdf'.
103-
104-
The link should be public in your server so you can access it. With express you can achieve it like this:
105-
106-
```javascript
107-
var express = require('express');
108-
var app = express();
109-
app.use(express.static(__dirname + '/uploads/'));
110-
```
111-
112-
Example:
113-
```javascript
114-
FroalaEditor.File.upload(req, {fileRoute: '/uploads/pdfs/'}, function(err, data) {
115-
116-
if (err) {
117-
return res.status(404).end(err);
118-
}
119-
res.send(data);
120-
});
121-
```
122-
123-
### Delete image from disk
124-
125-
`FroalaEditor.Image.delete(link, callback);`
126-
127-
* `link` public link to image
128-
129-
* `callback` function(err):
130-
131-
`err` is `null` if no error occured
132-
133-
Example:
134-
```javascript
135-
FroalaEditor.Image.delete(req.body.src, function(err) {
136-
137-
if (err) {
138-
return res.status(404).end(err);
139-
}
140-
return res.end();
141-
});
142-
```
143-
144-
### Delete file from disk
145-
146-
`FroalaEditor.File.delete(link, callback);`
147-
148-
* `link` public link to file
149-
150-
* `callback` function(err):
151-
152-
`err` is `null` if no error occured
153-
154-
Example:
155-
```javascript
156-
FroalaEditor.File.delete(req.body.src, function(err) {
157-
158-
if (err) {
159-
return res.status(404).end(err);
160-
}
161-
return res.end();
162-
});
163-
```
164-
165-
### Load images into [Image Manager](https://www.froala.com/wysiwyg-editor/docs/concepts/image-manager)
166-
167-
`FroalaEditor.Image.list(route, callback);`
168-
169-
* `route` public route to image. If the image link is '/uploads/image.png' then the route is '/uploads/'
23+
## Documentation
17024

171-
* `callback` function(err):
25+
* [Official documentation](https://www.froala.com/wysiwyg-editor/docs/sdks/nodejs)
17226

173-
`err` is `null` if no error occured
27+
## Help
28+
- Found a bug or have some suggestions? Just submit an issue.
29+
- Having trouble with your integration? [Contact Froala Support team](http://froala.dev/wysiwyg-editor/contact).
17430

175-
Example:
176-
```javascript
177-
FroalaEditor.Image.list(req.body.route, function(err) {
178-
179-
if (err) {
180-
return res.status(404).end(err);
181-
}
182-
return res.end();
183-
});
184-
```
185-
186-
### Get Amazon S3 upload configs with v4 signature
187-
188-
`FroalaEditor.S3.getHash(config);`
189-
190-
* `config` object:
191-
192-
```javascript
193-
{
194-
bucket: 'bucketName',
195-
region: 'region',
196-
keyStart: 'editor/',
197-
acl: 'public-read',
198-
awsAccessKey: 'YOUR-AMAZON-S3-PUBLIC-ACCESS-KEY',
199-
awsSecretAccessKey: 'YOUR-AMAZON-S3-SECRET-ACCESS-KEY'
200-
}
201-
```
202-
203-
* returns the needed object for the editor to work with Amazon S3
204-
205-
```javascript
206-
{
207-
bucket: bucket,
208-
region: region,
209-
keyStart: keyStart,
210-
params: {
211-
acl: acl,
212-
policy: policy,
213-
'x-amz-algorithm': 'AWS4-HMAC-SHA256',
214-
'x-amz-credential': xAmzCredential,
215-
'x-amz-date': xAmzDate,
216-
'x-amz-signature': signature
217-
}
218-
}
219-
```
220-
221-
### Example:
222-
223-
* Frontend
224-
225-
```javascript
226-
$(function() {
227-
228-
$.get( "get_amazon", {})
229-
.done(function( data ) {
230-
231-
$('#edit-amazon').froalaEditor({
232-
imageUploadToS3: data,
233-
fileUploadToS3: data
234-
})
235-
});
236-
});
237-
```
238-
239-
* Backend
240-
241-
```javascript
242-
app.get('/get_amazon', function (req, res) {
243-
244-
var config = {
245-
bucket: 'test',
246-
region: 'region',
247-
keyStart: 'editor/',
248-
acl: 'public-read',
249-
awsAccessKey: '',
250-
awsSecretAccessKey: ''
251-
}
252-
253-
var hash = FroalaEditor.S3.getHash(config);
254-
res.send(hash);
255-
});
256-
```
25731

25832
## License
25933

260-
The `froala-editor-node-sdk` project is under MIT license. However, in order to use Froala WYSIWYG HTML Editor plugin you should purchase a license for it.
34+
The Froala WYSIWYG Editor Node.JS SDK is licensed under MIT license. However, in order to use Froala WYSIWYG HTML Editor plugin you should purchase a license for it.
26135

26236
Froala Editor has [3 different licenses](http://froala.com/wysiwyg-editor/pricing) for commercial use.
26337
For details please see [License Agreement](http://froala.com/wysiwyg-editor/terms).

bower.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
{
2-
"name": "froala-editor-node-sdk",
2+
"name": "wysiwyg-editor-node-sdk",
33
"version": "2.3.4-rc.1",
44
"author": "Florin Marius Popescu <[email protected]> (https://www.froala.com/)",
55
"description": "Node.js SDK for Froala Editor",
66
"keywords": [
77
"froala",
8-
"editor",
98
"node.js",
10-
"sdk"
9+
"sdk",
10+
"froala-editor",
11+
"froala-wysiwyg",
12+
"html",
13+
"text",
14+
"editor",
15+
"wysiwyg",
16+
"jquery-plugin",
17+
"rich editor",
18+
"rich text editor",
19+
"rte",
20+
"javascript",
21+
"jquery"
1122
],
12-
"license": "https://froala.com/wysiwyg-editor/terms/",
23+
"license": "MIT",
1324
"ignore": [
1425
"**/.*",
1526
"node_modules",

lib/image.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function upload(req, fileRoute, options, callback) {
5151
* @param callback returns null/undefined or error string
5252
*/
5353
var _delete = function(src, callback) {
54-
5554
diskManagement.delete(src, callback);
5655
}
5756

lib/s3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
/**
3+
* Get signature for S3.
34
*
45
* @params config:
56
* {
@@ -33,6 +34,7 @@ function getHash(config) {
3334

3435
// Check default region.
3536
config.region = config.region || 'us-east-1';
37+
config.region = config.region == 's3' ? 'us-east-1' : config.region;
3638

3739
var bucket = config.bucket;
3840
var region = config.region;
@@ -57,8 +59,6 @@ function getHash(config) {
5759
{acl: acl },
5860
{'success_action_status': '201'},
5961
{'x-requested-with': 'xhr'},
60-
// Optionally control content type and file size
61-
// {'Content-Type': 'application/pdf'},
6262
{'x-amz-algorithm': 'AWS4-HMAC-SHA256'},
6363
{'x-amz-credential': credential},
6464
{'x-amz-date': xAmzDate},

0 commit comments

Comments
 (0)