mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-02 10:39:13 +00:00
Merge pull request #47 from MODSetter/dev
fix: Docs & Chats in other search spaces
This commit is contained in:
commit
6e1a254fcd
6 changed files with 32 additions and 21 deletions
|
@ -88,16 +88,19 @@ async def create_chat(
|
||||||
async def read_chats(
|
async def read_chats(
|
||||||
skip: int = 0,
|
skip: int = 0,
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
|
search_space_id: int = None,
|
||||||
session: AsyncSession = Depends(get_async_session),
|
session: AsyncSession = Depends(get_async_session),
|
||||||
user: User = Depends(current_active_user)
|
user: User = Depends(current_active_user)
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
|
query = select(Chat).join(SearchSpace).filter(SearchSpace.user_id == user.id)
|
||||||
|
|
||||||
|
# Filter by search_space_id if provided
|
||||||
|
if search_space_id is not None:
|
||||||
|
query = query.filter(Chat.search_space_id == search_space_id)
|
||||||
|
|
||||||
result = await session.execute(
|
result = await session.execute(
|
||||||
select(Chat)
|
query.offset(skip).limit(limit)
|
||||||
.join(SearchSpace)
|
|
||||||
.filter(SearchSpace.user_id == user.id)
|
|
||||||
.offset(skip)
|
|
||||||
.limit(limit)
|
|
||||||
)
|
)
|
||||||
return result.scalars().all()
|
return result.scalars().all()
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
|
|
|
@ -170,16 +170,19 @@ async def process_file_in_background(
|
||||||
async def read_documents(
|
async def read_documents(
|
||||||
skip: int = 0,
|
skip: int = 0,
|
||||||
limit: int = 300,
|
limit: int = 300,
|
||||||
|
search_space_id: int = None,
|
||||||
session: AsyncSession = Depends(get_async_session),
|
session: AsyncSession = Depends(get_async_session),
|
||||||
user: User = Depends(current_active_user)
|
user: User = Depends(current_active_user)
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
|
query = select(Document).join(SearchSpace).filter(SearchSpace.user_id == user.id)
|
||||||
|
|
||||||
|
# Filter by search_space_id if provided
|
||||||
|
if search_space_id is not None:
|
||||||
|
query = query.filter(Document.search_space_id == search_space_id)
|
||||||
|
|
||||||
result = await session.execute(
|
result = await session.execute(
|
||||||
select(Document)
|
query.offset(skip).limit(limit)
|
||||||
.join(SearchSpace)
|
|
||||||
.filter(SearchSpace.user_id == user.id)
|
|
||||||
.offset(skip)
|
|
||||||
.limit(limit)
|
|
||||||
)
|
)
|
||||||
db_documents = result.scalars().all()
|
db_documents = result.scalars().all()
|
||||||
|
|
||||||
|
|
|
@ -116,16 +116,18 @@ async def create_search_source_connector(
|
||||||
async def read_search_source_connectors(
|
async def read_search_source_connectors(
|
||||||
skip: int = 0,
|
skip: int = 0,
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
|
search_space_id: int = None,
|
||||||
session: AsyncSession = Depends(get_async_session),
|
session: AsyncSession = Depends(get_async_session),
|
||||||
user: User = Depends(current_active_user)
|
user: User = Depends(current_active_user)
|
||||||
):
|
):
|
||||||
"""List all search source connectors for the current user."""
|
"""List all search source connectors for the current user."""
|
||||||
try:
|
try:
|
||||||
|
query = select(SearchSourceConnector).filter(SearchSourceConnector.user_id == user.id)
|
||||||
|
|
||||||
|
# No need to filter by search_space_id as connectors are user-owned, not search space specific
|
||||||
|
|
||||||
result = await session.execute(
|
result = await session.execute(
|
||||||
select(SearchSourceConnector)
|
query.offset(skip).limit(limit)
|
||||||
.filter(SearchSourceConnector.user_id == user.id)
|
|
||||||
.offset(skip)
|
|
||||||
.limit(limit)
|
|
||||||
)
|
)
|
||||||
return result.scalars().all()
|
return result.scalars().all()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -7,12 +7,15 @@ interface PageProps {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ChatsPage({ params }: PageProps) {
|
export default async function ChatsPage({ params }: PageProps) {
|
||||||
|
// Await params to properly access dynamic route parameters
|
||||||
|
const searchSpaceId = params.search_space_id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<div className="flex items-center justify-center h-[60vh]">
|
<Suspense fallback={<div className="flex items-center justify-center h-[60vh]">
|
||||||
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"></div>
|
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"></div>
|
||||||
</div>}>
|
</div>}>
|
||||||
<ChatsPageClient searchSpaceId={params.search_space_id} />
|
<ChatsPageClient searchSpaceId={searchSpaceId} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -118,8 +118,8 @@ export function AppSidebarProvider({
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use the API client instead of direct fetch
|
// Use the API client instead of direct fetch - filter by current search space ID
|
||||||
const chats: Chat[] = await apiClient.get<Chat[]>('api/v1/chats/?limit=5&skip=0');
|
const chats: Chat[] = await apiClient.get<Chat[]>(`api/v1/chats/?limit=5&skip=0&search_space_id=${searchSpaceId}`);
|
||||||
|
|
||||||
// Transform API response to the format expected by AppSidebar
|
// Transform API response to the format expected by AppSidebar
|
||||||
const formattedChats = chats.map(chat => ({
|
const formattedChats = chats.map(chat => ({
|
||||||
|
@ -170,7 +170,7 @@ export function AppSidebarProvider({
|
||||||
|
|
||||||
// Clean up interval on component unmount
|
// Clean up interval on component unmount
|
||||||
return () => clearInterval(intervalId);
|
return () => clearInterval(intervalId);
|
||||||
}, []);
|
}, [searchSpaceId]);
|
||||||
|
|
||||||
// Handle delete chat
|
// Handle delete chat
|
||||||
const handleDeleteChat = async () => {
|
const handleDeleteChat = async () => {
|
||||||
|
|
|
@ -22,7 +22,7 @@ export function useDocuments(searchSpaceId: number) {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/documents`,
|
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/documents?search_space_id=${searchSpaceId}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem('surfsense_bearer_token')}`,
|
Authorization: `Bearer ${localStorage.getItem('surfsense_bearer_token')}`,
|
||||||
|
@ -57,7 +57,7 @@ export function useDocuments(searchSpaceId: number) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/documents`,
|
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/documents?search_space_id=${searchSpaceId}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem('surfsense_bearer_token')}`,
|
Authorization: `Bearer ${localStorage.getItem('surfsense_bearer_token')}`,
|
||||||
|
|
Loading…
Add table
Reference in a new issue