Fix Webfinger link resource
FossilOrigin-Name: 9ea701d53b503d124c996852004950187e609b79c6ac3ce7ed110d30d5936a48
This commit is contained in:
parent
bf91f46985
commit
2ed52959f8
2 changed files with 37 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "http/responsecode.h"
|
||||
#include "user.h"
|
||||
#include "webfinger.h"
|
||||
#include "stringhelper.h"
|
||||
#include "http/httpserver.h"
|
||||
#include "http/request.h"
|
||||
#include "logger.h"
|
||||
|
@ -80,12 +81,20 @@ HTTP::Response Route::webfinger(std::any& args, const HTTP::Request& req, const
|
|||
// Perform multiple different Resource formats
|
||||
// TODO separate into functions?
|
||||
constexpr std::string_view acct_prefix = "acct:";
|
||||
static const std::string acct_suffix = "@" + Config::instance().config.instance.host;
|
||||
static const std::string local_host_prefix = Instance::instance_host_https(true) + "users/";
|
||||
static const std::string at_prefix = Instance::instance_host_https(true) + "@";
|
||||
|
||||
// Standard "acct:" prefix check
|
||||
if (!resource.compare(0, acct_prefix.size(), acct_prefix))
|
||||
{
|
||||
if (StringHelper::ends_with(resource, acct_suffix))
|
||||
{
|
||||
size_t n = resource.find(acct_suffix);
|
||||
resource = resource.substr(0, n);
|
||||
}
|
||||
acct_str = resource.substr(acct_prefix.size());
|
||||
}
|
||||
else if (!resource.compare(0, local_host_prefix.size(), local_host_prefix)) // Instance host
|
||||
acct_str = resource.substr(local_host_prefix.size());
|
||||
else if (!resource.compare(0, at_prefix.size(), at_prefix)) // At prefix
|
||||
|
|
28
src/stringhelper.h
Normal file
28
src/stringhelper.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Wormhole - Federated social network
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace StringHelper
|
||||
{
|
||||
inline bool ends_with(const std::string& value, const std::string& ending)
|
||||
{
|
||||
if (ending.size() > value.size()) return false;
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue