nsarrazin HF staff commited on
Commit
ea856f7
1 Parent(s): 332d815

Get rid of the unused websearch collection, and the unused endpoint (#607)

Browse files

* Get rid of the unused websearch collection, and the unused endpoint

* removes index

* lint

src/lib/server/database.ts CHANGED
@@ -2,7 +2,6 @@ import { MONGODB_URL, MONGODB_DB_NAME, MONGODB_DIRECT_CONNECTION } from "$env/st
2
  import { GridFSBucket, MongoClient } from "mongodb";
3
  import type { Conversation } from "$lib/types/Conversation";
4
  import type { SharedConversation } from "$lib/types/SharedConversation";
5
- import type { WebSearch } from "$lib/types/WebSearch";
6
  import type { AbortedGeneration } from "$lib/types/AbortedGeneration";
7
  import type { Settings } from "$lib/types/Settings";
8
  import type { User } from "$lib/types/User";
@@ -29,7 +28,6 @@ const abortedGenerations = db.collection<AbortedGeneration>("abortedGenerations"
29
  const settings = db.collection<Settings>("settings");
30
  const users = db.collection<User>("users");
31
  const sessions = db.collection<Session>("sessions");
32
- const webSearches = db.collection<WebSearch>("webSearches");
33
  const messageEvents = db.collection<MessageEvent>("messageEvents");
34
  const bucket = new GridFSBucket(db, { bucketName: "files" });
35
 
@@ -41,7 +39,6 @@ export const collections = {
41
  settings,
42
  users,
43
  sessions,
44
- webSearches,
45
  messageEvents,
46
  bucket,
47
  };
@@ -59,7 +56,6 @@ client.on("open", () => {
59
  { partialFilterExpression: { userId: { $exists: true } } }
60
  )
61
  .catch(console.error);
62
- webSearches.createIndex({ sessionId: 1, updatedAt: -1 }).catch(console.error);
63
  abortedGenerations.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 }).catch(console.error);
64
  abortedGenerations.createIndex({ conversationId: 1 }, { unique: true }).catch(console.error);
65
  sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch(console.error);
 
2
  import { GridFSBucket, MongoClient } from "mongodb";
3
  import type { Conversation } from "$lib/types/Conversation";
4
  import type { SharedConversation } from "$lib/types/SharedConversation";
 
5
  import type { AbortedGeneration } from "$lib/types/AbortedGeneration";
6
  import type { Settings } from "$lib/types/Settings";
7
  import type { User } from "$lib/types/User";
 
28
  const settings = db.collection<Settings>("settings");
29
  const users = db.collection<User>("users");
30
  const sessions = db.collection<Session>("sessions");
 
31
  const messageEvents = db.collection<MessageEvent>("messageEvents");
32
  const bucket = new GridFSBucket(db, { bucketName: "files" });
33
 
 
39
  settings,
40
  users,
41
  sessions,
 
42
  messageEvents,
43
  bucket,
44
  };
 
56
  { partialFilterExpression: { userId: { $exists: true } } }
57
  )
58
  .catch(console.error);
 
59
  abortedGenerations.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 }).catch(console.error);
60
  abortedGenerations.createIndex({ conversationId: 1 }, { unique: true }).catch(console.error);
61
  sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch(console.error);
src/routes/search/[id]/+server.ts DELETED
@@ -1,39 +0,0 @@
1
- import { collections } from "$lib/server/database";
2
- import { hashConv } from "$lib/utils/hashConv";
3
- import { error } from "@sveltejs/kit";
4
- import { ObjectId } from "mongodb";
5
-
6
- export async function GET({ params, locals }) {
7
- const searchId = new ObjectId(params.id);
8
-
9
- const search = await collections.webSearches.findOne({
10
- _id: searchId,
11
- });
12
-
13
- if (!search) {
14
- throw error(404, "Search query not found");
15
- }
16
-
17
- const conv = await collections.conversations.findOne({
18
- _id: search.convId,
19
- });
20
-
21
- if (!conv) {
22
- throw error(404, "Conversation not found");
23
- }
24
-
25
- // there's no better way to see if a conversation has been shared, so we hash the messages and see if there's a shared conversation with the same hash
26
- const hash = await hashConv(conv);
27
- const sharedConv = await collections.sharedConversations.findOne({
28
- hash: hash,
29
- });
30
-
31
- const userShouldSeeConv =
32
- (conv.userId && locals.user?._id.toString() === conv.userId.toString()) || sharedConv !== null;
33
-
34
- if (!userShouldSeeConv) {
35
- throw error(403, "You don't have access to the conversation here.");
36
- }
37
-
38
- return new Response(JSON.stringify(search), { headers: { "Content-Type": "application/json" } });
39
- }