backend-manager 4.0.13 → 4.0.14

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": "4.0.13",
3
+ "version": "4.0.14",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -69,7 +69,7 @@
69
69
  "moment": "^2.30.1",
70
70
  "nanoid": "^3.3.7",
71
71
  "node-fetch": "^2.7.0",
72
- "node-powertools": "^1.5.9",
72
+ "node-powertools": "^1.6.0",
73
73
  "npm-api": "^1.0.1",
74
74
  "paypal-server-api": "^2.0.14",
75
75
  "pushid": "^1.0.0",
@@ -143,6 +143,7 @@ Module.prototype.extractImages = function () {
143
143
  src: match[2] || '',
144
144
  alt: match[1] || uuidv4(),
145
145
  replace: true,
146
+ header: false,
146
147
  }));
147
148
 
148
149
  // Add heading image to beginning of images
@@ -151,6 +152,7 @@ Module.prototype.extractImages = function () {
151
152
  src: payload.data.payload.headerImageURL,
152
153
  alt: payload.data.payload.url,
153
154
  replace: false,
155
+ header: true,
154
156
  });
155
157
 
156
158
  // Log
@@ -173,7 +175,14 @@ Module.prototype.extractImages = function () {
173
175
 
174
176
  // Check for error
175
177
  if (download instanceof Error) {
176
- return reject(download);
178
+ // If it's the header image, reject
179
+ // We can ignore body images since they are not critical and idiots usually fuck up the URLs
180
+ if (image.header) {
181
+ return reject(download);
182
+ } else {
183
+ assistant.warn(`extractImages(): Skipping NON-HEADER image download due to error`, download);
184
+ continue;
185
+ }
177
186
  }
178
187
 
179
188
  // Upload image
@@ -184,7 +193,14 @@ Module.prototype.extractImages = function () {
184
193
 
185
194
  // Check for error
186
195
  if (upload instanceof Error) {
187
- return reject(upload);
196
+ // If it's the header image, reject
197
+ // We can ignore body images since they are not critical and idiots usually fuck up the URLs
198
+ if (image.header) {
199
+ return reject(upload);
200
+ } else {
201
+ assistant.warn(`extractImages(): Skipping NON-HEADER image upload due to error`, upload);
202
+ continue;
203
+ }
188
204
  }
189
205
 
190
206
  // Create new image tag
@@ -257,16 +273,38 @@ Module.prototype.uploadImage = function (image) {
257
273
  const filepath = image.path;
258
274
  const filename = image.filename;
259
275
  const assetsPath = powertools.template(IMAGE_PATH_SRC, payload.data.payload);
276
+ const owner = payload.data.payload.githubUser;
277
+ const repo = payload.data.payload.githubRepo;
260
278
 
261
279
  // Log
262
280
  assistant.log(`uploadImage(): image`, image);
263
281
  assistant.log(`uploadImage(): path`, `${assetsPath}${filename}`);
264
282
 
283
+ // Get existing image
284
+ const existing = await self.octokit.rest.repos.getContent({
285
+ owner: owner,
286
+ repo: repo,
287
+ path: `${assetsPath}${filename}`,
288
+ })
289
+ .catch(e => e);
290
+
291
+ // Log
292
+ assistant.log(`uploadImage(): Existing`, existing);
293
+
294
+ // Quit if error and it's DIFFERENT than 404
295
+ if (
296
+ existing instanceof Error
297
+ && existing?.status !== 404
298
+ ) {
299
+ return reject(existing);
300
+ }
301
+
265
302
  // Upload image
266
303
  await self.octokit.rest.repos.createOrUpdateFileContents({
267
- owner: payload.data.payload.githubUser,
268
- repo: payload.data.payload.githubRepo,
304
+ owner: owner,
305
+ repo: repo,
269
306
  path: `${assetsPath}${filename}`,
307
+ sha: existing?.data?.sha || undefined,
270
308
  message: `📦 admin:create-post:upload-image ${filename}`,
271
309
  content: jetpack.read(filepath, 'buffer').toString('base64'),
272
310
  })
@@ -309,7 +347,7 @@ Module.prototype.uploadPost = function (content) {
309
347
  // Log
310
348
  assistant.log(`uploadPost(): Existing`, existing);
311
349
 
312
- // Quit if error and it's not a 404
350
+ // Quit if error and it's DIFFERENT than 404
313
351
  if (
314
352
  existing instanceof Error
315
353
  && existing?.status !== 404