nsarrazin HF staff commited on
Commit
95b3715
·
unverified ·
1 Parent(s): 9567da6

fix: See all your assistants regardless of usercount (#1053)

Browse files
src/routes/api/assistants/+server.ts CHANGED
@@ -14,6 +14,12 @@ export async function GET({ url, locals }) {
14
  const query = url.searchParams.get("q")?.trim() ?? null;
15
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
16
 
 
 
 
 
 
 
17
  let user: Pick<User, "_id"> | null = null;
18
  if (username) {
19
  user = await collections.users.findOne<Pick<User, "_id">>(
@@ -25,16 +31,13 @@ export async function GET({ url, locals }) {
25
  }
26
  }
27
 
28
- const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
29
-
30
  // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
31
  const filter: Filter<Assistant> = {
32
  ...(modelId && { modelId }),
33
- ...(!createdByCurrentUser &&
34
- REQUIRE_FEATURED_ASSISTANTS === "true" && { userCount: { $gt: 1 } }),
35
  ...(user && { createdById: user._id }),
36
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
37
  ...shouldBeFeatured,
 
38
  };
39
  const assistants = await collections.assistants
40
  .find(filter)
 
14
  const query = url.searchParams.get("q")?.trim() ?? null;
15
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
16
 
17
+ const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
18
+ const shouldHaveBeenShared =
19
+ REQUIRE_FEATURED_ASSISTANTS === "true" && !createdByCurrentUser
20
+ ? { userCount: { $gt: 1 } }
21
+ : {};
22
+
23
  let user: Pick<User, "_id"> | null = null;
24
  if (username) {
25
  user = await collections.users.findOne<Pick<User, "_id">>(
 
31
  }
32
  }
33
 
 
 
34
  // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
35
  const filter: Filter<Assistant> = {
36
  ...(modelId && { modelId }),
 
 
37
  ...(user && { createdById: user._id }),
38
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
39
  ...shouldBeFeatured,
40
+ ...shouldHaveBeenShared,
41
  };
42
  const assistants = await collections.assistants
43
  .find(filter)
src/routes/assistants/+page.server.ts CHANGED
@@ -22,6 +22,10 @@ export const load = async ({ url, locals }) => {
22
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
23
 
24
  const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
 
 
 
 
25
 
26
  let user: Pick<User, "_id"> | null = null;
27
  if (username) {
@@ -37,10 +41,9 @@ export const load = async ({ url, locals }) => {
37
  // fetch the top assistants sorted by user count from biggest to smallest. filter by model too if modelId is provided or query if query is provided
38
  const filter: Filter<Assistant> = {
39
  ...(modelId && { modelId }),
40
- ...(!createdByCurrentUser &&
41
- REQUIRE_FEATURED_ASSISTANTS === "true" && { userCount: { $gt: 1 } }),
42
  ...(user && { createdById: user._id }),
43
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
 
44
  ...shouldBeFeatured,
45
  };
46
  const assistants = await collections.assistants
 
22
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
23
 
24
  const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
25
+ const shouldHaveBeenShared =
26
+ REQUIRE_FEATURED_ASSISTANTS === "true" && !createdByCurrentUser
27
+ ? { userCount: { $gt: 1 } }
28
+ : {};
29
 
30
  let user: Pick<User, "_id"> | null = null;
31
  if (username) {
 
41
  // fetch the top assistants sorted by user count from biggest to smallest. filter by model too if modelId is provided or query if query is provided
42
  const filter: Filter<Assistant> = {
43
  ...(modelId && { modelId }),
 
 
44
  ...(user && { createdById: user._id }),
45
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
46
+ ...shouldHaveBeenShared,
47
  ...shouldBeFeatured,
48
  };
49
  const assistants = await collections.assistants