Add optional parameters object to `getPeertubeVideoURL`
At first I just wanted to make the isEmbed optional (default `false`), but I thought it would be more future-proof to wrap it in an object. Now when it's not needed, it's not there, and when it is, it's clear what it does.
This commit is contained in:
parent
104598477e
commit
bcec17a0a2
|
@ -47,7 +47,7 @@ const redirectYoutube = async (r) => {
|
||||||
|
|
||||||
const title = await getTitle(query);
|
const title = await getTitle(query);
|
||||||
const video = await searchByName(title);
|
const video = await searchByName(title);
|
||||||
const url = getPeertubeVideoURL(video, prefs, isEmbed);
|
const url = getPeertubeVideoURL(video, prefs, { isEmbed });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
redirectUrl: url
|
redirectUrl: url
|
||||||
|
@ -77,7 +77,7 @@ const redirectPeertube = async (r) => {
|
||||||
return {}; // Don't redirect if original instance
|
return {}; // Don't redirect if original instance
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = getPeertubeVideoURL(video, prefs, isEmbed);
|
const url = getPeertubeVideoURL(video, prefs, { isEmbed });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
redirectUrl: url
|
redirectUrl: url
|
||||||
|
|
|
@ -48,7 +48,7 @@ async function peertubeify() {
|
||||||
case RedirectType.Show: {
|
case RedirectType.Show: {
|
||||||
searchVideo()
|
searchVideo()
|
||||||
.then(async video => {
|
.then(async video => {
|
||||||
const link = videoLink(getPeertubeVideoURL(video, prefs, false), video);
|
const link = videoLink(getPeertubeVideoURL(video, prefs), video);
|
||||||
removeVideoLink();
|
removeVideoLink();
|
||||||
document.querySelector('body').appendChild(link);
|
document.querySelector('body').appendChild(link);
|
||||||
}).catch(removeVideoLink);
|
}).catch(removeVideoLink);
|
||||||
|
|
|
@ -4,7 +4,7 @@ export function htmlToElement(html: string): Element {
|
||||||
return template.content.firstElementChild;
|
return template.content.firstElementChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPeertubeVideoURL(video, prefs, isEmbed) {
|
export function getPeertubeVideoURL(video, prefs, { isEmbed = false } = {}) {
|
||||||
const endpoint = isEmbed ? 'embed' : 'watch';
|
const endpoint = isEmbed ? 'embed' : 'watch';
|
||||||
|
|
||||||
return `https://${getPeertubeHost(video.account.host, prefs)}/videos/${endpoint}/${video.uuid}`;
|
return `https://${getPeertubeHost(video.account.host, prefs)}/videos/${endpoint}/${video.uuid}`;
|
||||||
|
|
|
@ -39,7 +39,7 @@ async function peertubeify(query: String) {
|
||||||
case RedirectType.Show: {
|
case RedirectType.Show: {
|
||||||
searchVideo(query)
|
searchVideo(query)
|
||||||
.then(async video => {
|
.then(async video => {
|
||||||
const url = getPeertubeVideoURL(video, prefs, false)
|
const url = getPeertubeVideoURL(video, prefs)
|
||||||
const link = videoLink(url, video);
|
const link = videoLink(url, video);
|
||||||
|
|
||||||
removeVideoLink();
|
removeVideoLink();
|
||||||
|
|
Loading…
Reference in New Issue