mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support for Flickr album and group pool embeds (#3936)

* Support for Flickr album and group pool embeds

* Oops, forgot to add flickr to the persisted externalEmbeds schema

* Need a bigint since our id can have more than 52 bits...

* Remove unexpected trailing / from test data to match the expected behavior

* nits

---------

Co-authored-by: Hailey <me@haileyok.com>

authored by elfprince13.mumak.app

Hailey and committed by
GitHub
bd4703ca 891b432e

+157
+80
__tests__/lib/string.test.ts
··· 480 480 'https://media.tenor.com/someID/someName.gif', 481 481 'https://media.tenor.com/someID', 482 482 'https://media.tenor.com', 483 + 484 + 'https://www.flickr.com/photos/username/albums/72177720308493661', 485 + 'https://flickr.com/photos/username/albums/72177720308493661', 486 + 'https://flickr.com/photos/username/albums/72177720308493661/', 487 + 'https://flickr.com/photos/username/albums/72177720308493661//', 488 + 'https://flic.kr/s/aHBqjAES3i', 489 + 490 + 'https://flickr.com/foetoes/username/albums/3903', 491 + 'https://flickr.com/albums/3903', 492 + 'https://flic.kr/s/OolI', 493 + 'https://flic.kr/t/aHBqjAES3i', 494 + 495 + 'https://www.flickr.com/groups/898944@N23/pool', 496 + 'https://flickr.com/groups/898944@N23/pool', 497 + 'https://flickr.com/groups/898944@N23/pool/', 498 + 'https://flickr.com/groups/898944@N23/pool//', 499 + 'https://flic.kr/go/8WJtR', 500 + 501 + 'https://www.flickr.com/groups/898944@N23/', 502 + 'https://www.flickr.com/groups', 483 503 ] 484 504 485 505 const outputs = [ ··· 775 795 }, 776 796 undefined, 777 797 undefined, 798 + undefined, 799 + undefined, 800 + 801 + { 802 + type: 'flickr_album', 803 + source: 'flickr', 804 + playerUri: 'https://embedr.flickr.com/photosets/72177720308493661', 805 + }, 806 + { 807 + type: 'flickr_album', 808 + source: 'flickr', 809 + playerUri: 'https://embedr.flickr.com/photosets/72177720308493661', 810 + }, 811 + { 812 + type: 'flickr_album', 813 + source: 'flickr', 814 + playerUri: 'https://embedr.flickr.com/photosets/72177720308493661', 815 + }, 816 + { 817 + type: 'flickr_album', 818 + source: 'flickr', 819 + playerUri: 'https://embedr.flickr.com/photosets/72177720308493661', 820 + }, 821 + { 822 + type: 'flickr_album', 823 + source: 'flickr', 824 + playerUri: 'https://embedr.flickr.com/photosets/72177720308493661', 825 + }, 826 + 827 + undefined, 828 + undefined, 829 + undefined, 830 + undefined, 831 + 832 + { 833 + type: 'flickr_album', 834 + source: 'flickr', 835 + playerUri: 'https://embedr.flickr.com/groups/898944@N23', 836 + }, 837 + { 838 + type: 'flickr_album', 839 + source: 'flickr', 840 + playerUri: 'https://embedr.flickr.com/groups/898944@N23', 841 + }, 842 + { 843 + type: 'flickr_album', 844 + source: 'flickr', 845 + playerUri: 'https://embedr.flickr.com/groups/898944@N23', 846 + }, 847 + { 848 + type: 'flickr_album', 849 + source: 'flickr', 850 + playerUri: 'https://embedr.flickr.com/groups/898944@N23', 851 + }, 852 + { 853 + type: 'flickr_album', 854 + source: 'flickr', 855 + playerUri: 'https://embedr.flickr.com/groups/898944@N23', 856 + }, 857 + 778 858 undefined, 779 859 undefined, 780 860 ]
+76
src/lib/strings/embed-player.ts
··· 23 23 'vimeo', 24 24 'giphy', 25 25 'tenor', 26 + 'flickr', 26 27 ] as const 27 28 28 29 export type EmbedPlayerSource = (typeof embedPlayerSources)[number] ··· 42 43 | 'vimeo_video' 43 44 | 'giphy_gif' 44 45 | 'tenor_gif' 46 + | 'flickr_album' 45 47 46 48 export const externalEmbedLabels: Record<EmbedPlayerSource, string> = { 47 49 youtube: 'YouTube', ··· 53 55 spotify: 'Spotify', 54 56 appleMusic: 'Apple Music', 55 57 soundcloud: 'SoundCloud', 58 + flickr: 'Flickr', 56 59 } 57 60 58 61 export interface EmbedPlayerParams { ··· 373 376 playerUri: `https://t.gifs.bsky.app/${id}/${filename}`, 374 377 dimensions, 375 378 } 379 + } 380 + } 381 + 382 + // this is a standard flickr path! we can use the embedder for albums and groups, so validate the path 383 + if (urlp.hostname === 'www.flickr.com' || urlp.hostname === 'flickr.com') { 384 + let i = urlp.pathname.length - 1 385 + while (i > 0 && urlp.pathname.charAt(i) === '/') { 386 + --i 387 + } 388 + 389 + const path_components = urlp.pathname.slice(1, i + 1).split('/') 390 + if (path_components.length === 4) { 391 + // discard username - it's not relevant 392 + const [photos, _, albums, id] = path_components 393 + if (photos === 'photos' && albums === 'albums') { 394 + // this at least has the shape of a valid photo-album URL! 395 + return { 396 + type: 'flickr_album', 397 + source: 'flickr', 398 + playerUri: `https://embedr.flickr.com/photosets/${id}`, 399 + } 400 + } 401 + } 402 + 403 + if (path_components.length === 3) { 404 + const [groups, id, pool] = path_components 405 + if (groups === 'groups' && pool === 'pool') { 406 + return { 407 + type: 'flickr_album', 408 + source: 'flickr', 409 + playerUri: `https://embedr.flickr.com/groups/${id}`, 410 + } 411 + } 412 + } 413 + // not an album or a group pool, don't know what to do with this! 414 + return undefined 415 + } 416 + 417 + // link shortened flickr path 418 + if (urlp.hostname === 'flic.kr') { 419 + const b58alph = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' 420 + let [_, type, idBase58Enc] = urlp.pathname.split('/') 421 + let id = 0n 422 + for (const char of idBase58Enc) { 423 + const nextIdx = b58alph.indexOf(char) 424 + if (nextIdx >= 0) { 425 + id = id * 58n + BigInt(nextIdx) 426 + } else { 427 + // not b58 encoded, ergo not a valid link to embed 428 + return undefined 429 + } 430 + } 431 + 432 + switch (type) { 433 + case 'go': 434 + const formattedGroupId = `${id}` 435 + return { 436 + type: 'flickr_album', 437 + source: 'flickr', 438 + playerUri: `https://embedr.flickr.com/groups/${formattedGroupId.slice( 439 + 0, 440 + -2, 441 + )}@N${formattedGroupId.slice(-2)}`, 442 + } 443 + case 's': 444 + return { 445 + type: 'flickr_album', 446 + source: 'flickr', 447 + playerUri: `https://embedr.flickr.com/photosets/${id}`, 448 + } 449 + default: 450 + // we don't know what this is so we can't embed it 451 + return undefined 376 452 } 377 453 } 378 454 }
+1
src/state/persisted/schema.ts
··· 65 65 spotify: z.enum(externalEmbedOptions).optional(), 66 66 appleMusic: z.enum(externalEmbedOptions).optional(), 67 67 soundcloud: z.enum(externalEmbedOptions).optional(), 68 + flickr: z.enum(externalEmbedOptions).optional(), 68 69 }) 69 70 .optional(), 70 71 mutedThreads: z.array(z.string()), // should move to server