mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 11:17:29 +02:00
feat: allow use of vanity domains pointing to an account hosted elsewhere
This commit is contained in:
@@ -36,6 +36,7 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
ids = ids.filter(id => !utils.isNumber(id));
|
ids = ids.filter(id => !utils.isNumber(id));
|
||||||
|
|
||||||
// Translate webfinger handles to uris
|
// Translate webfinger handles to uris
|
||||||
|
const hostMap = new Map();
|
||||||
ids = (await Promise.all(ids.map(async (id) => {
|
ids = (await Promise.all(ids.map(async (id) => {
|
||||||
const originalId = id;
|
const originalId = id;
|
||||||
if (activitypub.helpers.isWebfinger(id)) {
|
if (activitypub.helpers.isWebfinger(id)) {
|
||||||
@@ -45,6 +46,7 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
({ actorUri: id } = await activitypub.helpers.query(id));
|
({ actorUri: id } = await activitypub.helpers.query(id));
|
||||||
|
hostMap.set(id, host);
|
||||||
}
|
}
|
||||||
// ensure the final id is a valid URI
|
// ensure the final id is a valid URI
|
||||||
if (!id || !activitypub.helpers.isUri(id)) {
|
if (!id || !activitypub.helpers.isUri(id)) {
|
||||||
@@ -130,7 +132,7 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
actors = actors.filter(Boolean); // remove unresolvable actors
|
actors = actors.filter(Boolean); // remove unresolvable actors
|
||||||
|
|
||||||
// Build userData object for storage
|
// Build userData object for storage
|
||||||
const profiles = (await activitypub.mocks.profile(actors)).filter(Boolean);
|
const profiles = (await activitypub.mocks.profile(actors, hostMap)).filter(Boolean);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const bulkSet = profiles.reduce((memo, profile) => {
|
const bulkSet = profiles.reduce((memo, profile) => {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const sanitizeConfig = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Mocks.profile = async (actors) => {
|
Mocks.profile = async (actors, hostMap) => {
|
||||||
// Should only ever be called by activitypub.actors.assert
|
// Should only ever be called by activitypub.actors.assert
|
||||||
const profiles = await Promise.all(actors.map(async (actor) => {
|
const profiles = await Promise.all(actors.map(async (actor) => {
|
||||||
if (!actor) {
|
if (!actor) {
|
||||||
@@ -37,18 +37,20 @@ Mocks.profile = async (actors) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uid = actor.id;
|
const uid = actor.id;
|
||||||
let hostname;
|
let hostname = hostMap.get(uid);
|
||||||
let {
|
let {
|
||||||
url, preferredUsername, published, icon, image,
|
url, preferredUsername, published, icon, image,
|
||||||
name, summary, followers, inbox, endpoints,
|
name, summary, followers, inbox, endpoints,
|
||||||
} = actor;
|
} = actor;
|
||||||
preferredUsername = preferredUsername || slugify(name);
|
preferredUsername = slugify(preferredUsername || name);
|
||||||
const { followers: followerCount, following: followingCount } = await activitypub.actors.getLocalFollowCounts(uid);
|
const { followers: followerCount, following: followingCount } = await activitypub.actors.getLocalFollowCounts(uid);
|
||||||
|
|
||||||
try {
|
if (!hostname) { // if not available via webfinger, infer from id
|
||||||
({ hostname } = new URL(actor.id));
|
try {
|
||||||
} catch (e) {
|
({ hostname } = new URL(actor.id));
|
||||||
return null;
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let picture;
|
let picture;
|
||||||
|
|||||||
Reference in New Issue
Block a user