podverse-parser 5.1.6-alpha.4 → 5.1.7-alpha.1

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import './module-alias-config';
2
2
  export { parseChapters } from './lib/chapters/chapters';
3
- export { parseRSSFeedAndSaveToDatabase, ParseRSSFeedAndSaveToDatabase } from './lib/rss/parser';
3
+ export { parseRSSFeedAndSaveToDatabase, ParseRSSFeedAndSaveToDatabaseOptions } from './lib/rss/parser';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,oCAAoC,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,7 +1,14 @@
1
+ import { OnDemandParserEventType } from 'podverse-helpers';
1
2
  import { FeedObject } from 'podcast-partytime';
2
3
  export declare const getAndParseRSSFeed: (url: string) => Promise<FeedObject>;
3
- export type ParseRSSFeedAndSaveToDatabase = {
4
- forceParse?: boolean;
4
+ export type ParseRSSOnDemandParserEvent = {
5
+ accountId: number | null;
6
+ remoteParentPodcastIndexId: number | null;
7
+ type: OnDemandParserEventType | null;
5
8
  };
6
- export declare const parseRSSFeedAndSaveToDatabase: (url: string, podcast_index_id: number, options: ParseRSSFeedAndSaveToDatabase) => Promise<void>;
9
+ export type ParseRSSFeedAndSaveToDatabaseOptions = {
10
+ forceParse: boolean;
11
+ onDemandParserEvent: ParseRSSOnDemandParserEvent;
12
+ };
13
+ export declare const parseRSSFeedAndSaveToDatabase: (url: string, podcast_index_id: number, options: ParseRSSFeedAndSaveToDatabaseOptions) => Promise<void>;
7
14
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/lib/rss/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,mBAAmB,CAAC;AAuB1D,eAAO,MAAM,kBAAkB,GAAU,KAAK,MAAM,wBAUnD,CAAC;AAQF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,KAAK,MAAM,EACX,kBAAkB,MAAM,EACxB,SAAS,6BAA6B,kBAgGvC,CAAC"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/lib/rss/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAIxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAa,MAAM,mBAAmB,CAAC;AAgC1D,eAAO,MAAM,kBAAkB,GAAU,KAAK,MAAM,wBAUnD,CAAC;AAQF,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0BAA0B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAAC;CACtC,CAAA;AAED,MAAM,MAAM,oCAAoC,GAAG;IACjD,UAAU,EAAE,OAAO,CAAC;IACpB,mBAAmB,EAAE,2BAA2B,CAAC;CAClD,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,KAAK,MAAM,EACX,kBAAkB,MAAM,EACxB,SAAS,oCAAoC,kBAuI9C,CAAC"}
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.parseRSSFeedAndSaveToDatabase = exports.getAndParseRSSFeed = void 0;
13
+ const podverse_helpers_1 = require("podverse-helpers");
13
14
  const podcast_partytime_1 = require("podcast-partytime");
14
15
  const podverse_orm_1 = require("podverse-orm");
15
16
  // import { handleNewItemsNotifications, handleNewLiveItemsNotifications } from '@parser/lib/notifications';
@@ -41,6 +42,25 @@ const getAndParseRSSFeed = (url) => __awaiter(void 0, void 0, void 0, function*
41
42
  });
42
43
  exports.getAndParseRSSFeed = getAndParseRSSFeed;
