backend-manager 3.2.147 → 3.2.148
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
|
@@ -5,13 +5,14 @@ const moment = require('moment');
|
|
|
5
5
|
const JSON5 = require('json5');
|
|
6
6
|
|
|
7
7
|
const PROMPT = `
|
|
8
|
-
Company: {name}: {description}
|
|
8
|
+
Company: {app.name}: {app.brand.description}
|
|
9
9
|
Date: {date}
|
|
10
10
|
Instructions: {prompt}
|
|
11
11
|
|
|
12
12
|
Use the following information to find a topic related to our company:
|
|
13
13
|
{suggestion}
|
|
14
14
|
`
|
|
15
|
+
|
|
15
16
|
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36';
|
|
16
17
|
|
|
17
18
|
function Module() {
|
|
@@ -29,24 +30,11 @@ Module.prototype.main = function (assistant, context) {
|
|
|
29
30
|
// Log
|
|
30
31
|
assistant.log(`Starting...`);
|
|
31
32
|
|
|
32
|
-
// Get settings
|
|
33
|
-
const settings = Manager.config.ghostii;
|
|
34
|
-
|
|
35
33
|
// Set post ID
|
|
36
34
|
self.postId = moment().unix();
|
|
37
35
|
|
|
38
|
-
// Log
|
|
39
|
-
assistant.log(`Settings`, settings);
|
|
40
|
-
|
|
41
|
-
// Quit if articles are disabled
|
|
42
|
-
if (!settings.articles || !settings.sources.length) {
|
|
43
|
-
assistant.log(`Quitting because articles are disabled`);
|
|
44
|
-
|
|
45
|
-
return resolve();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
36
|
// Get app content
|
|
49
|
-
self.appObject = await self.getAppData().catch((e) => e);
|
|
37
|
+
self.appObject = await self.getAppData(Manager.config.app.id).catch((e) => e);
|
|
50
38
|
if (self.appObject instanceof Error) {
|
|
51
39
|
return reject(self.appObject);
|
|
52
40
|
}
|
|
@@ -54,14 +42,45 @@ Module.prototype.main = function (assistant, context) {
|
|
|
54
42
|
// Log
|
|
55
43
|
assistant.log(`App object`, self.appObject);
|
|
56
44
|
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
if (result instanceof Error) {
|
|
60
|
-
return reject(result);
|
|
61
|
-
}
|
|
45
|
+
// Get settings
|
|
46
|
+
let settingsArray = powertools.arrayify(Manager.config.ghostii);
|
|
62
47
|
|
|
63
|
-
//
|
|
64
|
-
|
|
48
|
+
// Loop through each item
|
|
49
|
+
for (const settings of settingsArray) {
|
|
50
|
+
const appId = settings.app || self.appObject.id;
|
|
51
|
+
|
|
52
|
+
// Fix settings
|
|
53
|
+
settings.articles = settings.articles || 0;
|
|
54
|
+
settings.sources = settings.sources || [];
|
|
55
|
+
settings.prompt = settings.prompt || '';
|
|
56
|
+
settings.app = await self.getAppData(appId).catch((e) => e);
|
|
57
|
+
|
|
58
|
+
// Check for errors
|
|
59
|
+
if (settings.app instanceof Error) {
|
|
60
|
+
assistant.error(`Error fetching app data`, settings.app);
|
|
61
|
+
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Log
|
|
66
|
+
assistant.log(`Settings (app=${appId})`, settings);
|
|
67
|
+
|
|
68
|
+
// Quit if articles are disabled
|
|
69
|
+
if (!settings.articles || !settings.sources.length) {
|
|
70
|
+
assistant.log(`Quitting because articles are disabled`);
|
|
71
|
+
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Harvest articles
|
|
76
|
+
const result = await self.harvest(settings).catch((e) => e);
|
|
77
|
+
if (result instanceof Error) {
|
|
78
|
+
return reject(result);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Log
|
|
82
|
+
assistant.log(`Finished!`, result);
|
|
83
|
+
}
|
|
65
84
|
|
|
66
85
|
// Resolve
|
|
67
86
|
return resolve();
|
|
@@ -81,7 +100,7 @@ Module.prototype.harvest = function (settings) {
|
|
|
81
100
|
const date = moment().format('MMMM YYYY');
|
|
82
101
|
|
|
83
102
|
// Log
|
|
84
|
-
assistant.log(`harvest(): Starting...`);
|
|
103
|
+
assistant.log(`harvest(): Starting ${settings.app.id}...`);
|
|
85
104
|
|
|
86
105
|
// Process the number of sources in the settings
|
|
87
106
|
for (let index = 0; index < settings.articles; index++) {
|
|
@@ -110,9 +129,7 @@ Module.prototype.harvest = function (settings) {
|
|
|
110
129
|
|
|
111
130
|
// Set suggestion
|
|
112
131
|
const final = powertools.template(PROMPT, {
|
|
113
|
-
|
|
114
|
-
description: self.appObject.brand.description,
|
|
115
|
-
url: self.appObject.url,
|
|
132
|
+
...settings,
|
|
116
133
|
prompt: settings.prompt,
|
|
117
134
|
date: date,
|
|
118
135
|
suggestion: suggestion,
|
|
@@ -122,7 +139,7 @@ Module.prototype.harvest = function (settings) {
|
|
|
122
139
|
assistant.log('harvest(): Get final content', final);
|
|
123
140
|
|
|
124
141
|
// Request to Ghostii
|
|
125
|
-
const article = await self.requestGhostii(final).catch((e) => e);
|
|
142
|
+
const article = await self.requestGhostii(settings, final).catch((e) => e);
|
|
126
143
|
if (article instanceof Error) {
|
|
127
144
|
assistant.error(`harvest(): Error requesting Ghostii`, article);
|
|
128
145
|
|
|
@@ -133,7 +150,7 @@ Module.prototype.harvest = function (settings) {
|
|
|
133
150
|
assistant.log(`harvest(): Article`, article);
|
|
134
151
|
|
|
135
152
|
// Upload post to blog
|
|
136
|
-
const uploadedPost = await self.uploadPost(article).catch((e) => e);
|
|
153
|
+
const uploadedPost = await self.uploadPost(settings, article).catch((e) => e);
|
|
137
154
|
if (uploadedPost instanceof Error) {
|
|
138
155
|
assistant.error(`harvest(): Error uploading post to blog`, uploadedPost);
|
|
139
156
|
|
|
@@ -149,7 +166,7 @@ Module.prototype.harvest = function (settings) {
|
|
|
149
166
|
});
|
|
150
167
|
}
|
|
151
168
|
|
|
152
|
-
Module.prototype.getAppData = function (
|
|
169
|
+
Module.prototype.getAppData = function (id) {
|
|
153
170
|
const self = this;
|
|
154
171
|
|
|
155
172
|
// Shortcuts
|
|
@@ -166,16 +183,9 @@ Module.prototype.getAppData = function (settings) {
|
|
|
166
183
|
tries: 3,
|
|
167
184
|
response: 'json',
|
|
168
185
|
body: {
|
|
169
|
-
id:
|
|
186
|
+
id: id,
|
|
170
187
|
},
|
|
171
188
|
})
|
|
172
|
-
// .then((r) => {
|
|
173
|
-
// return resolve({
|
|
174
|
-
// name: r?.name,
|
|
175
|
-
// description: r?.brand?.description || '',
|
|
176
|
-
// acceptable: r?.sponsorships?.acceptable || [],
|
|
177
|
-
// })
|
|
178
|
-
// })
|
|
179
189
|
.then((r) => resolve(r))
|
|
180
190
|
.catch((e) => reject(e));
|
|
181
191
|
});
|
|
@@ -227,7 +237,7 @@ Module.prototype.isURL = function (url) {
|
|
|
227
237
|
}
|
|
228
238
|
|
|
229
239
|
// Request to Ghostii
|
|
230
|
-
Module.prototype.requestGhostii = function (content) {
|
|
240
|
+
Module.prototype.requestGhostii = function (settings, content) {
|
|
231
241
|
const self = this;
|
|
232
242
|
|
|
233
243
|
// Shortcuts
|
|
@@ -249,7 +259,8 @@ Module.prototype.requestGhostii = function (content) {
|
|
|
249
259
|
description: content,
|
|
250
260
|
insertLinks: true,
|
|
251
261
|
headerImageUrl: 'unsplash',
|
|
252
|
-
url:
|
|
262
|
+
url: settings.app.url,
|
|
263
|
+
feedUrl: `${settings.app.url}/feeds/posts.json`,
|
|
253
264
|
},
|
|
254
265
|
})
|
|
255
266
|
.then((r) => resolve(r))
|
|
@@ -257,7 +268,7 @@ Module.prototype.requestGhostii = function (content) {
|
|
|
257
268
|
});
|
|
258
269
|
}
|
|
259
270
|
|
|
260
|
-
Module.prototype.uploadPost = function (article) {
|
|
271
|
+
Module.prototype.uploadPost = function (settings, article) {
|
|
261
272
|
const self = this;
|
|
262
273
|
|
|
263
274
|
// Shortcuts
|
|
@@ -268,7 +279,7 @@ Module.prototype.uploadPost = function (article) {
|
|
|
268
279
|
|
|
269
280
|
return new Promise(async function(resolve, reject) {
|
|
270
281
|
// Fetch URL
|
|
271
|
-
fetch(`${
|
|
282
|
+
fetch(`${settings.app.server}/bm_api`, {
|
|
272
283
|
method: 'post',
|
|
273
284
|
timeout: 90000,
|
|
274
285
|
tries: 1,
|
|
@@ -285,8 +296,8 @@ Module.prototype.uploadPost = function (article) {
|
|
|
285
296
|
id: self.postId++,
|
|
286
297
|
author: 'alex',
|
|
287
298
|
path: 'ghostii',
|
|
288
|
-
githubUser:
|
|
289
|
-
githubRepo:
|
|
299
|
+
githubUser: settings.app.github.user,
|
|
300
|
+
githubRepo: settings.app.github.repo,
|
|
290
301
|
},
|
|
291
302
|
},
|
|
292
303
|
})
|
|
@@ -33,12 +33,14 @@
|
|
|
33
33
|
appId: '1:123:web:456',
|
|
34
34
|
measurementId: 'G-0123456789',
|
|
35
35
|
},
|
|
36
|
-
ghostii:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
ghostii: [
|
|
37
|
+
{
|
|
38
|
+
articles: 1,
|
|
39
|
+
sources: [
|
|
40
|
+
'$app',
|
|
41
|
+
// Add more sources here
|
|
42
|
+
],
|
|
43
|
+
prompt: '',
|
|
44
|
+
}
|
|
45
|
+
],
|
|
44
46
|
}
|