@peristyle/emdash-plugin-instagram-to-recipe 0.1.4 → 0.1.5

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  function instagramToRecipePlugin(options = {}) {
3
3
  return {
4
4
  id: "peristyle-instagram-to-recipe",
5
- version: "0.1.4",
5
+ version: "0.1.5",
6
6
  format: "standard",
7
7
  entrypoint: "@peristyle/emdash-plugin-instagram-to-recipe/sandbox",
8
8
  options,
@@ -60,6 +60,12 @@ declare const _default: {
60
60
  "plugin:install": {
61
61
  handler: (_event: unknown, ctx: PluginContext) => Promise<void>;
62
62
  };
63
+ "content:afterDelete": {
64
+ handler: (event: {
65
+ id: string;
66
+ collection: string;
67
+ }, ctx: PluginContext) => Promise<void>;
68
+ };
63
69
  };
64
70
  routes: {
65
71
  parse: {
@@ -1040,6 +1040,7 @@ var instagramBrowserUserAgent = BROWSER_UA2;
1040
1040
  var DEFAULT_COLLECTION = "posts";
1041
1041
  var PARSE_CACHE_PREFIX = "parse:";
1042
1042
  var IMPORT_MAP_PREFIX = "imported:";
1043
+ var IMPORT_BY_ID_PREFIX = "imported-by-id:";
1043
1044
  var PROFILE_CACHE_PREFIX = "igprofile:";
1044
1045
  var BULK_CREATE_DELAY_MS = 600;
1045
1046
  function sleep2(ms) {
@@ -1054,6 +1055,9 @@ function parseCacheKey(shortcode) {
1054
1055
  function importMapKey(shortcode) {
1055
1056
  return `${IMPORT_MAP_PREFIX}${shortcode}`;
1056
1057
  }
1058
+ function importByIdKey(contentId) {
1059
+ return `${IMPORT_BY_ID_PREFIX}${contentId}`;
1060
+ }
1057
1061
  async function httpFetch(ctx, url, init) {
1058
1062
  if (!ctx.http) {
1059
1063
  throw new Error("Network access is not available for this plugin.");
@@ -1188,6 +1192,7 @@ async function createDraftFromRecipe(ctx, shortcode) {
1188
1192
  const data = recipeToPostWriteData(recipe, featuredImage);
1189
1193
  const item = await ctx.content.create(collection, data);
1190
1194
  await ctx.kv.set(importMapKey(shortcode), item.id);
1195
+ await ctx.kv.set(importByIdKey(item.id), shortcode);
1191
1196
  return {
1192
1197
  contentId: item.id,
1193
1198
  title: recipe.title,
@@ -1270,6 +1275,19 @@ var sandbox_entry_default = {
1270
1275
  await ctx.kv.set("config:collection", DEFAULT_COLLECTION);
1271
1276
  }
1272
1277
  }
1278
+ },
1279
+ // Deleting an imported recipe post doesn't otherwise touch this plugin's
1280
+ // own "imported:<shortcode>" bookkeeping, so the bulk-scan UI keeps
1281
+ // treating the source Instagram post as already imported forever.
1282
+ "content:afterDelete": {
1283
+ handler: async (event, ctx) => {
1284
+ const collection = await collectionSlug(ctx);
1285
+ if (event.collection !== collection) return;
1286
+ const shortcode = await ctx.kv.get(importByIdKey(event.id));
1287
+ if (!shortcode) return;
1288
+ await ctx.kv.delete(importByIdKey(event.id));
1289
+ await ctx.kv.delete(importMapKey(shortcode));
1290
+ }
1273
1291
  }
1274
1292
  },
1275
1293
  routes: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peristyle/emdash-plugin-instagram-to-recipe",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Import Instagram post URLs as recipe drafts in the EmDash admin",
6
6
  "publishConfig": {
@@ -34,6 +34,7 @@ import { recipeToPostWriteData } from "./recipe-content.js";
34
34
  const DEFAULT_COLLECTION = "posts";
35
35
  const PARSE_CACHE_PREFIX = "parse:";
36
36
  const IMPORT_MAP_PREFIX = "imported:";
37
+ const IMPORT_BY_ID_PREFIX = "imported-by-id:";
37
38
  const PROFILE_CACHE_PREFIX = "igprofile:";
38
39
 
39
40
  /** Delay between draft creations so per-post image downloads stay polite. */
@@ -64,6 +65,10 @@ function importMapKey(shortcode: string): string {
64
65
  return `${IMPORT_MAP_PREFIX}${shortcode}`;
65
66
  }
66
67
 
68
+ function importByIdKey(contentId: string): string {
69
+ return `${IMPORT_BY_ID_PREFIX}${contentId}`;
70
+ }
71
+
67
72
  async function httpFetch(ctx: PluginContext, url: string, init?: RequestInit) {
68
73
  if (!ctx.http) {
69
74
  throw new Error("Network access is not available for this plugin.");
@@ -261,6 +266,7 @@ async function createDraftFromRecipe(
261
266
 
262
267
  const item = await ctx.content.create(collection, data);
263
268
  await ctx.kv.set(importMapKey(shortcode), item.id);
269
+ await ctx.kv.set(importByIdKey(item.id), shortcode);
264
270
 
265
271
  return {
266
272
  contentId: item.id,
@@ -397,6 +403,24 @@ export default {
397
403
  }
398
404
  },
399
405
  },
406
+ // Deleting an imported recipe post doesn't otherwise touch this plugin's
407
+ // own "imported:<shortcode>" bookkeeping, so the bulk-scan UI keeps
408
+ // treating the source Instagram post as already imported forever.
409
+ "content:afterDelete": {
410
+ handler: async (
411
+ event: { id: string; collection: string },
412
+ ctx: PluginContext,
413
+ ) => {
414
+ const collection = await collectionSlug(ctx);
415
+ if (event.collection !== collection) return;
416
+
417
+ const shortcode = await ctx.kv.get<string>(importByIdKey(event.id));
418
+ if (!shortcode) return;
419
+
420
+ await ctx.kv.delete(importByIdKey(event.id));
421
+ await ctx.kv.delete(importMapKey(shortcode));
422
+ },
423
+ },
400
424
  },
401
425
 
402
426
  routes: {