43
44
  const parseRSSFeedAndSaveToDatabase = (url, podcast_index_id, options) => __awaiter(void 0, void 0, void 0, function* () {
45
+ const { onDemandParserEvent } = options;
46
+ const onDemandParserEventService = new podverse_orm_1.OnDemandParserEventService();
47
+ if (onDemandParserEvent) {
48
+ const { accountId, type } = onDemandParserEvent;
49
+ if (accountId && type) {
50
+ if (type === podverse_helpers_1.OnDemandParserEventType.ADD) {
51
+ const count = yield onDemandParserEventService.getCountByAccountIdAndTypeSince(accountId, podverse_helpers_1.OnDemandParserEventType.ADD, (0, podverse_helpers_1.getOnDemandParserEventDateRange)());
52
+ if (count >= podverse_helpers_1.ON_DEMAND_ADD_PARSER_LIMIT) {
53
+ throw new Error('Monthly on-demand add feed parser limit reached');
54
+ }
55
+ }
56
+ else if (type === podverse_helpers_1.OnDemandParserEventType.REFRESH) {
57
+ const count = yield onDemandParserEventService.getCountByAccountIdAndTypeSince(accountId, podverse_helpers_1.OnDemandParserEventType.REFRESH, (0, podverse_helpers_1.getOnDemandParserEventDateRange)());
58
+ if (count >= podverse_helpers_1.ON_DEMAND_REFRESH_PARSER_LIMIT) {
59
+ throw new Error('Monthly on-demand refresh feed parser limit reached');
60
+ }
61
+ }
62
+ }
63
+ }
44
64
  const feedService = new podverse_orm_1.FeedService();
45
65
  let feed = null;
46
66
  let channel = null;
@@ -115,9 +135,27 @@ const parseRSSFeedAndSaveToDatabase = (url, podcast_index_id, options) => __awai
115
135
  });
116
136
  }
117
137
  }
138
+ if (onDemandParserEvent) {
139
+ const { accountId, remoteParentPodcastIndexId, type } = onDemandParserEvent;
140
+ if (accountId && type) {
141
+ const accountService = new podverse_orm_1.AccountService();
142
+ const account = yield accountService.get(accountId);
143
+ if (account) {
144
+ yield onDemandParserEventService.create({
145
+ account,
146
+ podcastIndexId: podcast_index_id,
147
+ remoteParentPodcastIndexId: remoteParentPodcastIndexId,
148
+ type,
149
+ });
150
+ }
151
+ }
152
+ }
118
153
  }
119
154
  if (channel) {
120
- yield (0, remoteItemParser_1.handleAllRemoteItemsFeedParsing)(channel);
155
+ yield (0, remoteItemParser_1.handleAllRemoteItemsFeedParsing)(channel, {
156
+ accountId: (onDemandParserEvent === null || onDemandParserEvent === void 0 ? void 0 : onDemandParserEvent.accountId) || null,
157
+ remoteParentPodcastIndexId: podcast_index_id,
158
+ });
121
159
  }
122
160
  return;
123
161
  });
@@ -1,3 +1,7 @@
1
- import { Channel } from "podverse-orm";
2
- export declare const handleAllRemoteItemsFeedParsing: (channel: Channel) => Promise<void>;
1
+ import { Channel } from 'podverse-orm';
2
+ export type OnDemandParserRemoteItemParams = {
3
+ accountId: number | null;
4
+ remoteParentPodcastIndexId: number;
5
+ };
6
+ export declare const handleAllRemoteItemsFeedParsing: (channel: Channel, params: OnDemandParserRemoteItemParams) => Promise<void>;
3
7
  //# sourceMappingURL=remoteItemParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"remoteItemParser.d.ts","sourceRoot":"","sources":["../../../src/lib/rss/remoteItemParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EACsD,MAAM,cAAc,CAAC;AAwD3F,eAAO,MAAM,+BAA+B,GAAU,SAAS,OAAO,kBAOrE,CAAC"}
1
+ {"version":3,"file":"remoteItemParser.d.ts","sourceRoot":"","sources":["../../../src/lib/rss/remoteItemParser.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EAUR,MAAM,cAAc,CAAC;AAUtB,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0BAA0B,EAAE,MAAM,CAAC;CACpC,CAAA;AAoED,eAAO,MAAM,+BAA+B,GAAU,SAAS,OAAO,EAAE,QAAQ,8BAA8B,kBAO7G,CAAC"}
@@ -28,8 +28,16 @@ function handleRequestDelay(url) {
28
28
  }
29
29
  });
30
30
  }
