Spaces:
Paused
Paused
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
Files changed (2)
1 unmodified line234567820 unmodified lines293031323334355 unmodified lines4142434445464711 unmodified lines596061626364651 unmodified lineimport { GridFSBucket, MongoClient } from "mongodb";import type { Conversation } from "$lib/types/Conversation";import type { SharedConversation } from "$lib/types/SharedConversation";import type { WebSearch } from "$lib/types/WebSearch";import type { AbortedGeneration } from "$lib/types/AbortedGeneration";import type { Settings } from "$lib/types/Settings";import type { User } from "$lib/types/User";20 unmodified linesconst settings = db.collection<Settings>("settings");const users = db.collection<User>("users");const sessions = db.collection<Session>("sessions");const webSearches = db.collection<WebSearch>("webSearches");const messageEvents = db.collection<MessageEvent>("messageEvents");const bucket = new GridFSBucket(db, { bucketName: "files" });5 unmodified linessettings,users,sessions,webSearches,messageEvents,bucket,};11 unmodified lines{ partialFilterExpression: { userId: { $exists: true } } }).catch(console.error);webSearches.createIndex({ sessionId: 1, updatedAt: -1 }).catch(console.error);abortedGenerations.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 }).catch(console.error);abortedGenerations.createIndex({ conversationId: 1 }, { unique: true }).catch(console.error);sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch(console.error);1 unmodified line23456720 unmodified lines2829303132335 unmodified lines39404142434411 unmodified lines5657585960611 unmodified lineimport { GridFSBucket, MongoClient } from "mongodb";import type { Conversation } from "$lib/types/Conversation";import type { SharedConversation } from "$lib/types/SharedConversation";import type { AbortedGeneration } from "$lib/types/AbortedGeneration";import type { Settings } from "$lib/types/Settings";import type { User } from "$lib/types/User";20 unmodified linesconst settings = db.collection<Settings>("settings");const users = db.collection<User>("users");const sessions = db.collection<Session>("sessions");const messageEvents = db.collection<MessageEvent>("messageEvents");const bucket = new GridFSBucket(db, { bucketName: "files" });5 unmodified linessettings,users,sessions,messageEvents,bucket,};11 unmodified lines{ partialFilterExpression: { userId: { $exists: true } } }).catch(console.error);abortedGenerations.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 }).catch(console.error);abortedGenerations.createIndex({ conversationId: 1 }, { unique: true }).catch(console.error);sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch(console.error);
123456789101112131415161718192021222324252627282930313233343536373839import { collections } from "$lib/server/database";import { hashConv } from "$lib/utils/hashConv";import { error } from "@sveltejs/kit";import { ObjectId } from "mongodb";
export async function GET({ params, locals }) { const searchId = new ObjectId(params.id);
const search = await collections.webSearches.findOne({ _id: searchId, });
if (!search) { throw error(404, "Search query not found"); }
const conv = await collections.conversations.findOne({ _id: search.convId, });
if (!conv) { throw error(404, "Conversation not found"); }
// 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 const hash = await hashConv(conv); const sharedConv = await collections.sharedConversations.findOne({ hash: hash, });
const userShouldSeeConv = (conv.userId && locals.user?._id.toString() === conv.userId.toString()) || sharedConv !== null;
if (!userShouldSeeConv) { throw error(403, "You don't have access to the conversation here."); }
return new Response(JSON.stringify(search), { headers: { "Content-Type": "application/json" } });}src/lib/server/database.ts-4
src/routes/search/[id]/+server.tsDeleted-39