From 92c6841cd324e2925967546bcc8563f332fd8944 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:02:27 +0000 Subject: [PATCH] support handles for channel request? --- src/utils/consts.js | 2 ++ src/views/AddChannelRequest.vue | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/utils/consts.js b/src/utils/consts.js index c2979fc43..ba980d613 100644 --- a/src/utils/consts.js +++ b/src/utils/consts.js @@ -60,6 +60,8 @@ export const ORGS_PREFIX = Object.freeze({ export const CHANNEL_URL_REGEX = /(?:(?:https?:|)\/\/|)(?:www\.|)(?:youtube\.com\/|\/?)channel\/(?[\w-]+)/i; +export const CHANNEL_OR_HANDLE_REGEX = /(?:(?:https?:|)\/\/|)(?:www\.|)(?:youtube\.com\/|\/?)(?:channel\/|@)(?[\w-]+)/i; + export const VIDEO_URL_REGEX = /(?:(?:https?:|)\/\/|)((?:www|m)\.|)(?youtube\.com|youtu\.be|holodex\.net)\/(?:[\w-]+\?v=|embed|v|watch|live|)\/?(?[\w-]{11})/i; export const TWITCH_VIDEO_URL_REGEX = /(?:(?:https?:|)\/\/|)twitch\.tv\/(?[\w-]+)/i; diff --git a/src/views/AddChannelRequest.vue b/src/views/AddChannelRequest.vue index 587fe49f2..d0f59520d 100644 --- a/src/views/AddChannelRequest.vue +++ b/src/views/AddChannelRequest.vue @@ -41,8 +41,8 @@ v-else v-model="link" label="Channel URL" - placeholder="https://www.youtube.com/channel/UC_____" - hint="https://www.youtube.com/channel/UC_____" + placeholder="https://www.youtube.com/channel/UC_____ or https://www.youtube.com/@_____" + hint="https://www.youtube.com/channel/UC_____ or https://www.youtube.com/@_____" :rules="[channelURLRule]" /> !!v.match(/^https?:\/\/[\w-]+(\.[\w-]+)+\.?(\/\S*)?/) || "Invalid url", twitterRule: (v) => !v || !!v.match(/^@.*$/) || "@ABC", channelURLRule(v) { - const REGEX = /(?:https?:\/\/)(?:www\.)?youtu(?:be\.com\/)(?:channel)\/([\w-_]*)$/i; + const REGEX = /(?:https?:\/\/)(?:www\.)?youtu(?:be\.com\/)(?:channel\/|@)([\w-_]*)$/i; const cid = v.match(REGEX); console.log(cid); return ( (cid && !cid[0].includes("/c/") - && cid[1].length > 12 + && (cid[1].length > 12 or cid[0].endsWith('@')) && cid[0].startsWith("ht")) || this.$t("channelRequest.ChannelURLErrorFeedback") ); @@ -264,16 +264,19 @@ export default { }, async onSubmit() { + let handle = null; if (this.type === ADD_VTUBER || this.type === ADD_CLIPPER) { // validate it's not added already: - const regex = /(?:https?:\/\/)(?:www\.)?youtu(?:be\.com\/)(?:channel)\/([\w\-_]*)/gi; + const regex = /(?:https?:\/\/)(?:www\.)?youtu(?:be\.com\/)(?:channel\/|@)([\w\-_]*)/gi; const matches = [...this.link.matchAll(regex)]; - const id = matches?.[0]?.[1]; + let id = matches?.[0]?.[1]; + handle = matches[0][0].endsWith('@') + id = handle ? '@' + id : id; try { const exists = id && (await backendApi.channel(id)); if (exists && exists.data && exists.data.id) { - this.$router.push({ path: `/channel/${id}` }); + this.$router.push({ path: `/channel/${exists.data.id}` }); return; } } catch (e) { @@ -302,7 +305,9 @@ export default { name: "Channel Link", value: this.link - || `https://www.youtube.com/channel/${this.channel.id}`, + || handle + ? `https://www.youtube.com/@${id}` + : `https://www.youtube.com/channel/${this.channel.id}`, inline: false, }, ...ifValid(this.english_name, {