podverse-orm 5.1.0-alpha.5 → 5.1.0-alpha.7

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.
@@ -12,6 +12,8 @@ export declare class ArchiverService {
12
12
  private processItems;
13
13
  processPendingArchiveFeeds(): Promise<void>;
14
14
  processPendingArchiveItems(): Promise<void>;
15
+ getFeedsWithTakedownStatus(): Promise<Feed[]>;
16
+ removeAllItemsForTakedownFeeds(): Promise<void>;
15
17
  archiveAll(): Promise<void>;
16
18
  }
17
19
  //# sourceMappingURL=archiver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"archiver.d.ts","sourceRoot":"","sources":["../../src/services/archiver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAK/C,qBAAa,eAAe;IAC1B,OAAO,CAAC,kBAAkB,CAAyC;IACnE,OAAO,CAAC,uBAAuB,CAA8C;IAC7E,OAAO,CAAC,kBAAkB,CAAyC;IACnE,OAAO,CAAC,uBAAuB,CAA8C;IAC7E,OAAO,CAAC,0BAA0B,CAAqD;IACvF,OAAO,CAAC,cAAc,CAAyC;IAEzD,sBAAsB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAsBzC,sBAAsB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YAWjC,YAAY;IAmBpB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC3C,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAIlC"}
1
+ {"version":3,"file":"archiver.d.ts","sourceRoot":"","sources":["../../src/services/archiver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAK/C,qBAAa,eAAe;IAC1B,OAAO,CAAC,kBAAkB,CAAyC;IACnE,OAAO,CAAC,uBAAuB,CAA8C;IAC7E,OAAO,CAAC,kBAAkB,CAAyC;IACnE,OAAO,CAAC,uBAAuB,CAA8C;IAC7E,OAAO,CAAC,0BAA0B,CAAqD;IACvF,OAAO,CAAC,cAAc,CAAyC;IAEzD,sBAAsB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAsBzC,sBAAsB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YAWjC,YAAY;IAmBpB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC;IAqC3C,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3C,0BAA0B,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAW7C,8BAA8B,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAKlC"}
@@ -65,12 +65,12 @@ class ArchiverService {
65
65
  processItems(items, archivedStatus) {
66
66
  return __awaiter(this, void 0, void 0, function* () {
67
67
  for (const item of items) {
68
- const hasPlaylistResource = yield this.playlistResourceRepository.findOne({
68
+ const hasPlaylistResource = !!(yield this.playlistResourceRepository.findOne({
69
69
  where: { item: { id: item.id } },
70
- });
71
- const hasClip = yield this.clipRepository.findOne({
70
+ }));
71
+ const hasClip = !!(yield this.clipRepository.findOne({
72
72
  where: { item: { id: item.id } },
73
- });
73
+ }));
74
74
  if (hasPlaylistResource || hasClip) {
75
75
  item.item_flag_status = archivedStatus;
76
76
  yield this.itemRepositoryReadWrite.save(item);
@@ -100,13 +100,13 @@ class ArchiverService {
100
100
  },
101
101
  relations: ['item_flag_status']
102
102
  });
103
- if (items.length === 0) {
104
- yield this.feedRepositoryReadWrite.delete(feed.id);
105
- }
106
- else {
107
- const activeOrPendingItems = items.filter(item => [itemFlagStatus_1.ItemFlagStatusStatusEnum.Active, itemFlagStatus_1.ItemFlagStatusStatusEnum.PendingArchive].includes(item.item_flag_status.id));
103
+ if (items.length > 0) {
104
+ const activeOrPendingItems = items.filter(item => [itemFlagStatus_1.ItemFlagStatusStatusEnum.Active, itemFlagStatus_1.ItemFlagStatusStatusEnum.PendingArchive]
105
+ .includes(item.item_flag_status.id));
108
106
  yield this.processItems(activeOrPendingItems, archivedStatus);
109
107
  }
108
+ feed.feed_flag_status = Object.assign(Object.assign({}, feed.feed_flag_status), { id: feedFlagStatus_1.FeedFlagStatusStatusEnum.Archived });
109
+ yield this.feedRepositoryReadWrite.save(feed);
110
110
  }
111
111
  });
112
112
  }
@@ -121,10 +121,38 @@ class ArchiverService {
121
121
  yield this.processItems(items, archivedStatus);
122
122
  });
123
123
  }
