mirror of
https://github.com/imputnet/cobalt.git
synced 2026-05-23 14:51:22 -05:00
[GH-ISSUE #364] Search for beginning of URL instead of accepting all text in input as URL #9048
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @RubyMetro on GitHub (Feb 20, 2024).
Original GitHub issue: https://github.com/imputnet/cobalt/issues/364
Instead of accepting all input in the text field as the URL, instead do a string search to find the beginning of the URL within the input and take in only the link.
Additional context: TikTok recently changed the way they copy links to your clipboard when you use the sharing feature inside of their app, instead of copying only the link to the clipboard they now copy statistics and tags (e.g. 4M likes, 35.2K comments, Bye bye https://www.tiktok.com/t/ZT8KmUpa7/ instead of just https://www.tiktok.com/t/ZT8KmUpa7/) so to download anything from TikTok correctly you have to paste the clipboard contents somewhere first and copy only the link.
@RubyMetro commented on GitHub (Feb 20, 2024):
Also I’m not sure how easy something like this would be to implement because I’m ✨a college freshman✨ so if this isn’t realistic please close this.
@Laurens256 commented on GitHub (Feb 22, 2024):
Could potentially add something like this but I'm not sure what kind of links need to be supported
via https://stackoverflow.com/a/3809435/16071690
feel free to use if anyone wants to implement this
Edit: just realized a similar regex is already being used, should not be too hard to implement this then. I think a good implementation of this would be to show some kind of small popover button with the found URL if a URL is detected within the input but the
URL !== input, then when clicking the popover, input is replaced by the URL@RubyMetro commented on GitHub (Feb 23, 2024):
you're right now that I'm looking that regex pattern looks to work perfectly fine, and I think that would be a good solution to this problem, something like "did you mean: https://www.tiktok.com/blahblahblah" but unfortunately I can't tell if this is pure html/css/js or a web app framework that I haven't used before. Wukko ily sm but please comment your code 😭💔
edit! found the html. maybe I'll see if I can do something with this
edit 2: (I am not guaranteeing anything I am a student and I barely have time to take a nap let alone fix an issue that TikTok caused out of spite... maybe though.. just maybe....)
@lostdusty commented on GitHub (Feb 23, 2024):
Well this doesn't really work:

However, this regex from my library should work with every link:

@RubyMetro commented on GitHub (Feb 23, 2024):
The regex pattern already in cobalt works for all links that I’ve tested from TikTok, and I haven’t looked very hard into it but what I think it might be doing is just testing if the url equals what the regex pattern returns to tell the user if there are invalid characters instead of attempting to download only the url in the string of text. I like what Laurens256 suggested with adding a pop up with the url extracted from the entire input with a button that replaces the input with just the actual URL
@wukko commented on GitHub (Feb 24, 2024):
frontend is a huge mess rn and will be redone completely for future major version (once i win over this damn cold)
@RubyMetro commented on GitHub (Feb 24, 2024):
get well soon :3
@lostdusty commented on GitHub (Feb 24, 2024):
The cobalt regex didn't work with the provided example from the issue. But yes, the code checks if the text input passes on the regex, if it does = downloads the media.
I forgot to say, but i edited the code slighty in the frontend so it removes every text, except the url itself. I think the only issue is there links that doesnt have
https://on them, should be a easy fix tho. I'll investigate more.@RubyMetro commented on GitHub (Feb 24, 2024):
@lostdusty ahhh gotcha, I could have sworn that regex had passed. I'll look into that later when I have some time
@Laurens256 commented on GitHub (Feb 26, 2024):
ahh, I didn't really test the regex my bad, was more meant as a proof of concept how the functionality could work. Concept could still be really useful if there's a regex we can use that doesn't give too many false positives like the one you provided