|
1 | | -import type { OgConfig } from './og-types'; |
| 1 | +import type { OgConfig, OgDisplay, OgInputs } from './og-types'; |
2 | 2 |
|
3 | | -export type OgInputs = { |
4 | | - label?: string | null; |
5 | | - title?: string | null; |
6 | | - description?: string | null; |
7 | | - filename?: string | null; |
8 | | - size?: string | null; |
9 | | - fileCount?: number | null; |
10 | | -}; |
11 | | - |
12 | | -export type OgDisplay = { |
13 | | - label: string; |
14 | | - title: string; |
15 | | - subtitle: string; |
16 | | - footerTags?: string[]; |
17 | | -}; |
18 | | - |
19 | | -function trimOr(value: string | null | undefined, fallback: string) { |
20 | | - const cleaned = value?.trim(); |
21 | | - return cleaned ? cleaned : fallback; |
22 | | -} |
| 3 | +const trimOr = (value: string | null | undefined, fallback: string) => value?.trim() || fallback; |
23 | 4 |
|
24 | | -export function buildOgDisplay(config: OgConfig, inputs: OgInputs): OgDisplay { |
| 5 | +export const buildOgDisplay = (config: OgConfig, inputs: OgInputs): OgDisplay => { |
25 | 6 | const label = config.labelFromQuery ? trimOr(inputs.label, config.label) : config.label; |
26 | 7 |
|
27 | | - const title = config.usesFileMeta |
28 | | - ? trimOr(inputs.filename, 'Encrypted File').slice(0, 42) |
29 | | - : trimOr(inputs.title, config.title ?? 'Chithi').slice(0, 42); |
| 8 | + const title = ( |
| 9 | + config.usesFileMeta |
| 10 | + ? trimOr(inputs.filename, 'Encrypted File') |
| 11 | + : trimOr(inputs.title, config.title || 'Chithi') |
| 12 | + ).slice(0, 42); |
| 13 | + |
| 14 | + const fileCount = Number.isFinite(inputs.fileCount) ? inputs.fileCount : null; |
30 | 15 |
|
31 | | - const fileCount = |
32 | | - typeof inputs.fileCount === 'number' && Number.isFinite(inputs.fileCount) |
33 | | - ? inputs.fileCount |
34 | | - : null; |
35 | 16 | const fileCountLabel = fileCount && fileCount > 0 ? ` | Files: ${fileCount}` : ''; |
| 17 | + |
36 | 18 | const subtitle = config.usesFileMeta |
37 | 19 | ? `Size: ${trimOr(inputs.size, 'Unknown size')}${fileCountLabel}` |
38 | | - : trimOr(inputs.description, config.description ?? '').slice(0, 90); |
| 20 | + : trimOr(inputs.description, config.description || '').slice(0, 90); |
39 | 21 |
|
40 | 22 | return { |
41 | 23 | label, |
42 | 24 | title, |
43 | 25 | subtitle, |
44 | 26 | footerTags: config.footerTags |
45 | 27 | }; |
46 | | -} |
| 28 | +}; |
0 commit comments