podverse-external-services 5.1.1-alpha.6 → 5.1.1-alpha.8

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.
@@ -11,8 +11,5 @@ export declare const config: {
11
11
  clientSecret: string;
12
12
  mode: string;
13
13
  };
14
- podcastIndex: {
15
- recentlyUpdatedDataInterval: number;
16
- };
17
14
  };
18
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;CAgBlB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;;CAalB,CAAA"}
@@ -13,8 +13,5 @@ exports.config = {
13
13
  clientId: process.env.PAYPAL_CLIENT_ID || '',
14
14
  clientSecret: process.env.PAYPAL_CLIENT_SECRET || '',
15
15
  mode: process.env.PAYPAL_MODE || 'sandbox'
16
- },
17
- podcastIndex: {
18
- recentlyUpdatedDataInterval: parseInt(process.env.PODCAST_INDEX_RECENTLY_UPDATED_DATA_INTERVAL || '1800', 10)
19
16
  }
20
17
  };
@@ -11,8 +11,9 @@ export declare class PodcastIndexService {
11
11
  constructor({ authKey, baseUrl, secretKey }: Constructor);
12
12
  podcastIndexAPIRequest: (url: string, config?: any) => Promise<any>;
13
13
  deadFeedsDownloadAndExtractCSV: () => Promise<any[]>;
14
+ podcastGetById: (podcastIndexId: number) => Promise<any | null>;
14
15
  podcastGetByGuid: (podcastGuid: string) => Promise<PodcastByGuidResponse | null>;
15
- recentGetData: () => Promise<any[]>;
16
+ recentGetData: (sinceRange: number) => Promise<any[]>;
16
17
  trendingGetPodcasts: (max?: number, since?: number, lang?: string, cat?: string) => Promise<{
17
18
  feeds: any[];
18
19
  nextSince?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/podcast-index/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,qBAAa,mBAAmB;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;gBAEZ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,WAAW;IAQzD,sBAAsB,GAAU,KAAK,MAAM,EAAE,SAAS,GAAG,kBA0BxD;IAID,8BAA8B,QAAa,OAAO,CAAC,GAAG,EAAE,CAAC,CAwCxD;IAID,gBAAgB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAYpF;IAID,aAAa,uBA6BZ;IAID,mBAAmB,GACjB,MAAK,MAAW,EAChB,QAAQ,MAAM,EACd,OAAO,MAAM,EACb,MAAM,MAAM,KACX,OAAO,CAAC;QAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAoB/C;IAID,oBAAoB,QAAa,OAAO,CAAC,MAAM,EAAE,CAAC,CAMjD;IAED,+BAA+B,GAC7B,4BAA4B,MAAM,EAAE,EAAE,gBAAW,KAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAatE;CACF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/podcast-index/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,qBAAa,mBAAmB;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;gBAEZ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,WAAW;IAQzD,sBAAsB,GAAU,KAAK,MAAM,EAAE,SAAS,GAAG,kBA+BxD;IAID,8BAA8B,QAAa,OAAO,CAAC,GAAG,EAAE,CAAC,CAwCxD;IAID,cAAc,GAAU,gBAAgB,MAAM,KAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAQnE;IAED,gBAAgB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAYpF;IAID,aAAa,GAAU,YAAY,MAAM,oBA4BxC;IAID,mBAAmB,GACjB,MAAK,MAAW,EAChB,QAAQ,MAAM,EACd,OAAO,MAAM,EACb,MAAM,MAAM,KACX,OAAO,CAAC;QAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAoB/C;IAID,oBAAoB,QAAa,OAAO,CAAC,MAAM,EAAE,CAAC,CAMjD;IAED,+BAA+B,GAC7B,4BAA4B,MAAM,EAAE,EAAE,gBAAW,KAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAatE;CACF"}
@@ -19,7 +19,6 @@ const csv_parser_1 = __importDefault(require("csv-parser"));
19
19
  const fs_1 = __importDefault(require("fs"));
20
20
  const path_1 = __importDefault(require("path"));
21
21
  const podverse_helpers_1 = require("podverse-helpers");
22
- const config_1 = require("@external-services/config");
23
22
  /*
24
23
  NOTE!!!
25
24
  The episodeGuid needs to be encoded both on the client-side and server side if it is an http url guid.
@@ -33,12 +32,16 @@ class PodcastIndexService {
33
32
  var _a, _b, _c;
34
33
  const apiHeaderTime = Math.floor(Date.now() / 1000);
35
34
  const hash = (0, sha1_1.default)(this.authKey + this.secretKey + apiHeaderTime).toString(enc_hex_1.default);
35
+ const shouldPreventHeaders = (config === null || config === void 0 ? void 0 : config.preventHeaders) || false;
36
+ config === null || config === void 0 ? true : delete config.preventHeaders;
36
37
  try {
37
- const response = yield (0, podverse_helpers_1.request)(url, Object.assign({ headers: {
38
+ const response = yield (0, podverse_helpers_1.request)(url, Object.assign(Object.assign({}, (shouldPreventHeaders ? {} : {
39
+ headers: {
38
40
  'X-Auth-Key': this.authKey,
39
41
  'X-Auth-Date': apiHeaderTime,
40
42
  Authorization: hash
41
- } }, config));
43
+ }
44
+ })), config));
42
45
  return response;
43
46
  }
44
47
  catch (error) {
@@ -61,7 +64,7 @@ class PodcastIndexService {
61
64
  if (!fs_1.default.existsSync(tmpDir)) {
62
65
  fs_1.default.mkdirSync(tmpDir);
63
66
  }
64
- const data = yield this.podcastIndexAPIRequest(url, { responseType: 'stream' });
67
+ const data = yield this.podcastIndexAPIRequest(url, { preventHeaders: true, responseType: 'stream' });
65
68
  const writer = fs_1.default.createWriteStream(filePath);
66
69
  data.pipe(writer);
67
70
  yield new Promise((resolve, reject) => {
@@ -78,15 +81,25 @@ class PodcastIndexService {
78
81
  });
79
82
  fs_1.default.unlinkSync(filePath);
80
83
  const parsedResults = results.map((row) => {
81
- const [id, duplicateOf] = Object.values(row).map((value) => value.trim());
84
+ const [id_to_remove, duplicate_id_to_keep] = Object.values(row).map((value) => value.trim());
82
85
  return {
83
- podcast_index_id: parseInt(id, 10),
84
- duplicateOf: duplicateOf ? parseInt(duplicateOf, 10) : null
86
+ id_to_remove: parseInt(id_to_remove, 10),
87
+ duplicate_id_to_keep: duplicate_id_to_keep ? parseInt(duplicate_id_to_keep, 10) : null
85
88
  };
86
89
  });
87
90
  return parsedResults;
88
91
  });
89
92
  // Podcast
93
+ this.podcastGetById = (podcastIndexId) => __awaiter(this, void 0, void 0, function* () {
94
+ const url = `${this.baseUrl}/podcasts/byfeedid?id=${podcastIndexId}`;
95
+ try {
96
+ const response = yield this.podcastIndexAPIRequest(url);
97
+ return response || null;
98
+ }
99
+ catch (error) {
100
+ return null;
101
+ }
102
+ });
90
103
  this.podcastGetByGuid = (podcastGuid) => __awaiter(this, void 0, void 0, function* () {
91
104
  const url = `${this.baseUrl}/podcasts/byguid?guid=${podcastGuid}`;
92
105
  let podcastIndexPodcast = null;
@@ -100,10 +113,9 @@ class PodcastIndexService {
100
113
  return podcastIndexPodcast || null;
101
114
  });
102
115
  // Recent
103
- this.recentGetData = () => __awaiter(this, void 0, void 0, function* () {
116
+ this.recentGetData = (sinceRange) => __awaiter(this, void 0, void 0, function* () {
104
117
  podverse_helpers_1.logger.info('recentGetData beginning...');
105
118
  const currentTimeInSeconds = Math.floor(Date.now() / 1000);
106
- const sinceRange = config_1.config.podcastIndex.recentlyUpdatedDataInterval;
107
119
  const sinceTimeInSeconds = currentTimeInSeconds - sinceRange;
108
120
  const fetchData = (since_1, ...args_1) => __awaiter(this, [since_1, ...args_1], void 0, function* (since, allData = []) {
109
121
  podverse_helpers_1.logger.info(`fetchData since: ${since}, allData.length: ${allData.length}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podverse-external-services",
3
- "version": "5.1.1-alpha.6",
3
+ "version": "5.1.1-alpha.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",