backend-manager 3.2.153 → 3.2.154
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 +1 -1
- package/src/manager/functions/core/actions/api/admin/templates/post.html +1 -0
- package/src/manager/functions/core/cron/daily/ghostii-auto-publisher.js +24 -4
- package/src/manager/helpers/settings.js +7 -0
- package/src/manager/index.js +2 -2
- package/templates/backend-manager-config.json +1 -0
package/package.json
CHANGED
|
@@ -4,12 +4,20 @@ const powertools = require('node-powertools');
|
|
|
4
4
|
const moment = require('moment');
|
|
5
5
|
const JSON5 = require('json5');
|
|
6
6
|
|
|
7
|
+
// const PROMPT = `
|
|
8
|
+
// Company: {app.name}: {app.brand.description}
|
|
9
|
+
// Date: {date}
|
|
10
|
+
// Instructions: {prompt}
|
|
11
|
+
|
|
12
|
+
// Use the following information to find a topic related to our company:
|
|
13
|
+
// {suggestion}
|
|
14
|
+
// `
|
|
7
15
|
const PROMPT = `
|
|
8
16
|
Company: {app.name}: {app.brand.description}
|
|
9
17
|
Date: {date}
|
|
10
18
|
Instructions: {prompt}
|
|
11
19
|
|
|
12
|
-
Use the following information to find a topic
|
|
20
|
+
Use the following information to find a topic for our company blog (it can be about our company OR any topic that would be relevant to our website and business BUT not about a competitor):
|
|
13
21
|
{suggestion}
|
|
14
22
|
`
|
|
15
23
|
|
|
@@ -51,9 +59,10 @@ Module.prototype.main = function (assistant, context) {
|
|
|
51
59
|
|
|
52
60
|
// Fix settings
|
|
53
61
|
settings.articles = settings.articles || 0;
|
|
54
|
-
settings.sources = settings.sources || [];
|
|
55
|
-
settings.links = settings.links || [];
|
|
62
|
+
settings.sources = randomize(settings.sources || []);
|
|
63
|
+
settings.links = randomize(settings.links || []);
|
|
56
64
|
settings.prompt = settings.prompt || '';
|
|
65
|
+
settings.chance = settings.chance || 1.0;
|
|
57
66
|
settings.app = await self.getAppData(appId).catch((e) => e);
|
|
58
67
|
|
|
59
68
|
// Check for errors
|
|
@@ -73,6 +82,12 @@ Module.prototype.main = function (assistant, context) {
|
|
|
73
82
|
continue;
|
|
74
83
|
}
|
|
75
84
|
|
|
85
|
+
// Quit if the chance is not met
|
|
86
|
+
const chance = Math.random();
|
|
87
|
+
if (chance > settings.chance) {
|
|
88
|
+
assistant.log(`Quitting because the chance is not met (${chance} <= ${settings.chance})`);
|
|
89
|
+
}
|
|
90
|
+
|
|
76
91
|
// Harvest articles
|
|
77
92
|
const result = await self.harvest(settings).catch((e) => e);
|
|
78
93
|
if (result instanceof Error) {
|
|
@@ -320,7 +335,7 @@ const extractBodyContent = (text, contentType, url) => {
|
|
|
320
335
|
// Try JSON
|
|
321
336
|
if (parsed) {
|
|
322
337
|
// If it's from rss.app, extract the content
|
|
323
|
-
if (
|
|
338
|
+
if (parsed.items) {
|
|
324
339
|
return parsed.items.map((i) => `${i.title}: ${i.content_text}`).join('\n');
|
|
325
340
|
}
|
|
326
341
|
|
|
@@ -350,4 +365,9 @@ function tryParse(json) {
|
|
|
350
365
|
}
|
|
351
366
|
};
|
|
352
367
|
|
|
368
|
+
// Randomize array
|
|
369
|
+
function randomize(array) {
|
|
370
|
+
return array.sort(() => Math.random() - 0.5);
|
|
371
|
+
}
|
|
372
|
+
|
|
353
373
|
module.exports = Module;
|
|
@@ -46,6 +46,13 @@ Settings.prototype.resolve = function (assistant, schema, settings, options) {
|
|
|
46
46
|
// Resolve settings
|
|
47
47
|
self.settings = powertools.defaults(settings, schema);
|
|
48
48
|
|
|
49
|
+
// If schema is not an object, throw an error
|
|
50
|
+
if (!schema || typeof schema !== 'object') {
|
|
51
|
+
throw assistant.errorify(`Invalid schema provided`, {code: 400});
|
|
52
|
+
}
|
|
53
|
+
// console.log('---schema', schema);
|
|
54
|
+
// console.log('---self.settings', self.settings);
|
|
55
|
+
|
|
49
56
|
// Iterate each key and check for some things
|
|
50
57
|
processSchema(schema, (path, schemaNode) => {
|
|
51
58
|
const originalValue = _.get(settings, path);
|
package/src/manager/index.js
CHANGED
|
@@ -638,7 +638,7 @@ Manager.prototype.setupFunctions = function (exporter, options) {
|
|
|
638
638
|
// Setup functions
|
|
639
639
|
exporter.bm_api =
|
|
640
640
|
self.libraries.functions
|
|
641
|
-
.runWith({memory: '256MB', timeoutSeconds:
|
|
641
|
+
.runWith({memory: '256MB', timeoutSeconds: 60 * 5})
|
|
642
642
|
// TODO: Replace this with new API
|
|
643
643
|
.https.onRequest(async (req, res) => self._process((new (require(`${core}/actions/api.js`))()).init(self, { req: req, res: res, })));
|
|
644
644
|
|
|
@@ -849,7 +849,7 @@ Manager.prototype.setupFunctions = function (exporter, options) {
|
|
|
849
849
|
// Setup cron jobs
|
|
850
850
|
exporter.bm_cronDaily =
|
|
851
851
|
self.libraries.functions
|
|
852
|
-
.runWith({ memory: '256MB', timeoutSeconds:
|
|
852
|
+
.runWith({ memory: '256MB', timeoutSeconds: 60 * 5 })
|
|
853
853
|
.pubsub.schedule('every 24 hours')
|
|
854
854
|
.onRun(async (context) => self._process((new (require(`${core}/cron/daily.js`))()).init(self, { context: context, })));
|
|
855
855
|
};
|