backend-manager 3.2.145 → 3.2.147

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.2.145",
3
+ "version": "3.2.147",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -15,9 +15,9 @@ Module.prototype.main = function () {
15
15
  const payload = self.payload;
16
16
 
17
17
  return new Promise(async function(resolve, reject) {
18
- // If not dev, quit
19
- if (!assistant.isDevelopment()) {
20
- return reject(assistant.errorify(`This command is only available in development mode`, {code: 401}));
18
+ // Perform checks
19
+ if (!payload.user.roles.admin && assistant.isProduction()) {
20
+ return reject(assistant.errorify(`Admin required.`, {code: 401}));
21
21
  }
22
22
 
23
23
  // Check for required options
@@ -2,13 +2,14 @@
2
2
  const fetch = require('wonderful-fetch');
3
3
  const powertools = require('node-powertools');
4
4
  const moment = require('moment');
5
+ const JSON5 = require('json5');
5
6
 
6
7
  const PROMPT = `
7
8
  Company: {name}: {description}
8
- Current Date: {date}
9
+ Date: {date}
9
10
  Instructions: {prompt}
10
11
 
11
- Use the following information to find a topic related to our company description:
12
+ Use the following information to find a topic related to our company:
12
13
  {suggestion}
13
14
  `
14
15
  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';
@@ -111,6 +112,7 @@ Module.prototype.harvest = function (settings) {
111
112
  const final = powertools.template(PROMPT, {
112
113
  name: self.appObject.name,
113
114
  description: self.appObject.brand.description,
115
+ url: self.appObject.url,
114
116
  prompt: settings.prompt,
115
117
  date: date,
116
118
  suggestion: suggestion,
@@ -193,13 +195,16 @@ Module.prototype.getURLContent = function (url) {
193
195
  fetch(url, {
194
196
  timeout: 30000,
195
197
  tries: 3,
196
- response: 'text',
198
+ response: 'raw',
197
199
  headers: {
198
200
  'User-Agent': USER_AGENT,
199
201
  }
200
202
  })
201
- .then((r) => {
202
- return resolve(extractBodyContent(r));
203
+ .then(async (r) => {
204
+ const contentType = res.headers.get('content-type');
205
+ const text = await res.text();
206
+
207
+ return resolve(extractBodyContent(text, contentType, url));
203
208
  })
204
209
  .catch((e) => reject(e));
205
210
  });
@@ -244,6 +249,7 @@ Module.prototype.requestGhostii = function (content) {
244
249
  description: content,
245
250
  insertLinks: true,
246
251
  headerImageUrl: 'unsplash',
252
+ url: self.appObject.url,
247
253
  },
248
254
  })
249
255
  .then((r) => resolve(r))
@@ -289,9 +295,22 @@ Module.prototype.uploadPost = function (article) {
289
295
  });
290
296
  }
291
297
 
292
- const extractBodyContent = (html) => {
298
+ const extractBodyContent = (text, contentType, url) => {
299
+ const parsed = tryParse(text);
300
+
301
+ // Try JSON
302
+ if (parsed) {
303
+ // If it's from rss.app, extract the content
304
+ if (url.includes('rss.app') && parsed.items) {
305
+ return parsed.items.map((i) => `${i.title}: ${i.content_text}`).join('\n');
306
+ }
307
+
308
+ // If we cant recognize the JSON, return the original text
309
+ return text;
310
+ }
311
+
293
312
  // Extract the content within the body tag
294
- const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
313
+ const bodyMatch = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
295
314
  if (!bodyMatch) return '';
296
315
 
297
316
  let bodyContent = bodyMatch[1];
@@ -304,4 +323,12 @@ const extractBodyContent = (html) => {
304
323
  return bodyContent.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
305
324
  };
306
325
 
326
+ function tryParse(json) {
327
+ try {
328
+ return JSON5.parse(json);
329
+ } catch (e) {
330
+ return null;
331
+ }
332
+ };
333
+
307
334
  module.exports = Module;