|
1 |
| -# Node.js SDK for Froala Editor |
| 1 | +# Froala WYSIWYG Editor Node.JS SDK |
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 | ## Installation
|
6 | 6 |
|
7 | 7 | 1. Clone this repo or download the zip.
|
8 | 8 |
|
9 |
| -2. Run `npm install` |
| 9 | +2. Run `npm install`. |
10 | 10 |
|
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. |
12 | 12 |
|
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');` |
15 | 14 |
|
16 |
| -## Usage |
| 15 | +4. To run examples: |
| 16 | +* `npm start` to start a nodejs server form `examples` directory at `http://localhost:3000/` |
17 | 17 |
|
18 |
| -### Import lib |
| 18 | +## Import lib |
19 | 19 | ```javascript
|
20 | 20 | var FroalaEditor = require('path/to/lib/froalaEditor.js');
|
21 | 21 | ```
|
22 | 22 |
|
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 |
170 | 24 |
|
171 |
| -* `callback` function(err): |
| 25 | + * [Official documentation](https://www.froala.com/wysiwyg-editor/docs/sdks/nodejs) |
172 | 26 |
|
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). |
174 | 30 |
|
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 |
| -``` |
257 | 31 |
|
258 | 32 | ## License
|
259 | 33 |
|
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. |
261 | 35 |
|
262 | 36 | Froala Editor has [3 different licenses](http://froala.com/wysiwyg-editor/pricing) for commercial use.
|
263 | 37 | For details please see [License Agreement](http://froala.com/wysiwyg-editor/terms).
|
|
0 commit comments