backend-manager 3.2.62 → 3.2.64
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.64",
|
|
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",
|
|
@@ -21,16 +21,23 @@ Module.prototype.main = function () {
|
|
|
21
21
|
return reject(assistant.errorify(`Admin required.`, {code: 401}));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// Get repo info
|
|
24
25
|
const repoInfo = assistant.parseRepo(get(self.Manager.config, 'github.repo_website'));
|
|
25
|
-
|
|
26
26
|
const poster = new Poster();
|
|
27
27
|
|
|
28
|
+
assistant.log(`main(): Creating post...`, repoInfo);
|
|
29
|
+
|
|
28
30
|
// Save to disk OR commit
|
|
29
31
|
poster.onDownload = function (meta) {
|
|
30
32
|
return new Promise(async function(resolve, reject) {
|
|
31
33
|
const tempPath = (meta.tempPath);
|
|
32
34
|
const finalPath = poster.removeDirDot(meta.finalPath);
|
|
33
35
|
|
|
36
|
+
// Log
|
|
37
|
+
assistant.log(`onDownload(): tempPath`, tempPath);
|
|
38
|
+
assistant.log(`onDownload(): finalPath`, finalPath);
|
|
39
|
+
|
|
40
|
+
// Save to disk
|
|
34
41
|
poster.readImage(tempPath)
|
|
35
42
|
.then(image => {
|
|
36
43
|
createFile(get(self.Manager.config, 'github.user'), repoInfo.user, repoInfo.name, get(self.Manager.config, 'github.key'), finalPath, image)
|
|
@@ -42,28 +49,34 @@ Module.prototype.main = function () {
|
|
|
42
49
|
});
|
|
43
50
|
}
|
|
44
51
|
|
|
52
|
+
// Create post
|
|
45
53
|
const finalPost = await poster.create(payload.data).catch(e => e);
|
|
46
|
-
|
|
47
54
|
if (finalPost instanceof Error) {
|
|
48
55
|
return reject(assistant.errorify(`Failed to post: ${finalPost}`, {code: 500}));
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
// Request indexing
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
// DEPRECATED
|
|
60
|
+
// try {
|
|
61
|
+
// const url = get(self.Manager.config, 'brand.url');
|
|
62
|
+
// const encoded = encodeURIComponent(`${url}/sitemap.xml`);
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
// wonderfulFetch(`https://www.google.com/ping?sitemap=${encoded}`)
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} catch (e) {
|
|
62
|
-
|
|
63
|
-
}
|
|
66
|
+
// // TODO
|
|
67
|
+
// // https://developers.google.com/search/apis/indexing-api/v3/prereqs
|
|
68
|
+
// // https://developers.google.com/search/apis/indexing-api/v3/using-api#url
|
|
69
|
+
// } catch (e) {
|
|
70
|
+
// assistant.error(`Failed to ping google: ${e}`);
|
|
71
|
+
// }
|
|
64
72
|
|
|
65
73
|
// Save post OR commit
|
|
66
|
-
|
|
74
|
+
const githubUser = get(self.Manager.config, 'github.user');
|
|
75
|
+
const githubKey = get(self.Manager.config, 'github.key');
|
|
76
|
+
const filePath = poster.removeDirDot(finalPost.path);
|
|
77
|
+
const fileContent = finalPost.content;
|
|
78
|
+
|
|
79
|
+
await createFile(githubUser, repoInfo.user, repoInfo.name, githubKey, filePath, fileContent)
|
|
67
80
|
.then(() => {
|
|
68
81
|
return resolve({data: finalPost});
|
|
69
82
|
})
|
|
@@ -76,19 +89,30 @@ Module.prototype.main = function () {
|
|
|
76
89
|
};
|
|
77
90
|
|
|
78
91
|
// HELPERS //
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
Module.prototype.createFile = function (user, repoUser, repoName, key, path, contents) {
|
|
93
|
+
const self = this;
|
|
94
|
+
const Manager = self.Manager;
|
|
95
|
+
const Api = self.Api;
|
|
96
|
+
const assistant = self.assistant;
|
|
97
|
+
const payload = self.payload;
|
|
81
98
|
|
|
82
|
-
let base64Data = Buffer.from(contents).toString('base64');
|
|
83
|
-
// base64Data = contents;
|
|
84
|
-
// console.log('--------base64Data', base64Data);
|
|
85
99
|
return new Promise(async (resolve, reject) => {
|
|
100
|
+
let fileParsed = pathApi.parse(path);
|
|
101
|
+
let base64Data = Buffer.from(contents).toString('base64');
|
|
86
102
|
let sha;
|
|
87
|
-
try {
|
|
88
103
|
|
|
89
|
-
|
|
104
|
+
// Log
|
|
105
|
+
assistant.log(`createFile(): Writing file to ${repoUser}/${repoName}/${path}`);
|
|
90
106
|
|
|
107
|
+
// Try to get sha
|
|
108
|
+
try {
|
|
109
|
+
let branch = repoName === 'ultimate-jekyll' ? 'template' : 'master';
|
|
91
110
|
let pathGet = `https://api.github.com/repos/${repoUser}/${repoName}/git/trees/${branch}:${encodeURIComponent(pathApi.dirname(path))}`;
|
|
111
|
+
|
|
112
|
+
// Log
|
|
113
|
+
assistant.log(`createFile(): pathGet`, pathGet);
|
|
114
|
+
|
|
115
|
+
// Make request
|
|
92
116
|
await makeRequest({
|
|
93
117
|
method: 'GET',
|
|
94
118
|
url: pathGet,
|
|
@@ -115,8 +139,7 @@ async function createFile(user, repoUser, repoName, key, path, contents) {
|
|
|
115
139
|
}
|
|
116
140
|
|
|
117
141
|
let pathPut = `https://api.github.com/repos/${repoUser}/${repoName}/contents/${path}`;
|
|
118
|
-
let writeRequest =
|
|
119
|
-
{
|
|
142
|
+
let writeRequest = {
|
|
120
143
|
// url: `https://api.github.com/repos/:owner/:repo/contents/:path`,
|
|
121
144
|
method: 'PUT',
|
|
122
145
|
url: pathPut,
|
|
@@ -132,10 +155,16 @@ async function createFile(user, repoUser, repoName, key, path, contents) {
|
|
|
132
155
|
'Authorization': `Basic ${Buffer.from(user + ':' + key).toString('base64')}`,
|
|
133
156
|
}
|
|
134
157
|
}
|
|
158
|
+
|
|
159
|
+
// Log
|
|
160
|
+
assistant.log(`createFile(): pathPut`, pathPut);
|
|
161
|
+
|
|
162
|
+
// Add sha if it exists
|
|
135
163
|
if (sha) {
|
|
136
164
|
writeRequest.body.sha = sha;
|
|
137
165
|
}
|
|
138
|
-
|
|
166
|
+
|
|
167
|
+
// Make request
|
|
139
168
|
await makeRequest(writeRequest)
|
|
140
169
|
.then((json) => {
|
|
141
170
|
if (!json || (json.message && (json.message === 'Not Found' || json.message.includes('Invalid request'))) ) {
|
|
@@ -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,17 +195,18 @@ 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;
|
|
199
203
|
options.format = typeof options.format === 'undefined' ? 'raw' : options.format;
|
|
200
204
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const item = self.cache.get(docPath).value();
|
|
205
|
+
// Check cache
|
|
206
|
+
const item = _.get(self.cache, docPath, null)
|
|
204
207
|
const age = item ? Date.now() - item.time : null;
|
|
205
208
|
|
|
209
|
+
// Format
|
|
206
210
|
function _format(doc) {
|
|
207
211
|
if (options.format === 'raw') {
|
|
208
212
|
return doc;
|
|
@@ -237,14 +241,15 @@ Utilities.prototype.get = function (docPath, options) {
|
|
|
237
241
|
.then(async (doc) => {
|
|
238
242
|
const data = doc.data();
|
|
239
243
|
|
|
244
|
+
// Set cache
|
|
240
245
|
if (data) {
|
|
241
|
-
self.cache
|
|
246
|
+
_.set(self.cache, docPath, {
|
|
242
247
|
doc: doc,
|
|
243
248
|
time: Date.now(),
|
|
244
249
|
})
|
|
245
|
-
.write();
|
|
246
250
|
}
|
|
247
251
|
|
|
252
|
+
// Return
|
|
248
253
|
return resolve(_format(doc));
|
|
249
254
|
})
|
|
250
255
|
.catch((e) => reject(e));
|