mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
The early universal file handler returned 404 for CollectionFS avatars before the legacy fallback handler could run, including versioned Meteor-Files URLs. Read legacy avatar metadata and streams only after authenticating the request, retain safe response headers, close conditional-request streams and preserve missing-file responses. Add positive and negative runtime coverage and a browser image regression. Thanks to xet7 !
13 lines
655 B
JavaScript
13 lines
655 B
JavaScript
import { getUserIdFromRequest } from '/server/lib/requestUser';
|
|
import { getOldAttachmentData, getOldAttachmentStream } from '/models/lib/attachmentBackwardCompatibility';
|
|
|
|
// CollectionFS records cannot reliably establish public-board visibility.
|
|
// Require authentication before looking up metadata or opening the old bucket.
|
|
export async function readAuthenticatedLegacyAvatar(req, fileId) {
|
|
if (!(await getUserIdFromRequest(req))) return null;
|
|
const avatar = await getOldAttachmentData(fileId, 'avatars');
|
|
if (!avatar) return null;
|
|
const stream = await getOldAttachmentStream(fileId, 'avatars');
|
|
return stream ? { avatar, stream } : null;
|
|
}
|