Skip to content

Commit c3e7d7d

Browse files
committed
chore: removes findByFederationMediaIdAndServerName and add mediaId index into upload collection
1 parent 3289203 commit c3e7d7d

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

ee/packages/federation-matrix/src/api/_matrix/media.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function createMultipartResponse(
6363
};
6464
}
6565

66-
async function getMediaFile(mediaId: string, serverName: string): Promise<{ file: IUpload; buffer: Buffer } | null> {
67-
const file = await MatrixMediaService.getLocalFileForMatrixNode(mediaId, serverName);
66+
async function getMediaFile(mediaId: string): Promise<{ file: IUpload; buffer: Buffer } | null> {
67+
const file = await MatrixMediaService.getLocalFileForMatrixNode(mediaId);
6868
if (!file) {
6969
return null;
7070
}
@@ -74,7 +74,7 @@ async function getMediaFile(mediaId: string, serverName: string): Promise<{ file
7474
}
7575

7676
export const getMatrixMediaRoutes = (homeserverServices: HomeserverServices) => {
77-
const { config, federationAuth } = homeserverServices;
77+
const { federationAuth } = homeserverServices;
7878
const router = new Router('/federation');
7979

8080
router.get(
@@ -95,10 +95,9 @@ export const getMatrixMediaRoutes = (homeserverServices: HomeserverServices) =>
9595
async (c) => {
9696
try {
9797
const { mediaId } = c.req.param();
98-
const { serverName } = config;
9998

10099
// TODO: Add file streaming support
101-
const result = await getMediaFile(mediaId, serverName);
100+
const result = await getMediaFile(mediaId);
102101
if (!result) {
103102
return {
104103
statusCode: 404,

ee/packages/federation-matrix/src/services/MatrixMediaService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export class MatrixMediaService {
6565
}
6666
}
6767

68-
static async getLocalFileForMatrixNode(mediaId: string, serverName: string): Promise<IUpload | null> {
68+
static async getLocalFileForMatrixNode(mediaId: string): Promise<IUpload | null> {
6969
try {
70-
let file = await Uploads.findByFederationMediaIdAndServerName(mediaId, serverName);
70+
let file = await Uploads.findByFederationMediaId(mediaId);
7171

7272
if (!file) {
7373
file = await Uploads.findOneById(mediaId);
@@ -102,7 +102,7 @@ export class MatrixMediaService {
102102
throw new Error('Invalid MXC URI');
103103
}
104104

105-
const uploadAlreadyExists = await Uploads.findByFederationMediaIdAndServerName(parts.mediaId, parts.serverName);
105+
const uploadAlreadyExists = await Uploads.findByFederationMediaId(parts.mediaId);
106106
if (uploadAlreadyExists) {
107107
return uploadAlreadyExists._id;
108108
}

packages/model-typings/src/models/IUploadsModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface IUploadsModel extends IBaseUploadsModel<IUpload> {
1515
options?: Omit<FindOptions<IUpload>, 'sort'>,
1616
): FindPaginated<FindCursor<WithId<IUpload>>>;
1717

18-
findByFederationMediaIdAndServerName(mediaId: string, serverName: string): Promise<IUpload | null>;
18+
findByFederationMediaId(mediaId: string): Promise<IUpload | null>;
1919

2020
setFederationInfo(fileId: string, info: { mxcUri: string; serverName: string; mediaId: string }): Promise<Document | UpdateResult>;
2121
}

packages/models/src/models/Uploads.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export class UploadsRaw extends BaseUploadModelRaw implements IUploadsModel {
1212
}
1313

1414
protected modelIndexes(): IndexDescription[] {
15-
return [...super.modelIndexes(), { key: { uploadedAt: -1 } }, { key: { rid: 1, _hidden: 1, typeGroup: 1 } }];
15+
return [
16+
...super.modelIndexes(),
17+
{ key: { uploadedAt: -1 } },
18+
{ key: { rid: 1, _hidden: 1, typeGroup: 1 } },
19+
{ key: { 'federation.mediaId': 1 } },
20+
];
1621
}
1722

1823
findNotHiddenFilesOfRoom(roomId: string, searchText: string, fileType: string, limit: number): FindCursor<IUpload> {
@@ -47,8 +52,8 @@ export class UploadsRaw extends BaseUploadModelRaw implements IUploadsModel {
4752
});
4853
}
4954

50-
findByFederationMediaIdAndServerName(mediaId: string, serverName: string): Promise<IUpload | null> {
51-
return this.findOne({ 'federation.mediaId': mediaId, 'federation.serverName': serverName });
55+
findByFederationMediaId(mediaId: string): Promise<IUpload | null> {
56+
return this.findOne({ 'federation.mediaId': mediaId });
5257
}
5358

5459
setFederationInfo(fileId: string, info: { mxcUri: string; serverName: string; mediaId: string }): Promise<Document | UpdateResult> {

0 commit comments

Comments
 (0)