-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathimages.js
45 lines (40 loc) · 1.07 KB
/
images.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint object-shorthand: 0 */
import Image from '../models/image';
import ErrorMessage from '../views/error-message';
/**
* Collection to hold all of our Image models.
*
* This has the functionality to make an API request.
*/
const Images = Backbone.Collection.extend( {
model: Image,
url: wpApiSettings.root + classifaiDalleData.endpoint,
/**
* Send a request to our API endpoint.
*
* @param {string} prompt Prompt used in generating images.
* @param {string} quality Quality of the image.
* @param {string} size Size of the image.
* @param {string} style Style of the image.
*/
makeRequest: function ( prompt, quality, size, style ) {
this.fetch( {
type: 'get',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce );
},
data: {
prompt: prompt,
quality: quality,
size: size,
style: style,
format: 'b64_json',
},
reset: true,
error: function ( collection, response ) {
new ErrorMessage( { error: response.responseJSON.message } );
},
} );
},
} );
export default Images;