Skip to content

Commit 8b4dde3

Browse files
committed
Implement story assets link generation
1 parent 2365010 commit 8b4dde3

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

modules/Story/Share/Share.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { translations, useIntl } from '@prezly/theme-kit-nextjs/index';
44
import classNames from 'classnames';
55

6-
import { Button } from '@/components/Button';
6+
import { Button, ButtonLink } from '@/components/Button';
77
import { Divider } from '@/components/Divider';
88
import { SocialShare } from '@/components/SocialShare';
99
import { IconFileDown, IconFolderDown, IconLink, IconText } from '@/icons';
@@ -13,15 +13,25 @@ import type { SharingOptions } from '../type';
1313

1414
import { ButtonWithSuccessTooltip } from './ButtonWithSuccessTooltip';
1515
import styles from './Share.module.scss';
16+
import { getAssetsArchiveDownloadUrl } from './utils/getAssetsArchiveDownloadUrl';
1617

1718
interface Props {
1819
actions?: StoryActions;
1920
sharingOptions: SharingOptions;
2021
thumbnailUrl?: string;
2122
url: string;
23+
uploadcareAssetsGroupUuid: string | null;
24+
slug: string;
2225
}
2326

24-
export function Share({ actions, thumbnailUrl, sharingOptions, url }: Props) {
27+
export function Share({
28+
actions,
29+
uploadcareAssetsGroupUuid,
30+
thumbnailUrl,
31+
sharingOptions,
32+
url,
33+
slug,
34+
}: Props) {
2535
const { formatMessage } = useIntl();
2636
const socialNetworks = sharingOptions.sharing_actions;
2737
const socialShareButtonsCount = socialNetworks.length;
@@ -31,6 +41,9 @@ export function Share({ actions, thumbnailUrl, sharingOptions, url }: Props) {
3141
actions?.show_download_assets,
3242
actions?.show_download_pdf,
3343
].filter(Boolean).length;
44+
const assetsUrl = uploadcareAssetsGroupUuid
45+
? getAssetsArchiveDownloadUrl(uploadcareAssetsGroupUuid, slug)
46+
: undefined;
3447

3548
function handleCopyLink() {
3649
window.navigator.clipboard.writeText(url);
@@ -85,14 +98,15 @@ export function Share({ actions, thumbnailUrl, sharingOptions, url }: Props) {
8598
</ButtonWithSuccessTooltip>
8699
)}
87100

88-
{actions.show_download_assets && (
89-
<Button
101+
{actions.show_download_assets && assetsUrl && (
102+
<ButtonLink
103+
href={assetsUrl}
90104
className={styles.action}
91105
icon={IconFolderDown}
92106
variation="secondary"
93107
>
94108
Download assets
95-
</Button>
109+
</ButtonLink>
96110
)}
97111

98112
{actions.show_download_pdf && (
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const ASSETS_CDN_URL = 'https://cdn.uc.assets.prezly.com';
2+
3+
export function getAssetsArchiveDownloadUrl(assetsGroupUuid: string, slug: string): string {
4+
const safeSlug = encodeURIComponent(slug.replace(/\//g, '_'));
5+
return `${ASSETS_CDN_URL}/${assetsGroupUuid}/archive/zip/${safeSlug}.zip`;
6+
}

modules/Story/Story.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ type Props = {
2828
};
2929

3030
export async function Story({ actions, sharingOptions, showDate, story, withHeaderImage }: Props) {
31-
const { links, visibility, thumbnail_url: thumbnailUrl } = story;
31+
const {
32+
links,
33+
visibility,
34+
thumbnail_url: thumbnailUrl,
35+
uploadcare_assets_group_uuid,
36+
slug,
37+
} = story;
3238
const nodes = JSON.parse(story.content);
3339
const [headerImageDocument, mainDocument] = pullHeaderImageNode(nodes, withHeaderImage);
3440
const sharingUrl = links.short || links.newsroom_view;
@@ -76,7 +82,9 @@ export async function Story({ actions, sharingOptions, showDate, story, withHead
7682
actions={actions}
7783
sharingOptions={sharingOptions}
7884
thumbnailUrl={thumbnailUrl}
85+
uploadcareAssetsGroupUuid={uploadcare_assets_group_uuid}
7986
url={sharingUrl}
87+
slug={slug}
8088
/>
8189
)}
8290
</div>

0 commit comments

Comments
 (0)