patreon-dl 3.2.0 → 3.3.0
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/README.md +15 -0
- package/dist/browse/api/CampaignAPIMixin.d.ts +4 -4
- package/dist/browse/api/CampaignAPIMixin.js +4 -4
- package/dist/browse/api/CampaignAPIMixin.js.map +1 -1
- package/dist/browse/api/ContentAPIMixin.d.ts +6 -5
- package/dist/browse/api/ContentAPIMixin.js +64 -29
- package/dist/browse/api/ContentAPIMixin.js.map +1 -1
- package/dist/browse/api/FilterAPIMixin.d.ts +3 -3
- package/dist/browse/api/FilterAPIMixin.js +13 -13
- package/dist/browse/api/FilterAPIMixin.js.map +1 -1
- package/dist/browse/api/MediaAPIMixin.d.ts +1 -1
- package/dist/browse/api/MediaAPIMixin.js.map +1 -1
- package/dist/browse/api/SettingsAPIMixin.d.ts +3 -3
- package/dist/browse/api/SettingsAPIMixin.js +2 -2
- package/dist/browse/api/SettingsAPIMixin.js.map +1 -1
- package/dist/browse/api/index.d.ts +30 -28
- package/dist/browse/db/CampaignDBMixin.d.ts +28 -27
- package/dist/browse/db/CampaignDBMixin.js +29 -29
- package/dist/browse/db/CampaignDBMixin.js.map +1 -1
- package/dist/browse/db/ContentDBMixin.d.ts +55 -50
- package/dist/browse/db/ContentDBMixin.js +158 -58
- package/dist/browse/db/ContentDBMixin.js.map +1 -1
- package/dist/browse/db/EnvDBMixin.d.ts +10 -9
- package/dist/browse/db/EnvDBMixin.js +9 -8
- package/dist/browse/db/EnvDBMixin.js.map +1 -1
- package/dist/browse/db/Init.d.ts +2 -3
- package/dist/browse/db/Init.js +71 -18
- package/dist/browse/db/Init.js.map +1 -1
- package/dist/browse/db/MediaDBMixin.d.ts +18 -17
- package/dist/browse/db/MediaDBMixin.js +19 -19
- package/dist/browse/db/MediaDBMixin.js.map +1 -1
- package/dist/browse/db/Update.d.ts +7 -0
- package/dist/browse/db/Update.js +46 -0
- package/dist/browse/db/Update.js.map +1 -0
- package/dist/browse/db/UserDBMixin.d.ts +21 -20
- package/dist/browse/db/UserDBMixin.js +10 -10
- package/dist/browse/db/UserDBMixin.js.map +1 -1
- package/dist/browse/db/index.d.ts +378 -142
- package/dist/browse/db/index.js +27 -47
- package/dist/browse/db/index.js.map +1 -1
- package/dist/browse/db/updaters/DBUpdater_1_1_0.d.ts +2 -0
- package/dist/browse/db/updaters/DBUpdater_1_1_0.js +11 -0
- package/dist/browse/db/updaters/DBUpdater_1_1_0.js.map +1 -0
- package/dist/browse/server/handler/CampaignAPIRequesthandler.d.ts +2 -2
- package/dist/browse/server/handler/CampaignAPIRequesthandler.js +4 -4
- package/dist/browse/server/handler/CampaignAPIRequesthandler.js.map +1 -1
- package/dist/browse/server/handler/ContentAPIRequestHandler.d.ts +3 -3
- package/dist/browse/server/handler/ContentAPIRequestHandler.js +50 -30
- package/dist/browse/server/handler/ContentAPIRequestHandler.js.map +1 -1
- package/dist/browse/server/handler/MediaAPIRequestHandler.d.ts +2 -2
- package/dist/browse/server/handler/MediaAPIRequestHandler.js +8 -8
- package/dist/browse/server/handler/MediaAPIRequestHandler.js.map +1 -1
- package/dist/browse/server/handler/MediaRequestHandler.d.ts +1 -1
- package/dist/browse/server/handler/MediaRequestHandler.js +11 -2
- package/dist/browse/server/handler/MediaRequestHandler.js.map +1 -1
- package/dist/browse/server/handler/SettingsAPIRequestHandler.d.ts +2 -2
- package/dist/browse/server/handler/SettingsAPIRequestHandler.js +4 -4
- package/dist/browse/server/handler/SettingsAPIRequestHandler.js.map +1 -1
- package/dist/browse/types/Content.d.ts +8 -0
- package/dist/browse/types/Content.js.map +1 -1
- package/dist/browse/web/assets/index-C5gLqRAU.js +209 -0
- package/dist/browse/web/assets/{index-USVypdWT.css → index-b301OTnD.css} +1 -1
- package/dist/browse/web/index.html +2 -2
- package/dist/cli/CLIOptions.d.ts +2 -1
- package/dist/cli/CLIOptions.js +20 -13
- package/dist/cli/CLIOptions.js.map +1 -1
- package/dist/cli/index.js +7 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/downloaders/Downloader.d.ts +2 -2
- package/dist/downloaders/Downloader.js +6 -5
- package/dist/downloaders/Downloader.js.map +1 -1
- package/dist/downloaders/PostDownloader.js +72 -7
- package/dist/downloaders/PostDownloader.js.map +1 -1
- package/dist/downloaders/ProductDownloader.js +2 -2
- package/dist/downloaders/ProductDownloader.js.map +1 -1
- package/dist/downloaders/task/DownloadTaskFactory.js +1 -0
- package/dist/downloaders/task/DownloadTaskFactory.js.map +1 -1
- package/dist/downloaders/task/FFmpegDownloadTaskBase.d.ts +1 -1
- package/dist/downloaders/task/FFmpegDownloadTaskBase.js +27 -13
- package/dist/downloaders/task/FFmpegDownloadTaskBase.js.map +1 -1
- package/dist/downloaders/task/M3U8DownloadTask.js +3 -1
- package/dist/downloaders/task/M3U8DownloadTask.js.map +1 -1
- package/dist/downloaders/task/YouTubeDownloadTask.d.ts +4 -2
- package/dist/downloaders/task/YouTubeDownloadTask.js +63 -6
- package/dist/downloaders/task/YouTubeDownloadTask.js.map +1 -1
- package/dist/entities/Post.d.ts +13 -0
- package/dist/entities/Post.js.map +1 -1
- package/dist/parsers/Parser.d.ts +2 -0
- package/dist/parsers/Parser.js +17 -1
- package/dist/parsers/Parser.js.map +1 -1
- package/dist/parsers/PostParser.js +4 -1
- package/dist/parsers/PostParser.js.map +1 -1
- package/dist/utils/FSHelper.d.ts +0 -1
- package/dist/utils/FSHelper.js +0 -10
- package/dist/utils/FSHelper.js.map +1 -1
- package/dist/utils/Fetcher.d.ts +2 -0
- package/dist/utils/Fetcher.js +3 -0
- package/dist/utils/Fetcher.js.map +1 -1
- package/dist/utils/Misc.d.ts +1 -1
- package/dist/utils/Misc.js.map +1 -1
- package/dist/utils/URLHelper.d.ts +9 -0
- package/dist/utils/URLHelper.js +25 -0
- package/dist/utils/URLHelper.js.map +1 -1
- package/dist/utils/logging/FileLogger.js +3 -3
- package/dist/utils/logging/FileLogger.js.map +1 -1
- package/dist/utils/yt/InnertubeLoader.js +1 -0
- package/dist/utils/yt/InnertubeLoader.js.map +1 -1
- package/package.json +5 -5
- package/dist/browse/web/assets/index-BqQSEIOs.js +0 -209
package/README.md
CHANGED
|
@@ -267,6 +267,21 @@ Note the URL shown in the output. Open this URL in a web browser to begin viewin
|
|
|
267
267
|
|
|
268
268
|
## Changelog
|
|
269
269
|
|
|
270
|
+
v3.3.0
|
|
271
|
+
- Fix:
|
|
272
|
+
- YouTube stream fetching error ([patreon-dl-gui#28](https://github.com/patrickkfkan/patreon-dl-gui/issues/28))
|
|
273
|
+
- Unsupported option error with FFmpeg v7.1.0 ([#97](https://github.com/patrickkfkan/patreon-dl/issues/97))
|
|
274
|
+
- Browse:
|
|
275
|
+
- Add next / previous links to post page ([#93](https://github.com/patrickkfkan/patreon-dl/issues/93))
|
|
276
|
+
- Fix media filter error when tier selected but not "Post"
|
|
277
|
+
- Process linked attachments in body of posts ([patreon-dl-gui#27](https://github.com/patrickkfkan/patreon-dl-gui/issues/27))
|
|
278
|
+
- Some DB optimizations (contrib by @[piperswe](https://github.com/piperswe) - PR #[95](https://github.com/patrickkfkan/patreon-dl/pull/95))
|
|
279
|
+
|
|
280
|
+
v3.2.1
|
|
281
|
+
- Fix log file path sometimes not sanitized properly on Windows
|
|
282
|
+
- API: add support for passing request options to `getCampaign()`
|
|
283
|
+
- CLI: add support for using request options from conf file when running with `--list-tiers` / `--list-tiers-uid`
|
|
284
|
+
|
|
270
285
|
v3.2.0
|
|
271
286
|
- Fix:
|
|
272
287
|
- "Initial data not found" error in `patreon.com/cw` pages ([#85](https://github.com/patrickkfkan/patreon-dl/issues/85)) and custom-domain pages
|
|
@@ -3,14 +3,14 @@ import { type Campaign } from "../../entities/index.js";
|
|
|
3
3
|
import { type CampaignList, type CampaignWithCounts, type GetCampaignListParams, type GetCampaignParams } from "../types/Campaign.js";
|
|
4
4
|
export declare function CampaignAPIMixin<TBase extends APIConstructor>(Base: TBase): {
|
|
5
5
|
new (...args: any[]): {
|
|
6
|
-
getCampaignList(params: GetCampaignListParams):
|
|
6
|
+
getCampaignList(params: GetCampaignListParams): CampaignList;
|
|
7
7
|
getCampaign(params: GetCampaignParams & {
|
|
8
8
|
withCounts: true;
|
|
9
|
-
}):
|
|
9
|
+
}): CampaignWithCounts | null;
|
|
10
10
|
getCampaign(params: GetCampaignParams & {
|
|
11
11
|
withCounts?: false;
|
|
12
|
-
}):
|
|
13
|
-
getCampaign(params: GetCampaignParams):
|
|
12
|
+
}): Campaign | null;
|
|
13
|
+
getCampaign(params: GetCampaignParams): Campaign | CampaignWithCounts | null;
|
|
14
14
|
"__#132@#sanitizeCampaign"(campaign: Campaign): void;
|
|
15
15
|
name: string;
|
|
16
16
|
db: import("../db").DBInstance;
|
|
@@ -12,9 +12,9 @@ export function CampaignAPIMixin(Base) {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
_CampaignAPI_instances.add(this);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
getCampaignList(params) {
|
|
16
16
|
const { sortBy = DEFAULT_CAMPAIGN_LIST_SORT_BY, limit = DEFAULT_CAMPAIGN_LIST_SIZE, offset = 0 } = params;
|
|
17
|
-
const list =
|
|
17
|
+
const list = this.db.getCampaignList({
|
|
18
18
|
sortBy,
|
|
19
19
|
limit,
|
|
20
20
|
offset
|
|
@@ -24,8 +24,8 @@ export function CampaignAPIMixin(Base) {
|
|
|
24
24
|
}
|
|
25
25
|
return list;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const campaign =
|
|
27
|
+
getCampaign(params) {
|
|
28
|
+
const campaign = this.db.getCampaign(params);
|
|
29
29
|
if (campaign) {
|
|
30
30
|
__classPrivateFieldGet(this, _CampaignAPI_instances, "m", _CampaignAPI_sanitizeCampaign).call(this, campaign);
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CampaignAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/CampaignAPIMixin.ts"],"names":[],"mappings":";;;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AAC;gBACrB,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACzD,CAAC;YACD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACtC,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;oBACvB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;QACH,CAAC;WACF;AACH,CAAC","sourcesContent":["import { type APIConstructor } from \".\";\nimport { type Campaign } from \"../../entities/index.js\";\nimport { type CampaignList, type CampaignListSortBy, type CampaignWithCounts, type GetCampaignListParams, type GetCampaignParams } from \"../types/Campaign.js\";\n\n\nconst DEFAULT_CAMPAIGN_LIST_SIZE = 10;\nconst DEFAULT_CAMPAIGN_LIST_SORT_BY: CampaignListSortBy = 'a-z';\n\n\nexport function CampaignAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class CampaignAPI extends Base {\n getCampaignList(params: GetCampaignListParams): CampaignList {\n const { sortBy = DEFAULT_CAMPAIGN_LIST_SORT_BY, limit = DEFAULT_CAMPAIGN_LIST_SIZE, offset = 0 } = params;\n const list = this.db.getCampaignList({\n sortBy,\n limit,\n offset\n });\n for (const campaign of list.campaigns) {\n this.#sanitizeCampaign(campaign);\n }\n return list;\n }\n\n getCampaign(params: GetCampaignParams & { withCounts: true }): CampaignWithCounts | null;\n getCampaign(params: GetCampaignParams & { withCounts?: false }): Campaign | null;\n getCampaign(params: GetCampaignParams): Campaign | CampaignWithCounts | null;\n getCampaign(params: GetCampaignParams) {\n const campaign = this.db.getCampaign(params);\n if (campaign) {\n this.#sanitizeCampaign(campaign);\n }\n return campaign;\n }\n\n #sanitizeCampaign(campaign: Campaign) {\n if (campaign.summary) {\n campaign.summary = this.sanitizeHTML(campaign.summary);\n }\n for (const reward of campaign.rewards) {\n if (reward.description) {\n reward.description = this.sanitizeHTML(reward.description);\n }\n }\n }\n }\n}"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type APIConstructor } from ".";
|
|
2
|
-
import { type Post } from "../../entities";
|
|
3
|
-
import { type ContentType, type GetContentListParams } from "../types/Content.js";
|
|
2
|
+
import { type Product, type Post } from "../../entities";
|
|
3
|
+
import { type GetContentContext, type ContentType, type GetContentListParams } from "../types/Content.js";
|
|
4
4
|
export declare function ContentAPIMixin<TBase extends APIConstructor>(Base: TBase): {
|
|
5
5
|
new (...args: any[]): {
|
|
6
|
-
getContentList<T extends ContentType>(params: GetContentListParams<T>):
|
|
7
|
-
getPost(id: string):
|
|
8
|
-
getProduct(id: string):
|
|
6
|
+
getContentList<T extends ContentType>(params: GetContentListParams<T>): import("../types/Content.js").ContentList<T>;
|
|
7
|
+
getPost(id: string): import("../types/Content.js").PostWithComments | null;
|
|
8
|
+
getProduct(id: string): Product | null;
|
|
9
|
+
getPreviousNextContent<T extends ContentType>(content: Post | Product, context: GetContentContext<T>): import("../types/Content.js").GetPreviousNextContentResult<T>;
|
|
9
10
|
"__#133@#processPostContentInlineMedia"(post: Post): void;
|
|
10
11
|
name: string;
|
|
11
12
|
db: import("../db").DBInstance;
|
|
@@ -5,6 +5,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
import { load as cheerioLoad } from 'cheerio';
|
|
7
7
|
import RawDataExtractor from '../web/utils/RawDataExtractor.js';
|
|
8
|
+
import { URLHelper } from '../../utils/index.js';
|
|
8
9
|
const DEFAULT_CONTENT_LIST_SIZE = 10;
|
|
9
10
|
const DEFAULT_CONTENT_LIST_SORT_BY = 'a-z';
|
|
10
11
|
export function ContentAPIMixin(Base) {
|
|
@@ -14,9 +15,9 @@ export function ContentAPIMixin(Base) {
|
|
|
14
15
|
super(...arguments);
|
|
15
16
|
_ContentAPI_instances.add(this);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
getContentList(params) {
|
|
18
19
|
const { sortBy = DEFAULT_CONTENT_LIST_SORT_BY, limit = DEFAULT_CONTENT_LIST_SIZE, offset = 0 } = params;
|
|
19
|
-
const list =
|
|
20
|
+
const list = this.db.getContentList({
|
|
20
21
|
...params,
|
|
21
22
|
sortBy,
|
|
22
23
|
limit,
|
|
@@ -37,8 +38,8 @@ export function ContentAPIMixin(Base) {
|
|
|
37
38
|
}
|
|
38
39
|
return list;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
const post =
|
|
41
|
+
getPost(id) {
|
|
42
|
+
const post = this.db.getContent(id, 'post');
|
|
42
43
|
if (post) {
|
|
43
44
|
__classPrivateFieldGet(this, _ContentAPI_instances, "m", _ContentAPI_processPostContentInlineMedia).call(this, post);
|
|
44
45
|
post.content = this.sanitizeHTML(post.content || '');
|
|
@@ -48,41 +49,75 @@ export function ContentAPIMixin(Base) {
|
|
|
48
49
|
getProduct(id) {
|
|
49
50
|
return this.db.getContent(id, 'product');
|
|
50
51
|
}
|
|
52
|
+
getPreviousNextContent(content, context) {
|
|
53
|
+
return this.db.getPreviousNextContent(content, context);
|
|
54
|
+
}
|
|
51
55
|
},
|
|
52
56
|
_ContentAPI_instances = new WeakSet(),
|
|
53
57
|
_ContentAPI_processPostContentInlineMedia = function _ContentAPI_processPostContentInlineMedia(post) {
|
|
54
58
|
const html = post.content || '';
|
|
55
|
-
|
|
59
|
+
const hasImages = post.images.length > 0;
|
|
60
|
+
const hasLinkedAttachments = post.linkedAttachments && post.linkedAttachments.length > 0;
|
|
61
|
+
if (!html || (!hasImages && !hasLinkedAttachments)) {
|
|
56
62
|
return;
|
|
57
63
|
}
|
|
58
64
|
const $ = cheerioLoad(html);
|
|
59
65
|
const replacedMediaIds = [];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
.attr('
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
66
|
+
let hasModified = false;
|
|
67
|
+
if (hasImages) {
|
|
68
|
+
$('img').each((_, _el) => {
|
|
69
|
+
const el = $(_el);
|
|
70
|
+
const id = el.attr('data-media-id');
|
|
71
|
+
const matched = id ? post.images.find(img => img.id === id && img.downloaded) : null;
|
|
72
|
+
const src = matched ? `/media/${matched.id}` : el.attr('src');
|
|
73
|
+
const imgEl = $('<img>').attr('src', src);
|
|
74
|
+
const aEl = $('<a>')
|
|
75
|
+
.attr('href', src)
|
|
76
|
+
.attr('class', 'lightgallery-item')
|
|
77
|
+
.append(imgEl);
|
|
78
|
+
const wrapperEl = $('<div>')
|
|
79
|
+
.attr('class', 'post-card__inline-media-wrapper')
|
|
80
|
+
.append(aEl);
|
|
81
|
+
if (!matched) {
|
|
82
|
+
const caption = "(Externally hosted - not stored locally)";
|
|
83
|
+
wrapperEl.append($('<span>').attr('class', 'post-card__inline-media-caption').append(caption));
|
|
84
|
+
}
|
|
85
|
+
el.replaceWith(wrapperEl);
|
|
86
|
+
if (id && matched) {
|
|
87
|
+
replacedMediaIds.push(id);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (replacedMediaIds.length > 0) {
|
|
91
|
+
hasModified = true;
|
|
92
|
+
// Remove images that have been inlined
|
|
93
|
+
post.images = post.images.filter((img) => !replacedMediaIds.includes(img.id));
|
|
80
94
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
95
|
+
}
|
|
96
|
+
// Linked attachments
|
|
97
|
+
if (hasLinkedAttachments) {
|
|
98
|
+
$('a').each((_, _el) => {
|
|
99
|
+
const aEl = $(_el);
|
|
100
|
+
const href = aEl.attr('href') || '';
|
|
101
|
+
const { validated, ownerId, mediaId } = URLHelper.isAttachmentLink(href);
|
|
102
|
+
if (validated) {
|
|
103
|
+
let modifiedPath;
|
|
104
|
+
if (post.id !== ownerId) {
|
|
105
|
+
const isDownloaded = post.linkedAttachments?.find((att) => att.postId === ownerId && att.mediaId === mediaId)?.downloadable?.downloaded;
|
|
106
|
+
modifiedPath = isDownloaded && `/media/${mediaId}?lapid=${post.id}`;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const isDownloaded = post.attachments.find((att) => att.id === mediaId)?.downloaded;
|
|
110
|
+
modifiedPath = isDownloaded && `/media/${mediaId}`;
|
|
111
|
+
}
|
|
112
|
+
if (modifiedPath) {
|
|
113
|
+
aEl.attr('href', modifiedPath);
|
|
114
|
+
hasModified = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (hasModified) {
|
|
83
120
|
post.content = $.html();
|
|
84
|
-
// Remove images that have been inlined
|
|
85
|
-
post.images = post.images.filter((img) => !replacedMediaIds.includes(img.id));
|
|
86
121
|
}
|
|
87
122
|
},
|
|
88
123
|
_a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/ContentAPIMixin.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAI9C,OAAO,gBAAgB,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"ContentAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/ContentAPIMixin.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAI9C,OAAO,gBAAgB,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,4BAA4B,GAAsB,KAAK,CAAC;AAE9D,MAAM,UAAU,eAAe,CAA+B,IAAW;;IACvE,YAAO,MAAM,UAAW,SAAQ,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AE,CAAC;gBAChB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1B,CAAC;QACH,CAAC;WACF;AACH,CAAC","sourcesContent":["import { load as cheerioLoad } from 'cheerio';\nimport { type APIConstructor } from \".\";\nimport { type Product, type Post } from \"../../entities\";\nimport { type GetContentContext, type ContentListSortBy, type ContentType, type GetContentListParams } from \"../types/Content.js\";\nimport RawDataExtractor from '../web/utils/RawDataExtractor.js';\nimport { URLHelper } from '../../utils/index.js';\n\nconst DEFAULT_CONTENT_LIST_SIZE = 10;\nconst DEFAULT_CONTENT_LIST_SORT_BY: ContentListSortBy = 'a-z';\n\nexport function ContentAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class ContentAPI extends Base {\n getContentList<T extends ContentType>(params: GetContentListParams<T>) {\n const { sortBy = DEFAULT_CONTENT_LIST_SORT_BY, limit = DEFAULT_CONTENT_LIST_SIZE, offset = 0 } = params;\n const list = this.db.getContentList({\n ...params,\n sortBy,\n limit,\n offset,\n });\n for (const item of list.items) {\n switch (item.type) {\n case 'post':\n this.#processPostContentInlineMedia(item);\n item.content = this.sanitizeHTML(item.content || '');\n break;\n case 'product': {\n const description = RawDataExtractor.getProductRichTextDescription(item);\n item.description = description ? this.sanitizeHTML(description) : null;\n break;\n }\n }\n }\n return list;\n }\n\n getPost(id: string) {\n const post = this.db.getContent(id, 'post');\n if (post) {\n this.#processPostContentInlineMedia(post);\n post.content = this.sanitizeHTML(post.content || '');\n }\n return post;\n }\n\n getProduct(id: string) {\n return this.db.getContent(id, 'product');\n }\n\n getPreviousNextContent<T extends ContentType>(content: Post | Product, context: GetContentContext<T>) {\n return this.db.getPreviousNextContent(content, context);\n }\n\n #processPostContentInlineMedia(post: Post) {\n const html = post.content || '';\n const hasImages = post.images.length > 0;\n const hasLinkedAttachments = post.linkedAttachments && post.linkedAttachments.length > 0;\n if (!html || (!hasImages && !hasLinkedAttachments)) {\n return;\n }\n\n const $ = cheerioLoad(html);\n const replacedMediaIds: string[] = [];\n let hasModified = false;\n\n if (hasImages) {\n $('img').each((_, _el) => {\n const el = $(_el);\n const id = el.attr('data-media-id');\n const matched = id ? post.images.find(img => img.id === id && img.downloaded) : null;\n const src = matched ? `/media/${matched.id}` : el.attr('src');\n const imgEl = $('<img>').attr('src', src);\n const aEl = $('<a>')\n .attr('href', src)\n .attr('class', 'lightgallery-item')\n .append(imgEl);\n const wrapperEl = $('<div>')\n .attr('class', 'post-card__inline-media-wrapper')\n .append(aEl);\n if (!matched) {\n const caption = \"(Externally hosted - not stored locally)\";\n wrapperEl.append(\n $('<span>').attr('class', 'post-card__inline-media-caption').append(caption)\n );\n }\n el.replaceWith(wrapperEl);\n if (id && matched) {\n replacedMediaIds.push(id);\n }\n });\n if (replacedMediaIds.length > 0) {\n hasModified = true;\n // Remove images that have been inlined\n post.images = post.images.filter((img) => !replacedMediaIds.includes(img.id));\n }\n }\n\n // Linked attachments\n if (hasLinkedAttachments) {\n $('a').each((_, _el) => {\n const aEl = $(_el);\n const href = aEl.attr('href') || '';\n const { validated, ownerId, mediaId } = URLHelper.isAttachmentLink(href);\n if (validated) {\n let modifiedPath: string | undefined;\n if (post.id !== ownerId) {\n const isDownloaded = post.linkedAttachments?.find((att) => att.postId === ownerId && att.mediaId === mediaId)?.downloadable?.downloaded;\n modifiedPath = isDownloaded && `/media/${mediaId}?lapid=${post.id}`;\n }\n else {\n const isDownloaded = post.attachments.find((att) => att.id === mediaId)?.downloaded;\n modifiedPath = isDownloaded && `/media/${mediaId}`;\n }\n if (modifiedPath) {\n aEl.attr('href', modifiedPath);\n hasModified = true;\n }\n }\n });\n }\n\n if (hasModified) {\n post.content = $.html();\n }\n }\n }\n}"]}
|
|
@@ -2,10 +2,10 @@ import { type APIConstructor } from ".";
|
|
|
2
2
|
import { type FilterData, type MediaFilterSearchParams, type PostFilterSearchParams, type ProductFilterSearchParams } from "../types/Filter.js";
|
|
3
3
|
export declare function FilterAPIMixin<TBase extends APIConstructor>(Base: TBase): {
|
|
4
4
|
new (...args: any[]): {
|
|
5
|
-
getPostFilterData(campaignId: string):
|
|
5
|
+
getPostFilterData(campaignId: string): FilterData<PostFilterSearchParams>;
|
|
6
6
|
"__#134@#getPostTypeTitle"(postType: string): "Link" | "Audio" | "Image" | "Video" | "Other" | "Text" | "Podcast" | "Poll";
|
|
7
|
-
getProductFilterData(campaignId: string):
|
|
8
|
-
getMediaFilterData(campaignId: string):
|
|
7
|
+
getProductFilterData(campaignId: string): FilterData<ProductFilterSearchParams>;
|
|
8
|
+
getMediaFilterData(campaignId: string): FilterData<MediaFilterSearchParams>;
|
|
9
9
|
name: string;
|
|
10
10
|
db: import("../db").DBInstance;
|
|
11
11
|
logger?: import("../..").Logger | null;
|
|
@@ -11,13 +11,13 @@ export function FilterAPIMixin(Base) {
|
|
|
11
11
|
super(...arguments);
|
|
12
12
|
_FilterAPI_instances.add(this);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
const postCountByTier =
|
|
16
|
-
const postCountByType =
|
|
17
|
-
const postCountByYear =
|
|
14
|
+
getPostFilterData(campaignId) {
|
|
15
|
+
const postCountByTier = this.db.getPostCountByTier(campaignId);
|
|
16
|
+
const postCountByType = this.db.getPostCountByType(campaignId);
|
|
17
|
+
const postCountByYear = this.db.getContentCountByDate('post', 'year', {
|
|
18
18
|
campaign: campaignId
|
|
19
19
|
});
|
|
20
|
-
const postCountThisMonth = (
|
|
20
|
+
const postCountThisMonth = (this.db.getContentCountByDate('post', 'month', {
|
|
21
21
|
campaign: campaignId,
|
|
22
22
|
date: new Date()
|
|
23
23
|
}))[0];
|
|
@@ -136,11 +136,11 @@ export function FilterAPIMixin(Base) {
|
|
|
136
136
|
});
|
|
137
137
|
return { sections };
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
const productCountByYear =
|
|
139
|
+
getProductFilterData(campaignId) {
|
|
140
|
+
const productCountByYear = this.db.getContentCountByDate('product', 'year', {
|
|
141
141
|
campaign: campaignId
|
|
142
142
|
});
|
|
143
|
-
const productCountThisMonth = (
|
|
143
|
+
const productCountThisMonth = (this.db.getContentCountByDate('product', 'month', {
|
|
144
144
|
campaign: campaignId,
|
|
145
145
|
date: new Date()
|
|
146
146
|
}))[0];
|
|
@@ -210,13 +210,13 @@ export function FilterAPIMixin(Base) {
|
|
|
210
210
|
});
|
|
211
211
|
return { sections };
|
|
212
212
|
}
|
|
213
|
-
|
|
214
|
-
const mediaCountByTier =
|
|
215
|
-
const mediaCountByType =
|
|
216
|
-
const mediaCountByYear =
|
|
213
|
+
getMediaFilterData(campaignId) {
|
|
214
|
+
const mediaCountByTier = this.db.getMediaCountByTier(campaignId);
|
|
215
|
+
const mediaCountByType = this.db.getMediaCountByContentType(campaignId);
|
|
216
|
+
const mediaCountByYear = this.db.getMediaCountByDate('year', {
|
|
217
217
|
campaign: campaignId
|
|
218
218
|
});
|
|
219
|
-
const postCountThisMonth = (
|
|
219
|
+
const postCountThisMonth = (this.db.getMediaCountByDate('month', {
|
|
220
220
|
campaign: campaignId,
|
|
221
221
|
date: new Date()
|
|
222
222
|
}))[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/FilterAPIMixin.ts"],"names":[],"mappings":";;;;;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAKlD,MAAM,UAAU,cAAc,CAA+B,IAAW;;IACtE,YAAO,MAAM,SAAU,SAAQ,IAAI;YAA5B;;;YAyXP,CAAC;YAxXC,KAAK,CAAC,iBAAiB,CACrB,UAAkB;gBAElB,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;gBACrE,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;gBACrE,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,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BACjD,KAAK,EAAE,YAAY;qBACpB,CAAC,CAAC;gBACL,CAAC;gBACD,oBAAoB,CAAC,OAAO,CAAC;oBAC3B,KAAK,EAAE,UAAU;oBACjB,KAAK,EAAE,IAAI;oBACX,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAC;gBACH,QAAQ,CAAC,IAAI,CAAC;oBACZ,KAAK,EAAE,gBAAgB;oBACvB,WAAW,EAAE,MAAM;oBACnB,WAAW,EAAE,gBAAgB;oBAC7B,OAAO,EAAE,oBAAoB;iBAC9B,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC;SACF;;2EAjPmB,QAAgB;YAChC,QAAQ,QAAQ,EAAE,CAAC;gBACjB,KAAK,QAAQ,CAAC,KAAK;oBACjB,OAAO,OAAO,CAAC;gBACjB,KAAK,QAAQ,CAAC,KAAK;oBACjB,OAAO,OAAO,CAAC;gBACjB,KAAK,QAAQ,CAAC,IAAI;oBAChB,OAAO,MAAM,CAAC;gBAChB,KAAK,QAAQ,CAAC,OAAO;oBACnB,OAAO,SAAS,CAAC;gBACnB,KAAK,QAAQ,CAAC,IAAI;oBAChB,OAAO,MAAM,CAAC;gBAChB,KAAK,QAAQ,CAAC,IAAI;oBAChB,OAAO,MAAM,CAAC;gBAChB,KAAK,QAAQ,CAAC,KAAK,CAAC;gBACpB,KAAK,QAAQ,CAAC,UAAU;oBACtB,OAAO,OAAO,CAAC;gBACjB;oBACE,OAAO,OAAO,CAAC;YACnB,CAAC;QACH,CAAC;WA6NF;AACH,CAAC","sourcesContent":["import { type APIConstructor } from \".\";\nimport { PostType } from \"../../entities/Post.js\";\nimport { type FilterData, type FilterOption, type FilterSection, type MediaFilterSearchParams, type PostFilterSearchParams, type ProductFilterSearchParams } from \"../types/Filter.js\";\nimport { type ContentListSortBy } from \"../types/Content.js\";\nimport { type MediaListSortBy } from \"../types/Media.js\";\n\nexport function FilterAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class FilterAPI extends Base {\n async getPostFilterData(\n campaignId: string\n ): Promise<FilterData<PostFilterSearchParams>> {\n const postCountByTier = await this.db.getPostCountByTier(campaignId);\n const postCountByType = await this.db.getPostCountByType(campaignId);\n const postCountByYear = await this.db.getContentCountByDate('post', 'year', {\n campaign: campaignId\n });\n const postCountThisMonth = (await this.db.getContentCountByDate('post', 'month', {\n campaign: campaignId,\n date: new Date()\n }))[0];\n\n const sections: FilterSection<PostFilterSearchParams>[] = [];\n\n const postTypeRecords = postCountByType.map<FilterOption & { count: number; }>(({ postType, count }) => ({\n title: this.#getPostTypeTitle(postType),\n count,\n value: postType\n }))\n .reduce<Record<string, { count: number, value: string; }>>((result, option) => {\n if (option.value) {\n if (result[option.title]) {\n result[option.title].count += option.count;\n result[option.title].value += `,${option.value}`;\n }\n else {\n result[option.title] = { \n count: option.count,\n value: option.value\n };\n }\n }\n return result;\n }, {});\n const postTypeOptions: FilterOption[] = [];\n for (const [title, { count, value }] of Object.entries(postTypeRecords)) {\n postTypeOptions.push({\n title: `${title} (${count})`,\n value\n });\n }\n if (postTypeOptions.length > 0) {\n sections.push({\n title: 'Post type',\n displayHint: 'pill',\n searchParam: 'post_types',\n options: postTypeOptions\n });\n }\n\n const postAccessOptions: FilterOption[] = [\n {\n title: 'Posts you have access to',\n value: 'true',\n },\n {\n title: 'All posts',\n value: null,\n isDefault: true,\n }\n ];\n sections.push({\n title: 'Post access',\n displayHint: 'list',\n searchParam: 'is_viewable',\n options: postAccessOptions\n });\n\n const tierOptions = postCountByTier.map<FilterOption>(({tierId, title, count}) => ({\n title: `${title || (tierId === '-1' ? 'Public' : title)} (${count})`,\n value: tierId,\n }));\n tierOptions.unshift({\n title: 'Any tier',\n value: null,\n isDefault: true\n });\n sections.push({\n displayHint: 'list',\n searchParam: 'tier_ids',\n options: tierOptions\n });\n\n const sortByOptions: FilterOption[] = [\n {\n title: 'Latest',\n value: 'latest' satisfies ContentListSortBy,\n isDefault: true\n },\n {\n title: 'Oldest',\n value: 'oldest' satisfies ContentListSortBy,\n },\n {\n title: 'A-Z',\n value: 'a-z' satisfies ContentListSortBy,\n },\n {\n title: 'Z-A',\n value: 'z-a' satisfies ContentListSortBy,\n }\n ];\n sections.push({\n title: 'Sort by',\n displayHint: 'list',\n searchParam: 'sort_by',\n options: sortByOptions\n });\n\n const datePublishedOptions = postCountByYear.map<FilterOption>(({dt, count}) => ({\n title: `${dt} (${count})`,\n value: dt,\n }));\n if (postCountThisMonth?.count > 0) {\n datePublishedOptions.unshift({\n title: `This month (${postCountThisMonth.count})`,\n value: 'this_month',\n });\n }\n datePublishedOptions.unshift({\n title: 'Any date',\n value: null,\n isDefault: true\n });\n sections.push({\n title: 'Date published',\n displayHint: 'list',\n searchParam: 'date_published',\n options: datePublishedOptions\n });\n\n return { sections };\n }\n\n #getPostTypeTitle(postType: string) {\n switch (postType) {\n case PostType.Audio:\n return 'Audio';\n case PostType.Image:\n return 'Image';\n case PostType.Link:\n return 'Link';\n case PostType.Podcast:\n return 'Podcast';\n case PostType.Poll:\n return 'Poll';\n case PostType.Text:\n return 'Text';\n case PostType.Video:\n case PostType.VideoEmbed:\n return 'Video';\n default:\n return 'Other';\n }\n }\n\n async getProductFilterData(\n campaignId: string\n ): Promise<FilterData<ProductFilterSearchParams>> {\n const productCountByYear = await this.db.getContentCountByDate('product', 'year', {\n campaign: campaignId\n });\n const productCountThisMonth = (await this.db.getContentCountByDate('product', 'month', {\n campaign: campaignId,\n date: new Date()\n }))[0];\n\n const sections: FilterSection<ProductFilterSearchParams>[] = [];\n \n const productAccessOptions: FilterOption[] = [\n {\n title: 'Products you have access to',\n value: 'true',\n },\n {\n title: 'All products',\n value: null,\n isDefault: true,\n }\n ];\n sections.push({\n title: 'Product access',\n displayHint: 'list',\n searchParam: 'is_viewable',\n options: productAccessOptions\n });\n\n const sortByOptions: FilterOption[] = [\n {\n title: 'Latest',\n value: 'latest' satisfies ContentListSortBy,\n isDefault: true\n },\n {\n title: 'Oldest',\n value: 'oldest' satisfies ContentListSortBy,\n },\n {\n title: 'A-Z',\n value: 'a-z' satisfies ContentListSortBy,\n },\n {\n title: 'Z-A',\n value: 'z-a' satisfies ContentListSortBy,\n }\n ];\n sections.push({\n title: 'Sort by',\n displayHint: 'list',\n searchParam: 'sort_by',\n options: sortByOptions\n });\n\n const datePublishedOptions = productCountByYear.map<FilterOption>(({dt, count}) => ({\n title: `${dt} (${count})`,\n value: dt,\n }));\n if (productCountThisMonth?.count > 0) {\n datePublishedOptions.unshift({\n title: `This month ${productCountThisMonth.count}`,\n value: 'this_month',\n });\n }\n datePublishedOptions.unshift({\n title: 'Any date',\n value: null,\n isDefault: true\n });\n sections.push({\n title: 'Date published',\n displayHint: 'list',\n searchParam: 'date_published',\n options: datePublishedOptions\n });\n\n return { sections };\n }\n\n async getMediaFilterData(\n campaignId: string\n ): Promise<FilterData<MediaFilterSearchParams>> {\n const mediaCountByTier = await this.db.getMediaCountByTier(campaignId);\n const mediaCountByType = await this.db.getMediaCountByContentType(campaignId);\n const mediaCountByYear = await this.db.getMediaCountByDate('year', {\n campaign: campaignId\n });\n const postCountThisMonth = (await this.db.getMediaCountByDate('month', {\n campaign: campaignId,\n date: new Date()\n }))[0];\n\n const sections: FilterSection<MediaFilterSearchParams>[] = [];\n\n const sourceTypeRecords = mediaCountByType.map<FilterOption & { count: number; }>(({ contentType, count }) => ({\n title: contentType === 'post' ? 'Posts' : 'Products',\n count,\n value: contentType\n }))\n .reduce<Record<string, { count: number, value: string; }>>((result, option) => {\n if (option.value) {\n if (result[option.title]) {\n result[option.title].count += option.count;\n result[option.title].value += `,${option.value}`;\n }\n else {\n result[option.title] = { \n count: option.count,\n value: option.value\n };\n }\n }\n return result;\n }, {});\n const sourceTypeOptions: FilterOption[] = [];\n for (const [title, { count, value }] of Object.entries(sourceTypeRecords)) {\n sourceTypeOptions.push({\n title: `${title} (${count})`,\n value\n });\n }\n if (sourceTypeOptions.length > 0) {\n sections.push({\n title: 'Show media from',\n displayHint: 'pill',\n searchParam: 'source_type',\n options: sourceTypeOptions\n });\n }\n\n const mediaAccessOptions: FilterOption[] = [\n {\n title: 'Media you have access to',\n value: 'true',\n },\n {\n title: 'All media',\n value: null,\n isDefault: true,\n }\n ];\n sections.push({\n title: 'Media access',\n displayHint: 'list',\n searchParam: 'is_viewable',\n options: mediaAccessOptions\n });\n\n if (sourceTypeOptions.find((o) => o.value === 'post')) {\n const tierOptions = mediaCountByTier.map<FilterOption>(({tierId, title, count}) => ({\n title: `${title || (tierId === '-1' ? 'Public' : title)} (${count})`,\n value: tierId,\n }));\n tierOptions.unshift({\n title: 'Any tier',\n value: null,\n isDefault: true\n });\n const tierSection: FilterSection<MediaFilterSearchParams> = {\n displayHint: 'list',\n searchParam: 'tier_ids',\n options: tierOptions\n };\n const hasProductSourceType = sourceTypeOptions.find((o) => o.value === 'product');\n if (hasProductSourceType) {\n tierSection.enableCondition = {\n searchParam: 'source_type',\n condition: 'not',\n value: 'post'\n };\n }\n sections.push(tierSection);\n }\n\n const sortByOptions: FilterOption[] = [\n {\n title: 'Latest',\n value: 'latest' satisfies MediaListSortBy,\n isDefault: true\n },\n {\n title: 'Oldest',\n value: 'oldest' satisfies MediaListSortBy,\n }\n ];\n sections.push({\n title: 'Sort by',\n displayHint: 'list',\n searchParam: 'sort_by',\n options: sortByOptions\n });\n\n const datePublishedOptions = mediaCountByYear.map<FilterOption>(({dt, count}) => ({\n title: `${dt} (${count})`,\n value: dt,\n }));\n if (postCountThisMonth?.count > 0) {\n datePublishedOptions.unshift({\n title: `This month (${postCountThisMonth.count})`,\n value: 'this_month',\n });\n }\n datePublishedOptions.unshift({\n title: 'Any date',\n value: null,\n isDefault: true\n });\n sections.push({\n title: 'Date published',\n displayHint: 'list',\n searchParam: 'date_published',\n options: datePublishedOptions\n });\n\n return { sections };\n }\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"FilterAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/FilterAPIMixin.ts"],"names":[],"mappings":";;;;;AACA,OAA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B;oBACE,OAAO,OAAO,CAAC;YACnB,CAAC;QACH,CAAC;WA6NF;AACH,CAAC","sourcesContent":["import { type APIConstructor } from \".\";\nimport { PostType } from \"../../entities/Post.js\";\nimport { type FilterData, type FilterOption, type FilterSection, type MediaFilterSearchParams, type PostFilterSearchParams, type ProductFilterSearchParams } from \"../types/Filter.js\";\nimport { type ContentListSortBy } from \"../types/Content.js\";\nimport { type MediaListSortBy } from \"../types/Media.js\";\n\nexport function FilterAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class FilterAPI extends Base {\n getPostFilterData(\n campaignId: string\n ): FilterData<PostFilterSearchParams> {\n const postCountByTier = this.db.getPostCountByTier(campaignId);\n const postCountByType = this.db.getPostCountByType(campaignId);\n const postCountByYear = this.db.getContentCountByDate('post', 'year', {\n campaign: campaignId\n });\n const postCountThisMonth = (this.db.getContentCountByDate('post', 'month', {\n campaign: campaignId,\n date: new Date()\n }))[0];\n\n const sections: FilterSection<PostFilterSearchParams>[] = [];\n\n const postTypeRecords = postCountByType.map<FilterOption & { count: number; }>(({ postType, count }) => ({\n title: this.#getPostTypeTitle(postType),\n count,\n value: postType\n }))\n .reduce<Record<string, { count: number, value: string; }>>((result, option) => {\n if (option.value) {\n if (result[option.title]) {\n result[option.title].count += option.count;\n result[option.title].value += `,${option.value}`;\n }\n else {\n result[option.title] = { \n count: option.count,\n value: option.value\n };\n }\n }\n return result;\n }, {});\n const postTypeOptions: FilterOption[] = [];\n for (const [title, { count, value }] of Object.entries(postTypeRecords)) {\n postTypeOptions.push({\n title: `${title} (${count})`,\n value\n });\n }\n if (postTypeOptions.length > 0) {\n sections.push({\n title: 'Post type',\n displayHint: 'pill',\n searchParam: 'post_types',\n options: postTypeOptions\n });\n }\n\n const postAccessOptions: FilterOption[] = [\n {\n title: 'Posts you have access to',\n value: 'true',\n },\n {\n title: 'All posts',\n value: null,\n isDefault: true,\n }\n ];\n sections.push({\n title: 'Post access',\n displayHint: 'list',\n searchParam: 'is_viewable',\n options: postAccessOptions\n });\n\n const tierOptions = postCountByTier.map<FilterOption>(({tierId, title, count}) => ({\n title: `${title || (tierId === '-1' ? 'Public' : title)} (${count})`,\n value: tierId,\n }));\n tierOptions.unshift({\n title: 'Any tier',\n value: null,\n isDefault: true\n });\n sections.push({\n displayHint: 'list',\n searchParam: 'tier_ids',\n options: tierOptions\n });\n\n const sortByOptions: FilterOption[] = [\n {\n title: 'Latest',\n value: 'latest' satisfies ContentListSortBy,\n isDefault: true\n },\n {\n title: 'Oldest',\n value: 'oldest' satisfies ContentListSortBy,\n },\n {\n title: 'A-Z',\n value: 'a-z' satisfies ContentListSortBy,\n },\n {\n title: 'Z-A',\n value: 'z-a' satisfies ContentListSortBy,\n }\n ];\n sections.push({\n title: 'Sort by',\n displayHint: 'list',\n searchParam: 'sort_by',\n options: sortByOptions\n });\n\n const datePublishedOptions = postCountByYear.map<FilterOption>(({dt, count}) => ({\n title: `${dt} (${count})`,\n value: dt,\n }));\n if (postCountThisMonth?.count > 0) {\n datePublishedOptions.unshift({\n title: `This month (${postCountThisMonth.count})`,\n value: 'this_month',\n });\n }\n datePublishedOptions.unshift({\n title: 'Any date',\n value: null,\n isDefault: true\n });\n sections.push({\n title: 'Date published',\n displayHint: 'list',\n searchParam: 'date_published',\n options: datePublishedOptions\n });\n\n return { sections };\n }\n\n #getPostTypeTitle(postType: string) {\n switch (postType) {\n case PostType.Audio:\n return 'Audio';\n case PostType.Image:\n return 'Image';\n case PostType.Link:\n return 'Link';\n case PostType.Podcast:\n return 'Podcast';\n case PostType.Poll:\n return 'Poll';\n case PostType.Text:\n return 'Text';\n case PostType.Video:\n case PostType.VideoEmbed:\n return 'Video';\n default:\n return 'Other';\n }\n }\n\n getProductFilterData(\n campaignId: string\n ): FilterData<ProductFilterSearchParams> {\n const productCountByYear = this.db.getContentCountByDate('product', 'year', {\n campaign: campaignId\n });\n const productCountThisMonth = (this.db.getContentCountByDate('product', 'month', {\n campaign: campaignId,\n date: new Date()\n }))[0];\n\n const sections: FilterSection<ProductFilterSearchParams>[] = [];\n \n const productAccessOptions: FilterOption[] = [\n {\n title: 'Products you have access to',\n value: 'true',\n },\n {\n title: 'All products',\n value: null,\n isDefault: true,\n }\n ];\n sections.push({\n title: 'Product access',\n displayHint: 'list',\n searchParam: 'is_viewable',\n options: productAccessOptions\n });\n\n const sortByOptions: FilterOption[] = [\n {\n title: 'Latest',\n value: 'latest' satisfies ContentListSortBy,\n isDefault: true\n },\n {\n title: 'Oldest',\n value: 'oldest' satisfies ContentListSortBy,\n },\n {\n title: 'A-Z',\n value: 'a-z' satisfies ContentListSortBy,\n },\n {\n title: 'Z-A',\n value: 'z-a' satisfies ContentListSortBy,\n }\n ];\n sections.push({\n title: 'Sort by',\n displayHint: 'list',\n searchParam: 'sort_by',\n options: sortByOptions\n });\n\n const datePublishedOptions = productCountByYear.map<FilterOption>(({dt, count}) => ({\n title: `${dt} (${count})`,\n value: dt,\n }));\n if (productCountThisMonth?.count > 0) {\n datePublishedOptions.unshift({\n title: `This month ${productCountThisMonth.count}`,\n value: 'this_month',\n });\n }\n datePublishedOptions.unshift({\n title: 'Any date',\n value: null,\n isDefault: true\n });\n sections.push({\n title: 'Date published',\n displayHint: 'list',\n searchParam: 'date_published',\n options: datePublishedOptions\n });\n\n return { sections };\n }\n\n getMediaFilterData(\n campaignId: string\n ): FilterData<MediaFilterSearchParams> {\n const mediaCountByTier = this.db.getMediaCountByTier(campaignId);\n const mediaCountByType = this.db.getMediaCountByContentType(campaignId);\n const mediaCountByYear = this.db.getMediaCountByDate('year', {\n campaign: campaignId\n });\n const postCountThisMonth = (this.db.getMediaCountByDate('month', {\n campaign: campaignId,\n date: new Date()\n }))[0];\n\n const sections: FilterSection<MediaFilterSearchParams>[] = [];\n\n const sourceTypeRecords = mediaCountByType.map<FilterOption & { count: number; }>(({ contentType, count }) => ({\n title: contentType === 'post' ? 'Posts' : 'Products',\n count,\n value: contentType\n }))\n .reduce<Record<string, { count: number, value: string; }>>((result, option) => {\n if (option.value) {\n if (result[option.title]) {\n result[option.title].count += option.count;\n result[option.title].value += `,${option.value}`;\n }\n else {\n result[option.title] = { \n count: option.count,\n value: option.value\n };\n }\n }\n return result;\n }, {});\n const sourceTypeOptions: FilterOption[] = [];\n for (const [title, { count, value }] of Object.entries(sourceTypeRecords)) {\n sourceTypeOptions.push({\n title: `${title} (${count})`,\n value\n });\n }\n if (sourceTypeOptions.length > 0) {\n sections.push({\n title: 'Show media from',\n displayHint: 'pill',\n searchParam: 'source_type',\n options: sourceTypeOptions\n });\n }\n\n const mediaAccessOptions: FilterOption[] = [\n {\n title: 'Media you have access to',\n value: 'true',\n },\n {\n title: 'All media',\n value: null,\n isDefault: true,\n }\n ];\n sections.push({\n title: 'Media access',\n displayHint: 'list',\n searchParam: 'is_viewable',\n options: mediaAccessOptions\n });\n\n if (sourceTypeOptions.find((o) => o.value === 'post')) {\n const tierOptions = mediaCountByTier.map<FilterOption>(({tierId, title, count}) => ({\n title: `${title || (tierId === '-1' ? 'Public' : title)} (${count})`,\n value: tierId,\n }));\n tierOptions.unshift({\n title: 'Any tier',\n value: null,\n isDefault: true\n });\n const tierSection: FilterSection<MediaFilterSearchParams> = {\n displayHint: 'list',\n searchParam: 'tier_ids',\n options: tierOptions\n };\n const hasProductSourceType = sourceTypeOptions.find((o) => o.value === 'product');\n if (hasProductSourceType) {\n tierSection.enableCondition = {\n searchParam: 'source_type',\n condition: 'not',\n value: 'post'\n };\n }\n sections.push(tierSection);\n }\n\n const sortByOptions: FilterOption[] = [\n {\n title: 'Latest',\n value: 'latest' satisfies MediaListSortBy,\n isDefault: true\n },\n {\n title: 'Oldest',\n value: 'oldest' satisfies MediaListSortBy,\n }\n ];\n sections.push({\n title: 'Sort by',\n displayHint: 'list',\n searchParam: 'sort_by',\n options: sortByOptions\n });\n\n const datePublishedOptions = mediaCountByYear.map<FilterOption>(({dt, count}) => ({\n title: `${dt} (${count})`,\n value: dt,\n }));\n if (postCountThisMonth?.count > 0) {\n datePublishedOptions.unshift({\n title: `This month (${postCountThisMonth.count})`,\n value: 'this_month',\n });\n }\n datePublishedOptions.unshift({\n title: 'Any date',\n value: null,\n isDefault: true\n });\n sections.push({\n title: 'Date published',\n displayHint: 'list',\n searchParam: 'date_published',\n options: datePublishedOptions\n });\n\n return { sections };\n }\n }\n}"]}
|
|
@@ -3,7 +3,7 @@ import { type GetMediaListParams, type MediaList } from "../types/Media.js";
|
|
|
3
3
|
import { type ContentType } from "../types/Content.js";
|
|
4
4
|
export declare function MediaAPIMixin<TBase extends APIConstructor>(Base: TBase): {
|
|
5
5
|
new (...args: any[]): {
|
|
6
|
-
getMediaList<T extends ContentType>(params: GetMediaListParams<T>):
|
|
6
|
+
getMediaList<T extends ContentType>(params: GetMediaListParams<T>): MediaList<T>;
|
|
7
7
|
name: string;
|
|
8
8
|
db: import("../db").DBInstance;
|
|
9
9
|
logger?: import("../..").Logger | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/MediaAPIMixin.ts"],"names":[],"mappings":"AAIA,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,0BAA0B,GAAoB,QAAQ,CAAC;AAE7D,MAAM,UAAU,aAAa,CAA+B,IAAW;IACrE,OAAO,MAAM,QAAS,SAAQ,IAAI;QAChC,YAAY,CAAwB,MAA6B;YAC/D,MAAM,EAAE,MAAM,GAAG,0BAA0B,EAAE,KAAK,GAAG,uBAAuB,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC;YACpG,OAAO,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;gBAC1B,GAAG,MAAM;gBACT,MAAM;gBACN,KAAK;gBACL,MAAM;aACP,CAAC,CAAC;QACL,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { type APIConstructor } from \".\";\nimport { type GetMediaListParams, type MediaList, type MediaListSortBy } from \"../types/Media.js\";\nimport { type ContentType } from \"../types/Content.js\";\n\nconst DEFAULT_MEDIA_LIST_SIZE = 10;\nconst DEFAULT_MEDIA_LIST_SORT_BY: MediaListSortBy = 'latest';\n\nexport function MediaAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class MediaAPI extends Base {\n getMediaList<T extends ContentType>(params: GetMediaListParams<T>):
|
|
1
|
+
{"version":3,"file":"MediaAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/MediaAPIMixin.ts"],"names":[],"mappings":"AAIA,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,0BAA0B,GAAoB,QAAQ,CAAC;AAE7D,MAAM,UAAU,aAAa,CAA+B,IAAW;IACrE,OAAO,MAAM,QAAS,SAAQ,IAAI;QAChC,YAAY,CAAwB,MAA6B;YAC/D,MAAM,EAAE,MAAM,GAAG,0BAA0B,EAAE,KAAK,GAAG,uBAAuB,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC;YACpG,OAAO,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;gBAC1B,GAAG,MAAM;gBACT,MAAM;gBACN,KAAK;gBACL,MAAM;aACP,CAAC,CAAC;QACL,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { type APIConstructor } from \".\";\nimport { type GetMediaListParams, type MediaList, type MediaListSortBy } from \"../types/Media.js\";\nimport { type ContentType } from \"../types/Content.js\";\n\nconst DEFAULT_MEDIA_LIST_SIZE = 10;\nconst DEFAULT_MEDIA_LIST_SORT_BY: MediaListSortBy = 'latest';\n\nexport function MediaAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class MediaAPI extends Base {\n getMediaList<T extends ContentType>(params: GetMediaListParams<T>): MediaList<T> {\n const { sortBy = DEFAULT_MEDIA_LIST_SORT_BY, limit = DEFAULT_MEDIA_LIST_SIZE, offset = 0 } = params;\n return this.db.getMediaList({\n ...params,\n sortBy,\n limit,\n offset,\n });\n }\n }\n}"]}
|
|
@@ -2,12 +2,12 @@ import { type APIConstructor } from ".";
|
|
|
2
2
|
import { type BrowseSettingOptions, type BrowseSettings } from "../types/Settings.js";
|
|
3
3
|
export declare function SettingsAPIMixin<TBase extends APIConstructor>(Base: TBase): {
|
|
4
4
|
new (...args: any[]): {
|
|
5
|
-
getBrowseSettings():
|
|
5
|
+
getBrowseSettings(): {
|
|
6
6
|
theme: string;
|
|
7
7
|
listItemsPerPage: number;
|
|
8
8
|
galleryItemsPerPage: number;
|
|
9
|
-
}
|
|
10
|
-
saveBrowseSettings(settings: BrowseSettings):
|
|
9
|
+
};
|
|
10
|
+
saveBrowseSettings(settings: BrowseSettings): void;
|
|
11
11
|
getBrowseSettingOptions(): BrowseSettingOptions;
|
|
12
12
|
name: string;
|
|
13
13
|
db: import("../db").DBInstance;
|
|
@@ -45,8 +45,8 @@ const DEFAULT_BROWSE_SETTINGS = {
|
|
|
45
45
|
};
|
|
46
46
|
export function SettingsAPIMixin(Base) {
|
|
47
47
|
return class SettingsAPI extends Base {
|
|
48
|
-
|
|
49
|
-
const settings =
|
|
48
|
+
getBrowseSettings() {
|
|
49
|
+
const settings = this.db.getEnvValue(BROWSE_SETTINGS_ENV_KEY);
|
|
50
50
|
if (settings) {
|
|
51
51
|
return {
|
|
52
52
|
...DEFAULT_BROWSE_SETTINGS,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/SettingsAPIMixin.ts"],"names":[],"mappings":"AAGA,MAAM,uBAAuB,GAAG,iBAAiB,CAAC;AAElD,MAAM,MAAM,GAAkB;IAC5B;QACE,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,CAAC,iDAAiD,CAAC;KACjE;IACD,GAAG;QACD,OAAO;QACP,UAAU;QACV,OAAO;QACP,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,QAAQ;QACR,OAAO;QACP,KAAK;QACL,SAAS;QACT,OAAO;QACP,OAAO;QACP,OAAO;QACP,QAAQ;QACR,WAAW;QACX,SAAS;QACT,SAAS;QACT,OAAO;QACP,OAAO;QACP,UAAU;QACV,WAAW;QACX,QAAQ;QACR,OAAO;QACP,MAAM;QACN,QAAQ;KACT,CAAC,GAAG,CAAC,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;QAChF,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,CAAC,sBAAsB,mBAAmB,oBAAoB,CAAC;KAC7E,CAAC,CAAC;CACJ,CAAA;AAED,MAAM,uBAAuB,GAAmB;IAC9C,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;IACtB,gBAAgB,EAAE,EAAE;IACpB,mBAAmB,EAAE,GAAG;CACzB,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAA+B,IAAW;IACxE,OAAO,MAAM,WAAY,SAAQ,IAAI;QACnC,
|
|
1
|
+
{"version":3,"file":"SettingsAPIMixin.js","sourceRoot":"","sources":["../../../src/browse/api/SettingsAPIMixin.ts"],"names":[],"mappings":"AAGA,MAAM,uBAAuB,GAAG,iBAAiB,CAAC;AAElD,MAAM,MAAM,GAAkB;IAC5B;QACE,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,CAAC,iDAAiD,CAAC;KACjE;IACD,GAAG;QACD,OAAO;QACP,UAAU;QACV,OAAO;QACP,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,QAAQ;QACR,OAAO;QACP,KAAK;QACL,SAAS;QACT,OAAO;QACP,OAAO;QACP,OAAO;QACP,QAAQ;QACR,WAAW;QACX,SAAS;QACT,SAAS;QACT,OAAO;QACP,OAAO;QACP,UAAU;QACV,WAAW;QACX,QAAQ;QACR,OAAO;QACP,MAAM;QACN,QAAQ;KACT,CAAC,GAAG,CAAC,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;QAChF,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,CAAC,sBAAsB,mBAAmB,oBAAoB,CAAC;KAC7E,CAAC,CAAC;CACJ,CAAA;AAED,MAAM,uBAAuB,GAAmB;IAC9C,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;IACtB,gBAAgB,EAAE,EAAE;IACpB,mBAAmB,EAAE,GAAG;CACzB,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAA+B,IAAW;IACxE,OAAO,MAAM,WAAY,SAAQ,IAAI;QACnC,iBAAiB;YACf,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAiB,uBAAuB,CAAC,CAAC;YAC9E,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO;oBACL,GAAG,uBAAuB;oBAC1B,GAAG,QAAQ;iBACZ,CAAC;YACJ,CAAC;YACD,OAAO,EAAC,GAAG,uBAAuB,EAAC,CAAC;QACtC,CAAC;QAED,kBAAkB,CAAC,QAAwB;YACzC,OAAO,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC;QAED,uBAAuB;YACrB,OAAO;gBACL,MAAM,EAAE,MAAM;gBACd,gBAAgB,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;gBAClC,mBAAmB,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;aACzC,CAAC;QACJ,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { type APIConstructor } from \".\";\nimport { type BrowseSettingOptions, type BrowseSettings, type BrowseTheme } from \"../types/Settings.js\";\n\nconst BROWSE_SETTINGS_ENV_KEY = 'browse_settings';\n\nconst THEMES: BrowseTheme[] = [\n {\n name: 'Default',\n value: 'default',\n stylesheets: ['/themes/bootstrap/default/css/bootstrap.min.css']\n },\n ...[\n 'brite',\n 'cerulean',\n 'cosmo',\n 'cyborg',\n 'darkly',\n 'flatly',\n 'journal',\n 'litera',\n 'lumen',\n 'lux',\n 'materia',\n 'minty',\n 'morph',\n 'pulse',\n 'quartz',\n 'sandstone',\n 'simplex',\n 'sketchy',\n 'slate',\n 'solar',\n 'spacelab',\n 'superhero',\n 'united',\n 'vapor',\n 'yeti',\n 'zephyr'\n ].map((bootswatchThemeName) => ({\n name: bootswatchThemeName.charAt(0).toUpperCase() + bootswatchThemeName.slice(1),\n value: bootswatchThemeName,\n stylesheets: [`/themes/bootswatch/${bootswatchThemeName}/bootstrap.min.css`]\n }))\n]\n\nconst DEFAULT_BROWSE_SETTINGS: BrowseSettings = {\n theme: THEMES[0].value,\n listItemsPerPage: 20,\n galleryItemsPerPage: 100\n};\n\nexport function SettingsAPIMixin<TBase extends APIConstructor>(Base: TBase) {\n return class SettingsAPI extends Base {\n getBrowseSettings() {\n const settings = this.db.getEnvValue<BrowseSettings>(BROWSE_SETTINGS_ENV_KEY);\n if (settings) {\n return {\n ...DEFAULT_BROWSE_SETTINGS,\n ...settings\n };\n }\n return {...DEFAULT_BROWSE_SETTINGS};\n }\n\n saveBrowseSettings(settings: BrowseSettings) {\n return this.db.saveEnvValue(BROWSE_SETTINGS_ENV_KEY, settings);\n }\n\n getBrowseSettingOptions(): BrowseSettingOptions {\n return {\n themes: THEMES,\n listItemsPerPage: [10, 20, 30, 50],\n galleryItemsPerPage: [50, 100, 150, 200]\n };\n }\n }\n}"]}
|