31
- const handleRemoteItemsFeedParsing = (feedGuidsToParse) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const handleRemoteItemsFeedParsing = (feedGuidsToParse, params) => __awaiter(void 0, void 0, void 0, function* () {
32
32
  var _a, _b;
33
+ const { accountId, remoteParentPodcastIndexId } = params;
34
+ if (accountId) {
35
+ const onDemandParserEventService = new podverse_orm_1.OnDemandParserEventService();
36
+ const count = yield onDemandParserEventService.getCountByAccountIdAndTypeSince(accountId, podverse_helpers_1.OnDemandParserEventType.REMOTE_ITEM, (0, podverse_helpers_1.getOnDemandParserEventDateRange)());
37
+ if (count >= podverse_helpers_1.ON_DEMAND_REMOTE_ITEM_PARSER_LIMIT) {
38
+ throw new Error('Monthly on-demand remote item feed parser limit reached');
39
+ }
40
+ }
33
41
  const piFeedDatas = [];
34
42
  for (const feedGuid of feedGuidsToParse) {
35
43
  const feedService = new podverse_orm_1.FeedService();
@@ -54,46 +62,53 @@ const handleRemoteItemsFeedParsing = (feedGuidsToParse) => __awaiter(void 0, voi
54
62
  if (!feed) {
55
63
  yield handleRequestDelay(piFeedData.url);
56
64
  loggerService_1.loggerService.info(`handleRemoteItemsFeedParsing: ${piFeedData.url} ${piFeedData.id}`);
57
- yield (0, parser_1.parseRSSFeedAndSaveToDatabase)(piFeedData.url, piFeedData.id, { forceParse: false });
65
+ yield (0, parser_1.parseRSSFeedAndSaveToDatabase)(piFeedData.url, piFeedData.id, {
66
+ forceParse: false,
67
+ onDemandParserEvent: {
68
+ accountId,
69
+ remoteParentPodcastIndexId,
70
+ type: podverse_helpers_1.OnDemandParserEventType.REMOTE_ITEM,
71
+ },
72
+ });
58
73
  }
59
74
  }
60
75
  });
61
- const handleAllRemoteItemsFeedParsing = (channel) => __awaiter(void 0, void 0, void 0, function* () {
76
+ const handleAllRemoteItemsFeedParsing = (channel, params) => __awaiter(void 0, void 0, void 0, function* () {
62
77
  const channelService = new podverse_orm_1.ChannelService();
63
78
  const latestChannel = yield channelService.get(channel.id);
64
- yield handleRemoteItemsPodrollParsing(channel);
65
- yield handleRemoteItemsPublisherParsing(channel);
66
- yield handleRemoteItemsChannelParsing(channel);
67
- yield handleRemoteItemsItemValueTimeSplitParsing(latestChannel);
79
+ yield handleRemoteItemsPodrollParsing(channel, params);
80
+ yield handleRemoteItemsPublisherParsing(channel, params);
81
+ yield handleRemoteItemsChannelParsing(channel, params);
82
+ yield handleRemoteItemsItemValueTimeSplitParsing(latestChannel, params);
68
83
  });
69
84
  exports.handleAllRemoteItemsFeedParsing = handleAllRemoteItemsFeedParsing;
70
- const handleRemoteItemsPodrollParsing = (channel) => __awaiter(void 0, void 0, void 0, function* () {
85
+ const handleRemoteItemsPodrollParsing = (channel, params) => __awaiter(void 0, void 0, void 0, function* () {
71
86
  const channelPodrollService = new podverse_orm_1.ChannelPodrollService();
72
87
  const channelPodroll = yield channelPodrollService.get(channel);
73
88
  if (channelPodroll) {
74
89
  const channelPodrollRemoteItemService = new podverse_orm_1.ChannelPodrollRemoteItemService();
75
90
  const channelPodrollRemoteItems = yield channelPodrollRemoteItemService.getAll(channelPodroll);
76
- const feedGuidsToParse = channelPodrollRemoteItems.map((remoteItem) => remoteItem.feed_guid);
77
- yield handleRemoteItemsFeedParsing(feedGuidsToParse);
91
+ const feedGuidsToParse = channelPodrollRemoteItems.map(remoteItem => remoteItem.feed_guid);
92
+ yield handleRemoteItemsFeedParsing(feedGuidsToParse, params);
78
93
  }
79
94
  });
80
- const handleRemoteItemsPublisherParsing = (channel) => __awaiter(void 0, void 0, void 0, function* () {
95
+ const handleRemoteItemsPublisherParsing = (channel, params) => __awaiter(void 0, void 0, void 0, function* () {
81
96
  const channelPublisherService = new podverse_orm_1.ChannelPublisherService();
82
97
  const channelPublisher = yield channelPublisherService.get(channel);
83
98
  if (channelPublisher) {
84
99
  const channelPublisherRemoteItemService = new podverse_orm_1.ChannelPublisherRemoteItemService();
85
100
  const channelPublisherRemoteItems = yield channelPublisherRemoteItemService.getAll(channelPublisher);
86
- const feedGuidsToParse = channelPublisherRemoteItems.map((remoteItem) => remoteItem.feed_guid);
87
- yield handleRemoteItemsFeedParsing(feedGuidsToParse);
101
+ const feedGuidsToParse = channelPublisherRemoteItems.map(remoteItem => remoteItem.feed_guid);
102
+ yield handleRemoteItemsFeedParsing(feedGuidsToParse, params);
88
103
  }
89
104
  });
90
- const handleRemoteItemsChannelParsing = (channel) => __awaiter(void 0, void 0, void 0, function* () {
105
+ const handleRemoteItemsChannelParsing = (channel, params) => __awaiter(void 0, void 0, void 0, function* () {
91
106
  const channelRemoteItemService = new podverse_orm_1.ChannelRemoteItemService();
92
107
  const channelRemoteItems = yield channelRemoteItemService.getAll(channel);
93
- const feedGuidsToParse = channelRemoteItems.map((remoteItem) => remoteItem.feed_guid);
94
- yield handleRemoteItemsFeedParsing(feedGuidsToParse);
108
+ const feedGuidsToParse = channelRemoteItems.map(remoteItem => remoteItem.feed_guid);
109
+ yield handleRemoteItemsFeedParsing(feedGuidsToParse, params);
95
110
  });
96
- const handleRemoteItemsItemValueTimeSplitParsing = (channel) => __awaiter(void 0, void 0, void 0, function* () {
111
+ const handleRemoteItemsItemValueTimeSplitParsing = (channel, params) => __awaiter(void 0, void 0, void 0, function* () {
97
112
  var _a, _b;
98
113
  if (channel.has_value_time_splits) {
99
114
  const itemService = new podverse_orm_1.ItemService();
@@ -113,7 +128,7 @@ const handleRemoteItemsItemValueTimeSplitParsing = (channel) => __awaiter(void 0
113
128
  for (const itemValueTimeSplit of itemValue.item_value_time_splits) {
114
129
  if (itemValueTimeSplit.item_value_time_split_remote_item) {
115
130
  const feedGuid = itemValueTimeSplit.item_value_time_split_remote_item.feed_guid;
116
- yield handleRemoteItemsFeedParsing([feedGuid]);
131
+ yield handleRemoteItemsFeedParsing([feedGuid], params);
117
132
  }
118
133
  }
119
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podverse-parser",
3
- "version": "5.1.6-alpha.4",
3
+ "version": "5.1.7-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  "dependencies": {
19
19
  "module-alias": "^2.2.3",
20
20
  "podcast-partytime": "^4.9.1",
21
- "podverse-external-services": "^5.1.6-alpha.3",
22
- "podverse-helpers": "^5.1.6-alpha.1",
23
- "podverse-orm": "^5.1.6-alpha.3"
21
+ "podverse-external-services": "^5.1.7-alpha.0",
22
+ "podverse-helpers": "^5.1.7-alpha.0",
23
+ "podverse-orm": "^5.1.7-alpha.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@eslint/config-array": "^0.21.0",