Support copy pasting links in web app

This commit is contained in:
Brahim Hadriche committed 2023-10-27 16:32:11 -04:00
1 parent af020b509a
commit bde4523c00
2 files changed
+35 -18

No files matched your search

+1
View File
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Pagination support in web app search (load more button) - Pagination support in web app search (load more button)
- Video links pasted into the web app triggers the dialog to cast the video
## [0.14.0] - 2023-10-25 ## [0.14.0] - 2023-10-25
+34 -18
View File
@@ -30,13 +30,22 @@
onMount(async () => { onMount(async () => {
document.body.addEventListener("drop", onDrop); document.body.addEventListener("drop", onDrop);
document.body.addEventListener("dragover", onDragOver); document.body.addEventListener("dragover", onDragOver);
document.body.addEventListener("paste", onPaste);
}); });
onDestroy(() => { onDestroy(() => {
document.body.removeEventListener("drop", onDrop); document.body.removeEventListener("drop", onDrop);
document.body.removeEventListener("dragover", onDragOver); document.body.removeEventListener("dragover", onDragOver);
document.body.removeEventListener("paste", onPaste);
}); });
async function onPaste(event) {
modal.close();
const dataString = event.clipboardData.getData("text/plain");
await processUrlText(dataString);
}
async function onDrop(event) { async function onDrop(event) {
event.preventDefault(); event.preventDefault();
modal.close(); modal.close();
@@ -48,20 +57,24 @@
let dataString = (await new Promise((resolve) => let dataString = (await new Promise((resolve) =>
item.getAsString(resolve) item.getAsString(resolve)
)) as string; )) as string;
if (isValidHttpUrl(dataString)) { await processUrlText(dataString);
const videoInfo = parseYouTubeUrl(dataString); }
if (videoInfo.videoId) { }
searchForVideoById(videoInfo.videoId, videoInfo.timestamp); }
return;
} else { async function processUrlText(dataString: string) {
// TODO:P2 make a HEAD request and check for a redirect, then if (isValidHttpUrl(dataString)) {
// resolve the redirect url. const videoInfo = parseYouTubeUrl(dataString);
const urlInfo: any = await invidiousApi.resolveUrl(dataString); if (videoInfo.videoId) {
if (urlInfo && urlInfo.pageType === "WEB_PAGE_TYPE_CHANNEL") { searchForVideoById(videoInfo.videoId, videoInfo.timestamp);
searchForChannelById(urlInfo.ucid); return;
return; } else {
} // TODO:P2 make a HEAD request and check for a redirect, then
} // resolve the redirect url.
const urlInfo: any = await invidiousApi.resolveUrl(dataString);
if (urlInfo && urlInfo.pageType === "WEB_PAGE_TYPE_CHANNEL") {
searchForChannelById(urlInfo.ucid);
return;
} }
} }
} }
@@ -101,14 +114,17 @@
event.preventDefault(); event.preventDefault();
} }
function isValidHttpUrl(string) { function isValidHttpUrl(url) {
let url; if (!url) {
return false;
}
let urlObj;
try { try {
url = new URL(string); urlObj = new URL(url);
} catch (_) { } catch (_) {
return false; return false;
} }
return url.protocol === "http:" || url.protocol === "https:"; return urlObj.protocol === "http:" || urlObj.protocol === "https:";
} }
function parseYouTubeUrl(url) { function parseYouTubeUrl(url) {