Skip to content

Commit 5433f29

Browse files
authored
FIX dev branch error with loading youtube links that have no params (#570)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description This is a quick and dirty fix to youtube links not having parameters **This fixes a branch issue** #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. --> I have asked God for the solution
2 parents 748794c + e286911 commit 5433f29

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/app/components/url-preview/ClientPreview.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function parseYoutubeLink(url: string): YoutubeLink | null {
166166
if (url.includes('youtu.be')) {
167167
const split = path.split('?');
168168
[videoId] = split;
169-
params = split[1].split('&');
169+
params = split[1]?.split('&');
170170
} else {
171171
params = path.split('?')[1].split('&');
172172
videoId = params.find((s) => s.startsWith('v='), params)?.split('v=')[1];
@@ -175,8 +175,10 @@ function parseYoutubeLink(url: string): YoutubeLink | null {
175175
if (!videoId) return null;
176176

177177
// playlist is not used for the embed, it can be appended as is
178-
const playlist = params.find((s) => s.startsWith('list='), params);
179-
const timestamp = params.find((s) => s.startsWith('t='), params)?.split('t=')[1];
178+
const playlist = params ? params.find((s) => s.startsWith('list='), params) : undefined;
179+
const timestamp = params
180+
? params.find((s) => s.startsWith('t='), params)?.split('t=')[1]
181+
: undefined;
180182

181183
return {
182184
videoId,

0 commit comments

Comments
 (0)