mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +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;
|
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) => {
|
Helpers.query = async (id) => {
|
||||||
const [username, hostname] = id.split('@');
|
const [username, hostname] = id.split('@');
|
||||||
if (!username || !hostname) {
|
if (!username || !hostname) {
|
||||||
@@ -71,13 +79,7 @@ Helpers.resolveLocalUid = async (input) => {
|
|||||||
if (process.env.CI === 'true') {
|
if (process.env.CI === 'true') {
|
||||||
protocols.push('http');
|
protocols.push('http');
|
||||||
}
|
}
|
||||||
if (validator.isURL(input, {
|
if (Helpers.isUri(input)) {
|
||||||
require_protocol: true,
|
|
||||||
require_host: true,
|
|
||||||
require_tld: false,
|
|
||||||
protocols,
|
|
||||||
require_valid_protocol: true,
|
|
||||||
})) {
|
|
||||||
const { host, pathname } = new URL(input);
|
const { host, pathname } = new URL(input);
|
||||||
|
|
||||||
if (host === nconf.get('url_parsed').host) {
|
if (host === nconf.get('url_parsed').host) {
|
||||||
|
|||||||
@@ -18,13 +18,7 @@ ActivityPub.inbox = require('./inbox');
|
|||||||
ActivityPub.getActor = async (input) => {
|
ActivityPub.getActor = async (input) => {
|
||||||
// Can be a webfinger id, uri, or object, handle as appropriate
|
// Can be a webfinger id, uri, or object, handle as appropriate
|
||||||
let uri;
|
let uri;
|
||||||
if (validator.isURL(input, {
|
if (ActivityPub.helpers.isUri(input)) {
|
||||||
require_protocol: true,
|
|
||||||
require_host: true,
|
|
||||||
protocols: ['https'],
|
|
||||||
require_valid_protocol: true,
|
|
||||||
require_tld: false,
|
|
||||||
})) {
|
|
||||||
uri = input;
|
uri = input;
|
||||||
} else if (input.indexOf('@') !== -1) { // Webfinger
|
} else if (input.indexOf('@') !== -1) { // Webfinger
|
||||||
({ actorUri: uri } = await ActivityPub.helpers.query(input));
|
({ actorUri: uri } = await ActivityPub.helpers.query(input));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const _ = require('lodash');
|
|||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const activitypub = require('../activitypub');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
const relative_path = nconf.get('relative_path');
|
const relative_path = nconf.get('relative_path');
|
||||||
|
|||||||
Reference in New Issue
Block a user