Skip to content

Commit

Permalink
Only require featured assistants for other users' assistants (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin authored Apr 23, 2024
1 parent 95b3715 commit 7ede405
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/routes/api/assistants/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export async function GET({ url, locals }) {
const query = url.searchParams.get("q")?.trim() ?? null;
const createdByCurrentUser = locals.user?.username && locals.user.username === username;

const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
const shouldHaveBeenShared =
const shouldBeFeatured =
REQUIRE_FEATURED_ASSISTANTS === "true" && !createdByCurrentUser
? { userCount: { $gt: 1 } }
? { featured: true, userCount: { $gt: 1 } }
: {};

let user: Pick<User, "_id"> | null = null;
Expand All @@ -37,7 +36,6 @@ export async function GET({ url, locals }) {
...(user && { createdById: user._id }),
...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
...shouldBeFeatured,
...shouldHaveBeenShared,
};
const assistants = await collections.assistants
.find(filter)
Expand Down
6 changes: 2 additions & 4 deletions src/routes/assistants/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ export const load = async ({ url, locals }) => {
const sort = url.searchParams.get("sort")?.trim() ?? SortKey.POPULAR;
const createdByCurrentUser = locals.user?.username && locals.user.username === username;

const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
const shouldHaveBeenShared =
const shouldBeFeatured =
REQUIRE_FEATURED_ASSISTANTS === "true" && !createdByCurrentUser
? { userCount: { $gt: 1 } }
? { featured: true, userCount: { $gt: 1 } }
: {};

let user: Pick<User, "_id"> | null = null;
Expand All @@ -43,7 +42,6 @@ export const load = async ({ url, locals }) => {
...(modelId && { modelId }),
...(user && { createdById: user._id }),
...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
...shouldHaveBeenShared,
...shouldBeFeatured,
};
const assistants = await collections.assistants
Expand Down

0 comments on commit 7ede405

Please sign in to comment.