mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
refactor: validator check to helper method
This commit is contained in:
@@ -14,6 +14,14 @@ const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
|
||||
|
||||
const Helpers = module.exports;
|
||||
|
||||
Helpers.isUri = value => validator.isURL(value, {
|
||||
require_protocol: true,
|
||||
require_host: true,
|
||||
protocols: ['https'],
|
||||
require_valid_protocol: true,
|
||||
require_tld: false, // temporary — for localhost
|
||||
});
|
||||
|
||||
Helpers.query = async (id) => {
|
||||
const [username, hostname] = id.split('@');
|
||||
if (!username || !hostname) {
|
||||
@@ -71,13 +79,7 @@ Helpers.resolveLocalUid = async (input) => {
|
||||
if (process.env.CI === 'true') {
|
||||
protocols.push('http');
|
||||
}
|
||||
if (validator.isURL(input, {
|
||||
require_protocol: true,
|
||||
require_host: true,
|
||||
require_tld: false,
|
||||
protocols,
|
||||
require_valid_protocol: true,
|
||||
})) {
|
||||
if (Helpers.isUri(input)) {
|
||||
const { host, pathname } = new URL(input);
|
||||
|
||||
if (host === nconf.get('url_parsed').host) {
|
||||
|
||||
@@ -18,13 +18,7 @@ ActivityPub.inbox = require('./inbox');
|
||||
ActivityPub.getActor = async (input) => {
|
||||
// Can be a webfinger id, uri, or object, handle as appropriate
|
||||
let uri;
|
||||
if (validator.isURL(input, {
|
||||
require_protocol: true,
|
||||
require_host: true,
|
||||
protocols: ['https'],
|
||||
require_valid_protocol: true,
|
||||
require_tld: false,
|
||||
})) {
|
||||
if (ActivityPub.helpers.isUri(input)) {
|
||||
uri = input;
|
||||
} else if (input.indexOf('@') !== -1) { // Webfinger
|
||||
({ actorUri: uri } = await ActivityPub.helpers.query(input));
|
||||
|
||||
@@ -7,6 +7,7 @@ const _ = require('lodash');
|
||||
const db = require('../database');
|
||||
const meta = require('../meta');
|
||||
const plugins = require('../plugins');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
|
||||
const relative_path = nconf.get('relative_path');
|
||||
|
||||
Reference in New Issue
Block a user