Skip to content

Commit b2e74f6

Browse files
author
Rajat
committed
filtering by prefix in get media route
1 parent 8a04c27 commit b2e74f6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

apps/api/src/media/queries.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import GetPageProps from "./GetPageProps";
44
import MediaModel from "./model";
55
import { Constants, type MediaWithUserId } from "@medialit/models";
66

7+
function escapeRegex(value: string): string {
8+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9+
}
10+
711
export async function getMedia({
812
userId,
913
apikey,
@@ -89,8 +93,8 @@ export async function getPaginatedMedia({
8993
? Constants.AccessControl.PRIVATE
9094
: Constants.AccessControl.PUBLIC;
9195
}
92-
if (group) {
93-
query.group = group;
96+
if (typeof group === "string" && group.trim().length > 0) {
97+
query.group = { $regex: `^${escapeRegex(group.trim())}` };
9498
}
9599
const limitWithFallback = recordsPerPage || numberOfRecordsPerPage;
96100

0 commit comments

Comments
 (0)