File size: 1,335 Bytes
af661cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7b5125
 
 
 
 
af661cf
c7b5125
 
 
 
 
af661cf
c7b5125
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


import os
import json
import logging
import asyncio
import traceback

from aiohttp import web
from pyrogram import raw
from aiohttp.http_exceptions import BadStatusLine

from FileStream.utils.FileProcessors.human_readable import humanbytes
from FileStream.Database import Database
from FileStream.config import Telegram, Server
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)

async def searchAll(request: web.Request):
  query = request.rel_url.query.get('query', '')  # Extract 'query' from URL params
  offset = request.rel_url.query.get('offset', '0')  # Extract 'offset' (default 0)
  
  print(query, offset)  # Debugging print
  
  results = []
  offset = int(offset)  # Convert offset to integer
  
  # Simulating a database function call (replace with actual implementation)
  files, next_offset = await db.get_search_results(query, file_type=None, max_results=10, offset=offset)
  
  for file in files:
      results.append({
          "title": file['file']['file_name'],
          "document_file_id": file['file']['file_id'],
          "caption": file['file']['file_name'] or "",
          "description": f"Size: {humanbytes(file['file']['file_size'])}\nType: {file['file']['mime_type']}",
      })
  
  return web.json_response({"results": results, "next_offset": next_offset})  # Correct JSON response format