From: Chocobozzz Date: Mon, 17 Sep 2018 08:12:30 +0000 (+0200) Subject: Handle actors search beginning with '@' X-Git-Tag: v1.0.0-beta.14~66 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2ff83ae2923aa93ccefb0fa989ae0bf138a46d77;p=oweals%2Fpeertube.git Handle actors search beginning with '@' Something like @toto@example.com --- diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 28a7a04ca..58851d0b5 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts @@ -56,6 +56,9 @@ function searchVideoChannels (req: express.Request, res: express.Response) { const isURISearch = search.startsWith('http://') || search.startsWith('https://') const parts = search.split('@') + + // Handle strings like @toto@example.com + if (parts.length === 3 && parts[0].length === 0) parts.shift() const isWebfingerSearch = parts.length === 2 && parts.every(p => p.indexOf(' ') === -1) if (isURISearch || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts index 10fcec462..156376943 100644 --- a/server/helpers/webfinger.ts +++ b/server/helpers/webfinger.ts @@ -12,7 +12,10 @@ const webfinger = new WebFinger({ request_timeout: 3000 }) -async function loadActorUrlOrGetFromWebfinger (uri: string) { +async function loadActorUrlOrGetFromWebfinger (uriArg: string) { + // Handle strings like @toto@example.com + const uri = uriArg.startsWith('@') ? uriArg.slice(1) : uriArg + const [ name, host ] = uri.split('@') let actor: ActorModel