backend-manager 3.2.137 → 3.2.138
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/package.json
CHANGED
package/src/cli/cli.js
CHANGED
|
@@ -1284,7 +1284,7 @@ async function cmd_configSet(self, newPath, newValue) {
|
|
|
1284
1284
|
} catch (e) {
|
|
1285
1285
|
}
|
|
1286
1286
|
|
|
1287
|
-
const isObject = typeof object === 'object';
|
|
1287
|
+
const isObject = object && typeof object === 'object';
|
|
1288
1288
|
|
|
1289
1289
|
// If it's a string, ensure some things
|
|
1290
1290
|
if (!isObject) {
|
|
@@ -60,10 +60,16 @@ Module.prototype.main = function () {
|
|
|
60
60
|
|
|
61
61
|
// Fix required values
|
|
62
62
|
payload.data.payload.url = payload.data.payload.url
|
|
63
|
-
// Replace
|
|
63
|
+
// Replace blog/
|
|
64
64
|
.replace(/blog\//ig, '')
|
|
65
65
|
// Remove leading and trailing slashes
|
|
66
|
-
.replace(/^\/|\/$/g, '')
|
|
66
|
+
.replace(/^\/|\/$/g, '')
|
|
67
|
+
// Replace anything that's not a letter or number with a hyphen
|
|
68
|
+
.replace(/[^a-zA-Z0-9]/g, '-')
|
|
69
|
+
// Remove multiple hyphens
|
|
70
|
+
.replace(/-+/g, '-')
|
|
71
|
+
// Lowercase
|
|
72
|
+
.toLowerCase();
|
|
67
73
|
|
|
68
74
|
// Fix body
|
|
69
75
|
payload.data.payload.body = payload.data.payload.body
|
|
@@ -108,16 +108,29 @@ Module.prototype.harvest = function (settings) {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
// Log
|
|
111
|
-
assistant.log('Get final content', final);
|
|
111
|
+
assistant.log('harvest(): Get final content', final);
|
|
112
112
|
|
|
113
113
|
// Request to Ghostii
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
assistant.error(`harvest(): Error requesting Ghostii`,
|
|
114
|
+
const article = await self.requestGhostii(final).catch((e) => e);
|
|
115
|
+
if (article instanceof Error) {
|
|
116
|
+
assistant.error(`harvest(): Error requesting Ghostii`, article);
|
|
117
117
|
|
|
118
118
|
break;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
// Log
|
|
122
|
+
assistant.log(`harvest(): Article`, article);
|
|
123
|
+
|
|
124
|
+
// Upload post to blog
|
|
125
|
+
const uploadedPost = await self.uploadPost(article).catch((e) => e);
|
|
126
|
+
if (uploadedPost instanceof Error) {
|
|
127
|
+
assistant.error(`harvest(): Error uploading post to blog`, uploadedPost);
|
|
128
|
+
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Log
|
|
133
|
+
assistant.log(`harvest(): Uploaded post`, uploadedPost);
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
// Log
|
|
@@ -209,17 +222,71 @@ Module.prototype.requestGhostii = function (content) {
|
|
|
209
222
|
// Fetch URL
|
|
210
223
|
fetch('https://api.ghostii.ai/write/article', {
|
|
211
224
|
method: 'post',
|
|
212
|
-
timeout:
|
|
213
|
-
tries:
|
|
225
|
+
timeout: 90000,
|
|
226
|
+
tries: 1,
|
|
214
227
|
response: 'json',
|
|
215
228
|
body: {
|
|
229
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
216
230
|
keywords: [''],
|
|
217
231
|
description: content,
|
|
232
|
+
insertLinks: true,
|
|
218
233
|
},
|
|
219
234
|
})
|
|
220
|
-
.then((r) =>
|
|
221
|
-
|
|
235
|
+
.then((r) => resolve(r))
|
|
236
|
+
.catch((e) => reject(e));
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
Module.prototype.uploadPost = function (article) {
|
|
241
|
+
const self = this;
|
|
242
|
+
|
|
243
|
+
// Shortcuts
|
|
244
|
+
const Manager = self.Manager;
|
|
245
|
+
const libraries = self.libraries;
|
|
246
|
+
const assistant = self.assistant;
|
|
247
|
+
const context = self.context;
|
|
248
|
+
|
|
249
|
+
return new Promise(async function(resolve, reject) {
|
|
250
|
+
// request.body.command = 'admin:create-post';
|
|
251
|
+
// request.body.payload = {
|
|
252
|
+
// title: data.payload.postTitle,
|
|
253
|
+
// url: data.formatted.path,
|
|
254
|
+
// excerpt: data.payload.postExcerpt,
|
|
255
|
+
// headerImageURL: data.payload.postHeaderImageUrl,
|
|
256
|
+
// body: data.payload.postBody,
|
|
257
|
+
// id: self.postId++,
|
|
258
|
+
// author: 'alex',
|
|
259
|
+
// // affiliate: '',
|
|
260
|
+
// // tags: 'tag, tag2, tag3',
|
|
261
|
+
// // categories: 'marketing, business',
|
|
262
|
+
// githubUser: app.github.user,
|
|
263
|
+
// githubRepo: app.github.repo,
|
|
264
|
+
// }
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
// Fetch URL
|
|
268
|
+
fetch(`${self.appObject.server}/bm_api`, {
|
|
269
|
+
method: 'post',
|
|
270
|
+
timeout: 90000,
|
|
271
|
+
tries: 1,
|
|
272
|
+
response: 'json',
|
|
273
|
+
body: {
|
|
274
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
275
|
+
command: '',
|
|
276
|
+
payload: {
|
|
277
|
+
title: article.title,
|
|
278
|
+
url: article.title, // This is formatted on the bm_api endpoint
|
|
279
|
+
excerpt: article.description,
|
|
280
|
+
headerImageURL: article.headerImageUrl,
|
|
281
|
+
body: article.body,
|
|
282
|
+
id: self.postId++,
|
|
283
|
+
author: 'alex',
|
|
284
|
+
githubUser: self.appObject.github.user,
|
|
285
|
+
githubRepo: self.appObject.github.repo,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
222
288
|
})
|
|
289
|
+
.then((r) => resolve(r))
|
|
223
290
|
.catch((e) => reject(e));
|
|
224
291
|
});
|
|
225
292
|
}
|
package/src/manager/index.js
CHANGED
|
@@ -67,7 +67,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
67
67
|
options.uniqueAppName = options.uniqueAppName || undefined;
|
|
68
68
|
options.assistant = options.assistant || {};
|
|
69
69
|
options.cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd;
|
|
70
|
-
options.
|
|
70
|
+
options.projectPackageDirectory = typeof options.projectPackageDirectory === 'undefined' ? undefined : options.projectPackageDirectory;
|
|
71
71
|
// options.assistant.optionsLogString = options.assistant.optionsLogString || undefined;
|
|
72
72
|
|
|
73
73
|
// Load libraries
|
|
@@ -99,7 +99,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
99
99
|
self.project.backendManagerConfigPath = path.resolve(self.cwd, options.backendManagerConfigPath);
|
|
100
100
|
|
|
101
101
|
// Load package.json
|
|
102
|
-
self.package = resolveProjectPackage(options.
|
|
102
|
+
self.package = resolveProjectPackage(options.projectPackageDirectory || self.cwd);
|
|
103
103
|
|
|
104
104
|
// Load config
|
|
105
105
|
self.config = merge(
|
|
@@ -206,7 +206,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
206
206
|
if (self.options.initialize) {
|
|
207
207
|
// Initialize Firebase
|
|
208
208
|
try {
|
|
209
|
-
//
|
|
209
|
+
// Initialize Firebase
|
|
210
210
|
if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
211
211
|
self.libraries.initializedAdmin = self.libraries.admin.initializeApp();
|
|
212
212
|
} else {
|
|
@@ -254,9 +254,9 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
254
254
|
|
|
255
255
|
// Set dotenv
|
|
256
256
|
try {
|
|
257
|
-
require('dotenv').config();
|
|
257
|
+
const env = require('dotenv').config();
|
|
258
258
|
} catch (e) {
|
|
259
|
-
self.assistant.error(new Error(
|
|
259
|
+
self.assistant.error(new Error(`Failed to set up environment variables from .env file: ${e.message}`));
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
// Setup LocalDatabase
|
|
@@ -555,6 +555,19 @@ Manager.prototype.storage = function (options) {
|
|
|
555
555
|
return self._internal.storage[options.name]
|
|
556
556
|
};
|
|
557
557
|
|
|
558
|
+
Manager.prototype.getCustomServer = function () {
|
|
559
|
+
const self = this;
|
|
560
|
+
|
|
561
|
+
if (!self._internal.server || !self._internal.app) {
|
|
562
|
+
throw new Error('Server not set up');
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return {
|
|
566
|
+
server: self._internal.server,
|
|
567
|
+
app: self._internal.app,
|
|
568
|
+
};
|
|
569
|
+
};
|
|
570
|
+
|
|
558
571
|
Manager.prototype.install = function (controller, options) {
|
|
559
572
|
const self = this;
|
|
560
573
|
|
|
@@ -857,7 +870,7 @@ Manager.prototype.setupCustomServer = function (_library, options) {
|
|
|
857
870
|
// // querystringParser: str => querystring.parse(str.toLowerCase())
|
|
858
871
|
// });
|
|
859
872
|
|
|
860
|
-
//
|
|
873
|
+
// Setup express
|
|
861
874
|
const app = require('express')({
|
|
862
875
|
logger: true,
|
|
863
876
|
// querystringParser: str => querystring.parse(str.toLowerCase())
|
|
@@ -980,6 +993,10 @@ Manager.prototype.setupCustomServer = function (_library, options) {
|
|
|
980
993
|
self.assistant.log(`Server listening on ${address.address}:${address.port}`);
|
|
981
994
|
}
|
|
982
995
|
|
|
996
|
+
// Set server and app to internal
|
|
997
|
+
self._internal.server = server;
|
|
998
|
+
self._internal.app = app;
|
|
999
|
+
|
|
983
1000
|
// Emit event
|
|
984
1001
|
self.emit('online', new Event('online'), server, app);
|
|
985
1002
|
});
|