mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2025-03-04 07:18:50 -07:00
[mastodon-client] Refresh user profile data on /accounts/lookup
This commit is contained in:
parent
75c9873796
commit
7c7c6a09a2
2 changed files with 15 additions and 5 deletions
packages/backend/src
|
@ -18,7 +18,8 @@ const mentionUriCache = new Cache<string>("resolveMentionUserUri", 60 * 60 * 72)
|
||||||
export async function resolveUser(
|
export async function resolveUser(
|
||||||
username: string,
|
username: string,
|
||||||
host: string | null,
|
host: string | null,
|
||||||
refresh: boolean = true
|
refresh: boolean = true,
|
||||||
|
awaitRefresh: boolean = true
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
const usernameLower = username.toLowerCase();
|
const usernameLower = username.toLowerCase();
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ export async function resolveUser(
|
||||||
|
|
||||||
// If user information is out of date, return it by starting over from WebFinger
|
// If user information is out of date, return it by starting over from WebFinger
|
||||||
if (
|
if (
|
||||||
refresh && (
|
refresh && awaitRefresh && (
|
||||||
user.lastFetchedAt == null ||
|
user.lastFetchedAt == null ||
|
||||||
Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24
|
Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24
|
||||||
)
|
)
|
||||||
|
@ -172,6 +173,10 @@ export async function resolveUser(
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (refresh && !awaitRefresh && (user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24)) {
|
||||||
|
// Run the refresh in the background
|
||||||
|
// noinspection ES6MissingAwait
|
||||||
|
resolveUser(username, host, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`return existing remote user: ${acctLower}`);
|
logger.info(`return existing remote user: ${acctLower}`);
|
||||||
|
|
|
@ -41,6 +41,7 @@ import { UserProfile } from "@/models/entities/user-profile.js";
|
||||||
import { verifyLink } from "@/services/fetch-rel-me.js";
|
import { verifyLink } from "@/services/fetch-rel-me.js";
|
||||||
import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js";
|
import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js";
|
||||||
import { MastoContext } from "@/server/api/mastodon/index.js";
|
import { MastoContext } from "@/server/api/mastodon/index.js";
|
||||||
|
import { resolveUser } from "@/remote/resolve-user.js";
|
||||||
|
|
||||||
export type AccountCache = {
|
export type AccountCache = {
|
||||||
locks: AsyncLock;
|
locks: AsyncLock;
|
||||||
|
@ -233,10 +234,14 @@ export class UserHelpers {
|
||||||
public static async getUserFromAcct(acct: string): Promise<User> {
|
public static async getUserFromAcct(acct: string): Promise<User> {
|
||||||
const split = acct.toLowerCase().split('@');
|
const split = acct.toLowerCase().split('@');
|
||||||
if (split.length > 2) throw new Error('Invalid acct');
|
if (split.length > 2) throw new Error('Invalid acct');
|
||||||
return Users.findOneBy({ usernameLower: split[0], host: split[1] ?? IsNull() })
|
return split[1] == null
|
||||||
|
? Users.findOneBy({ usernameLower: split[0], host: split[1] ?? IsNull() })
|
||||||
.then(p => {
|
.then(p => {
|
||||||
if (p) return p;
|
if (p) return p;
|
||||||
throw new MastoApiError(404);
|
throw new MastoApiError(404);
|
||||||
|
})
|
||||||
|
: resolveUser(split[0], split[1], true, false).catch(() => {
|
||||||
|
throw new MastoApiError(404);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue