@tryghost/admin-api 1.4.5 → 1.7.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.
- package/lib/index.js +45 -22
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -202,29 +202,52 @@ module.exports = function GhostAdminAPI(options) {
|
|
|
202
202
|
if (data.file) {
|
|
203
203
|
formData = new FormData();
|
|
204
204
|
formData.append('file', fs.createReadStream(data.file));
|
|
205
|
+
// NOTE: this default "image" doesn't work for all upload endpoints. Should be moved from here and required as
|
|
206
|
+
// an explicit method parameter. Leaving it here for now as I'm focusing on a different problem.
|
|
205
207
|
formData.append('purpose', data.purpose || 'image');
|
|
206
208
|
|
|
207
209
|
if (data.ref) {
|
|
208
210
|
formData.append('ref', data.ref);
|
|
209
211
|
}
|
|
210
212
|
|
|
213
|
+
if (data.thumbnail) {
|
|
214
|
+
formData.append('thumbnail', fs.createReadStream(data.thumbnail));
|
|
215
|
+
}
|
|
216
|
+
|
|
211
217
|
return formData;
|
|
212
218
|
}
|
|
213
219
|
}
|
|
214
220
|
|
|
215
221
|
api.images = {
|
|
216
222
|
upload(data) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (!isValidUpload(data)) {
|
|
222
|
-
return Promise.reject(new Error('Must be of FormData or include path'));
|
|
223
|
-
}
|
|
223
|
+
return makeUploadRequest('images', data, endpointFor('images/upload'));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
224
226
|
|
|
225
|
-
|
|
227
|
+
api.media = {
|
|
228
|
+
/**
|
|
229
|
+
*
|
|
230
|
+
* @param {Object} data
|
|
231
|
+
* @param {String} data.file - file path to a media file
|
|
232
|
+
* @param {String} [data.thumbnail] - file path to a thumbnail file
|
|
233
|
+
* @param {String} [data.purpose]
|
|
234
|
+
* @returns Promise<Object>
|
|
235
|
+
*/
|
|
236
|
+
upload(data) {
|
|
237
|
+
return makeUploadRequest('media', data, endpointFor('media/upload'));
|
|
238
|
+
}
|
|
239
|
+
};
|
|
226
240
|
|
|
227
|
-
|
|
241
|
+
api.files = {
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
* @param {Object} data
|
|
245
|
+
* @param {String} data.file - file path to a media file
|
|
246
|
+
* @param {String} [data.ref] - reference field returned in the response
|
|
247
|
+
* @returns Promise<Object>
|
|
248
|
+
*/
|
|
249
|
+
upload(data) {
|
|
250
|
+
return makeUploadRequest('files', data, endpointFor('files/upload'));
|
|
228
251
|
}
|
|
229
252
|
};
|
|
230
253
|
|
|
@@ -242,17 +265,7 @@ module.exports = function GhostAdminAPI(options) {
|
|
|
242
265
|
|
|
243
266
|
api.themes = {
|
|
244
267
|
upload(data) {
|
|
245
|
-
|
|
246
|
-
return Promise.reject(new Error('Missing data'));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (!isValidUpload(data)) {
|
|
250
|
-
return Promise.reject(new Error('Must be of FormData or include path'));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
let formData = getFormData(data);
|
|
254
|
-
|
|
255
|
-
return makeUploadRequest('themes', formData, endpointFor('themes/upload'));
|
|
268
|
+
return makeUploadRequest('themes', data, endpointFor('themes/upload'));
|
|
256
269
|
},
|
|
257
270
|
activate(name) {
|
|
258
271
|
if (!name) {
|
|
@@ -266,14 +279,24 @@ module.exports = function GhostAdminAPI(options) {
|
|
|
266
279
|
return api;
|
|
267
280
|
|
|
268
281
|
function makeUploadRequest(resourceType, data, endpoint) {
|
|
282
|
+
if (!data) {
|
|
283
|
+
return Promise.reject(new Error('Missing data'));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (!isValidUpload(data)) {
|
|
287
|
+
return Promise.reject(new Error('Must be of FormData or include path'));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let formData = getFormData(data);
|
|
291
|
+
|
|
269
292
|
const headers = {
|
|
270
|
-
'Content-Type': `multipart/form-data; boundary=${
|
|
293
|
+
'Content-Type': `multipart/form-data; boundary=${formData._boundary}`
|
|
271
294
|
};
|
|
272
295
|
|
|
273
296
|
return makeApiRequest({
|
|
274
297
|
endpoint: endpoint,
|
|
275
298
|
method: 'POST',
|
|
276
|
-
body:
|
|
299
|
+
body: formData,
|
|
277
300
|
headers
|
|
278
301
|
}).then((apiData) => {
|
|
279
302
|
if (!Array.isArray(apiData[resourceType])) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/admin-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/SDK/tree/master/packages/admin-api",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"dev": "echo \"Implement me!\"",
|
|
16
|
-
"test": "NODE_ENV=testing c8 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
16
|
+
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
17
17
|
"lint": "eslint . --ext .js --cache",
|
|
18
18
|
"posttest": "yarn lint"
|
|
19
19
|
},
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"axios": "^0.21.1",
|
|
31
|
-
"form-data": "^
|
|
31
|
+
"form-data": "^4.0.0",
|
|
32
32
|
"jsonwebtoken": "^8.4.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "bb3a33a1ff85c0d3efb2972e8d6dd72df458c271"
|
|
35
35
|
}
|