backend-manager 3.2.61 → 3.2.63
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.
|
|
3
|
+
"version": "3.2.63",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"busboy": "^1.6.0",
|
|
42
42
|
"chalk": "^4.1.2",
|
|
43
43
|
"cors": "^2.8.5",
|
|
44
|
-
"dotenv": "^16.4.
|
|
44
|
+
"dotenv": "^16.4.5",
|
|
45
45
|
"firebase-admin": "^11.11.1",
|
|
46
46
|
"firebase-functions": "^4.7.0",
|
|
47
47
|
"fs-jetpack": "^5.1.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"shortid": "^2.2.16",
|
|
66
66
|
"sizeitup": "^1.0.7",
|
|
67
67
|
"uid-generator": "^2.0.0",
|
|
68
|
-
"ultimate-jekyll-poster": "^0.0
|
|
68
|
+
"ultimate-jekyll-poster": "^1.0.0",
|
|
69
69
|
"uuid": "^9.0.1",
|
|
70
70
|
"wonderful-fetch": "^1.1.1",
|
|
71
71
|
"wonderful-log": "^1.0.5",
|
|
@@ -49,18 +49,19 @@ Module.prototype.main = function () {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// Request indexing
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
52
|
+
// DEPRECATED
|
|
53
|
+
// try {
|
|
54
|
+
// const url = get(self.Manager.config, 'brand.url');
|
|
55
|
+
// const encoded = encodeURIComponent(`${url}/sitemap.xml`);
|
|
56
|
+
|
|
57
|
+
// wonderfulFetch(`https://www.google.com/ping?sitemap=${encoded}`)
|
|
58
|
+
|
|
59
|
+
// // TODO
|
|
60
|
+
// // https://developers.google.com/search/apis/indexing-api/v3/prereqs
|
|
61
|
+
// // https://developers.google.com/search/apis/indexing-api/v3/using-api#url
|
|
62
|
+
// } catch (e) {
|
|
63
|
+
// assistant.error(`Failed to ping google: ${e}`);
|
|
64
|
+
// }
|
|
64
65
|
|
|
65
66
|
// Save post OR commit
|
|
66
67
|
await createFile(get(self.Manager.config, 'github.user'), repoInfo.user, repoInfo.name, get(self.Manager.config, 'github.key'), poster.removeDirDot(finalPost.path), finalPost.content)
|
|
@@ -168,7 +168,7 @@ Module.prototype.clearFirestore = function() {
|
|
|
168
168
|
// Clear temporary/usage in firestore by deleting the doc
|
|
169
169
|
admin.firestore().collection('temporary').listDocuments()
|
|
170
170
|
.then((snap) => {
|
|
171
|
-
const chunks = []
|
|
171
|
+
const chunks = [];
|
|
172
172
|
for (let i = 0; i < snap.length; i += 500) {
|
|
173
173
|
chunks.push(snap.slice(i, i + 500))
|
|
174
174
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
let nanoId;
|
|
2
|
+
let _;
|
|
2
3
|
|
|
3
4
|
function Utilities(Manager) {
|
|
4
5
|
const self = this;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
_ = require('lodash');
|
|
8
|
+
|
|
9
|
+
self.cache = {};
|
|
7
10
|
|
|
8
11
|
self.Manager = Manager;
|
|
9
12
|
}
|
|
@@ -192,53 +195,64 @@ Utilities.prototype.get = function (docPath, options) {
|
|
|
192
195
|
const Manager = self.Manager;
|
|
193
196
|
const { admin } = Manager.libraries;
|
|
194
197
|
|
|
198
|
+
// Set defaults
|
|
195
199
|
options = options || {};
|
|
196
200
|
options.maxAge = options.maxAge || (1000 * 60 * 5); // 5 minutes
|
|
197
201
|
options.readTime = typeof options.readTime === 'undefined' ? null : options.readTime;
|
|
198
202
|
options.log = typeof options.log === 'undefined' ? false : options.log;
|
|
203
|
+
options.format = typeof options.format === 'undefined' ? 'raw' : options.format;
|
|
199
204
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const item = self.cache.get(docPath).value();
|
|
205
|
+
// Check cache
|
|
206
|
+
const item = _.get(self.cache, docPath, null)
|
|
203
207
|
const age = item ? Date.now() - item.time : null;
|
|
204
208
|
|
|
209
|
+
// Format
|
|
210
|
+
function _format(doc) {
|
|
211
|
+
if (options.format === 'raw') {
|
|
212
|
+
return doc;
|
|
213
|
+
} else if (options.format === 'data') {
|
|
214
|
+
return doc.data();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Log
|
|
205
219
|
if (options.readTime) {
|
|
206
220
|
const { Timestamp } = require('firebase-admin/firestore')
|
|
207
221
|
const time = Math.round(new Date(options.readTime).getTime() / 1000 / 60);
|
|
208
|
-
const
|
|
222
|
+
const timeLog = new Date(time * 1000 * 60);
|
|
209
223
|
|
|
224
|
+
// Log
|
|
210
225
|
if (options.log) {
|
|
211
|
-
console.log('Read time:',
|
|
226
|
+
console.log('Read time:', timeLog);
|
|
212
227
|
}
|
|
213
228
|
|
|
214
|
-
//
|
|
229
|
+
// Loop docs
|
|
215
230
|
admin.firestore().runTransaction(
|
|
216
231
|
updateFunction => updateFunction.get(admin.firestore().doc(docPath)),
|
|
217
232
|
{readOnly: true, readTime: new Timestamp(time * 60, 0)}
|
|
218
233
|
)
|
|
219
|
-
.then(snap =>
|
|
220
|
-
|
|
221
|
-
})
|
|
222
|
-
.catch(e => reject(e));
|
|
234
|
+
.then((snap) => resolve(_format(snap)))
|
|
235
|
+
.catch((e) => reject(e));
|
|
223
236
|
} else if (item && age && age < options.maxAge) {
|
|
224
|
-
return resolve(item.doc);
|
|
237
|
+
return resolve(_format(item.doc));
|
|
225
238
|
} else {
|
|
226
239
|
admin.firestore().doc(docPath)
|
|
227
240
|
.get()
|
|
228
241
|
.then(async (doc) => {
|
|
229
242
|
const data = doc.data();
|
|
230
243
|
|
|
244
|
+
// Set cache
|
|
231
245
|
if (data) {
|
|
232
|
-
self.cache
|
|
246
|
+
_.set(self.cache, docPath, {
|
|
233
247
|
doc: doc,
|
|
234
248
|
time: Date.now(),
|
|
235
249
|
})
|
|
236
|
-
.write();
|
|
237
250
|
}
|
|
238
251
|
|
|
239
|
-
|
|
252
|
+
// Return
|
|
253
|
+
return resolve(_format(doc));
|
|
240
254
|
})
|
|
241
|
-
.catch(e => reject(e));
|
|
255
|
+
.catch((e) => reject(e));
|
|
242
256
|
}
|
|
243
257
|
});
|
|
244
258
|
};
|