fix: resolve federated avatar double-path URL that broke cross-instance profile pictures

profileSync stored avatar/banner paths with /api/uploads/ prefix on remote
instances, causing resolveAssetUrl to produce double-path URLs like
https://remote/api/uploads//api/uploads/file.jpg that 404'd. Store bare
filenames instead, strip prefix defensively in resolveAssetUrl and server-side
for existing data self-healing.
This commit is contained in:
Jannis Braun
2026-03-17 00:36:45 +01:00
parent bc4dd81632
commit cbef0fe0f8
3 changed files with 23 additions and 8 deletions
+9 -7
View File
@@ -10,7 +10,9 @@ async function downloadAsset(filename: string, origin?: string): Promise<Blob> {
const res = await fetch(filename);
return res.blob();
}
const base = origin ? `${origin}/api/uploads/${filename}` : `/api/uploads/${filename}`;
// Strip /api/uploads/ prefix to avoid double-path URLs (profileSync previously stored full paths)
const bare = filename.startsWith('/api/uploads/') ? filename.slice('/api/uploads/'.length) : filename;
const base = origin ? `${origin}/api/uploads/${bare}` : `/api/uploads/${bare}`;
const res = await fetch(base);
return res.blob();
}
@@ -62,7 +64,7 @@ async function pushProfileToRemote(inst: ConnectedInstance, homeUser: NonNullabl
try {
const blob = await downloadAsset(homeUser.avatar);
const attachment = await inst.api.uploads.upload(new File([blob], homeUser.avatar));
payload.avatar = `/api/uploads/${attachment.filename}`;
payload.avatar = attachment.filename;
} catch (err) {
console.warn('[ProfileSync] Failed to upload avatar to remote:', err);
}
@@ -75,7 +77,7 @@ async function pushProfileToRemote(inst: ConnectedInstance, homeUser: NonNullabl
try {
const blob = await downloadAsset(homeUser.banner);
const attachment = await inst.api.uploads.upload(new File([blob], homeUser.banner));
payload.banner = `/api/uploads/${attachment.filename}`;
payload.banner = attachment.filename;
} catch (err) {
console.warn('[ProfileSync] Failed to upload banner to remote:', err);
}
@@ -108,7 +110,7 @@ async function pullProfileFromRemote(inst: ConnectedInstance): Promise<void> {
try {
const blob = await downloadAsset(remoteUser.avatar, inst.origin);
const attachment = await api.uploads.upload(new File([blob], remoteUser.avatar.split('/').pop() || 'avatar'));
payload.avatar = `/api/uploads/${attachment.filename}`;
payload.avatar = attachment.filename;
} catch (err) {
console.warn('[ProfileSync] Failed to download/upload avatar from remote:', err);
}
@@ -121,7 +123,7 @@ async function pullProfileFromRemote(inst: ConnectedInstance): Promise<void> {
try {
const blob = await downloadAsset(remoteUser.banner, inst.origin);
const attachment = await api.uploads.upload(new File([blob], remoteUser.banner.split('/').pop() || 'banner'));
payload.banner = `/api/uploads/${attachment.filename}`;
payload.banner = attachment.filename;
} catch (err) {
console.warn('[ProfileSync] Failed to download/upload banner from remote:', err);
}
@@ -206,7 +208,7 @@ export async function syncProfileUpdateToRemotes(update: Partial<UpdateUserReque
if (avatarBlob && avatarFilename) {
try {
const attachment = await inst.api.uploads.upload(new File([avatarBlob], avatarFilename));
perInstPayload.avatar = `/api/uploads/${attachment.filename}`;
perInstPayload.avatar = attachment.filename;
} catch (err) {
console.warn(`[ProfileSync] Failed to upload avatar to ${inst.origin}:`, err);
}
@@ -220,7 +222,7 @@ export async function syncProfileUpdateToRemotes(update: Partial<UpdateUserReque
if (bannerBlob && bannerFilename) {
try {
const attachment = await inst.api.uploads.upload(new File([bannerBlob], bannerFilename));
perInstPayload.banner = `/api/uploads/${attachment.filename}`;
perInstPayload.banner = attachment.filename;
} catch (err) {
console.warn(`[ProfileSync] Failed to upload banner to ${inst.origin}:`, err);
}