124
+ getFeedsWithTakedownStatus() {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ return this.feedRepositoryRead.find({
127
+ where: {
128
+ feed_flag_status: {
129
+ id: feedFlagStatus_1.FeedFlagStatusStatusEnum.Takedown,
130
+ },
131
+ },
132
+ relations: ['channel', 'channel.items', 'feed_flag_status'],
133
+ });
134
+ });
135
+ }
136
+ removeAllItemsForTakedownFeeds() {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const feeds = yield this.getFeedsWithTakedownStatus();
139
+ for (const feed of feeds) {
140
+ const channel = feed.channel;
141
+ if (!channel || !channel.items || channel.items.length === 0) {
142
+ continue;
143
+ }
144
+ const itemIds = channel.items.map(item => item.id);
145
+ if (itemIds.length > 0) {
146
+ yield this.itemRepositoryReadWrite.delete(itemIds);
147
+ }
148
+ }
149
+ });
150
+ }
124
151
  archiveAll() {
125
152
  return __awaiter(this, void 0, void 0, function* () {
126
153
  yield this.processPendingArchiveFeeds();
127
154
  yield this.processPendingArchiveItems();
155
+ yield this.removeAllItemsForTakedownFeeds();
128
156
  });
129
157
  }
130
158
  }
@@ -3,14 +3,14 @@ import { Item } from '@orm/entities/item/item';
3
3
  export declare class DeduplicatorService {
4
4
  protected readWriteEntityManager: EntityManager;
5
5
  constructor();
6
- mergeChannels(id_to_remove: number, duplicate_id_to_keep: number): Promise<void>;
6
+ mergeChannels(id_to_archive: number, duplicate_id_to_keep: number): Promise<void>;
7
7
  private updateAccountFollowingChannel;
8
8
  private buildItemMaps;
9
9
  private findDuplicateItem;
10
10
  private updateClipAndPlaylistResource;
11
11
  getChannelItems(channel_id: number): Promise<Item[]>;
12
- getItemsForBothChannels(id_to_remove: number, duplicate_id_to_keep: number): Promise<{
13
- itemsToRemove: Item[];
12
+ getItemsForBothChannels(id_to_archive: number, duplicate_id_to_keep: number): Promise<{
13
+ itemsToArchive: Item[];
14
14
  duplicateItemsToKeep: Item[];
15
15
  }>;
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../src/services/deduplicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG/C,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,sBAAsB,EAAE,aAAa,CAAC;;IAM1C,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAcxE,6BAA6B;IAS3C,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,iBAAiB;YAcX,6BAA6B;IAgBrC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAOpD,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QAAC,oBAAoB,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC;CAKpJ"}
1
+ {"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../src/services/deduplicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG/C,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,sBAAsB,EAAE,aAAa,CAAC;;IAM1C,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAczE,6BAA6B;IAS3C,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,iBAAiB;YAcX,6BAA6B;IAgBrC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAOpD,uBAAuB,CAAC,aAAa,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,cAAc,EAAE,IAAI,EAAE,CAAC;QAAC,oBAAoB,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC;CAKtJ"}
@@ -19,26 +19,26 @@ class DeduplicatorService {
19
19
  constructor() {
20
20
  this.readWriteEntityManager = db_1.AppDataSourceReadWrite.manager;
21
21
  }
22
- mergeChannels(id_to_remove, duplicate_id_to_keep) {
22
+ mergeChannels(id_to_archive, duplicate_id_to_keep) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- yield this.updateAccountFollowingChannel(id_to_remove, duplicate_id_to_keep);
25
- const { itemsToRemove, duplicateItemsToKeep } = yield this.getItemsForBothChannels(id_to_remove, duplicate_id_to_keep);
24
+ yield this.updateAccountFollowingChannel(id_to_archive, duplicate_id_to_keep);
25
+ const { itemsToArchive, duplicateItemsToKeep } = yield this.getItemsForBothChannels(id_to_archive, duplicate_id_to_keep);
26
26
  const { guidMap, guidEnclosureUrlMap } = this.buildItemMaps(duplicateItemsToKeep);
27
- for (const itemToRemove of itemsToRemove) {
28
- const duplicateItemToKeep = this.findDuplicateItem(itemToRemove, guidMap, guidEnclosureUrlMap);
27
+ for (const itemToArchive of itemsToArchive) {
28
+ const duplicateItemToKeep = this.findDuplicateItem(itemToArchive, guidMap, guidEnclosureUrlMap);
29
29
  if (duplicateItemToKeep) {
30
- yield this.updateClipAndPlaylistResource(itemToRemove.id, duplicateItemToKeep.id);
30
+ yield this.updateClipAndPlaylistResource(itemToArchive.id, duplicateItemToKeep.id);
31
31
  }
32
32
  }
33
33
  });
34
34
  }
35
- updateAccountFollowingChannel(id_to_remove, duplicate_id_to_keep) {
35
+ updateAccountFollowingChannel(id_to_archive, duplicate_id_to_keep) {
36
36
  return __awaiter(this, void 0, void 0, function* () {
37
37
  yield this.readWriteEntityManager
38
38
  .createQueryBuilder()
39
39
  .update(accountFollowingChannel_1.AccountFollowingChannel)
40
40
  .set({ channel_id: duplicate_id_to_keep })
41
- .where("channel_id = :channel_to_remove", { channel_to_remove: id_to_remove })
41
+ .where("channel_id = :id_to_archive", { id_to_archive })
42
42
  .execute();
43
43
  });
44
44
  }
@@ -53,28 +53,28 @@ class DeduplicatorService {
53
53
  }
54
54
  return { guidMap, guidEnclosureUrlMap };
55
55
  }
56
- findDuplicateItem(itemToRemove, guidMap, guidEnclosureUrlMap) {
57
- if (itemToRemove.guid && guidMap.has(itemToRemove.guid)) {
58
- return guidMap.get(itemToRemove.guid);
56
+ findDuplicateItem(itemToArchive, guidMap, guidEnclosureUrlMap) {
57
+ if (itemToArchive.guid && guidMap.has(itemToArchive.guid)) {
58
+ return guidMap.get(itemToArchive.guid);
59
59
  }
60
- if (itemToRemove.guid_enclosure_url && guidEnclosureUrlMap.has(itemToRemove.guid_enclosure_url)) {
61
- return guidEnclosureUrlMap.get(itemToRemove.guid_enclosure_url);
60
+ if (itemToArchive.guid_enclosure_url && guidEnclosureUrlMap.has(itemToArchive.guid_enclosure_url)) {
61
+ return guidEnclosureUrlMap.get(itemToArchive.guid_enclosure_url);
62
62
  }
63
63
  return undefined;
64
64
  }
65
- updateClipAndPlaylistResource(itemToRemoveId, duplicateItemToKeepId) {
65
+ updateClipAndPlaylistResource(itemToArchiveId, duplicateItemToKeepId) {
66
66
  return __awaiter(this, void 0, void 0, function* () {
67
67
  yield this.readWriteEntityManager
68
68
  .createQueryBuilder()
69
69
  .update(clip_1.Clip)
70
70
  .set({ item_id: duplicateItemToKeepId })
71
- .where("item_id = :itemToRemoveId", { itemToRemoveId })
71
+ .where("item_id = :itemToArchiveId", { itemToArchiveId })
72
72
  .execute();
73
73
  yield this.readWriteEntityManager
74
74
  .createQueryBuilder()
75
75
  .update(playlistResource_1.PlaylistResource)
76
76
  .set({ item_id: duplicateItemToKeepId })
77
- .where("item_id = :itemToRemoveId", { itemToRemoveId })
77
+ .where("item_id = :itemToArchiveId", { itemToArchiveId })
78
78
  .execute();
79
79
  });
80
80
  }
@@ -86,11 +86,11 @@ class DeduplicatorService {
86
86
  return items;
87
87
  });
88
88
  }
89
- getItemsForBothChannels(id_to_remove, duplicate_id_to_keep) {
89
+ getItemsForBothChannels(id_to_archive, duplicate_id_to_keep) {
90
90
  return __awaiter(this, void 0, void 0, function* () {
91
- const itemsToRemove = yield this.getChannelItems(id_to_remove);
91
+ const itemsToArchive = yield this.getChannelItems(id_to_archive);
92
92
  const duplicateItemsToKeep = yield this.getChannelItems(duplicate_id_to_keep);
93
- return { itemsToRemove, duplicateItemsToKeep };
93
+ return { itemsToArchive, duplicateItemsToKeep };
94
94
  });
95
95
  }
96
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podverse-orm",
3
- "version": "5.1.0-alpha.5",
3
+ "version": "5.1.0-alpha.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",