import virtool.file
from virtool.handlers.utils import json_response


async def find(req):
    db = req.app["db"]

    cursor = db.files.find({"eof": True}, virtool.file.LIST_PROJECTION)

    found_count = await cursor.count()

    documents = [virtool.file.processor(d) for d in await cursor.to_list(15)]

    return json_response({
        "documents": documents,
        "found_count": found_count
    })

import os

import virtool.file
import virtool.utils
from virtool.handlers.utils import json_response, not_found


async def find(req):
    db = req.app["db"]

    cursor = db.files.find({"ready": True}, virtool.file.LIST_PROJECTION)

    found_count = await cursor.count()

    documents = [virtool.file.processor(d) for d in await cursor.to_list(15)]

    return json_response({
        "documents": documents,
        "found_count": found_count
    })


async def remove(req):
    file_id = req.match_info["file_id"]

    file_path = os.path.join(req.app["settings"].get("data_path"), "files", file_id)

    delete_result = await req.app["db"].files.delete_one({"_id": file_id})

    virtool.utils.rm(file_path)

    if delete_result.deleted_count == 0:
        return not_found("Document does not exist")

    await req.app["dispatcher"].dispatch("files", "remove", [file_id])

    return json_response({
        "file_id": file_id,
        "removed": True
    })

Add uploaded file removal endpoint
Add uploaded file removal endpoint


+ import os
+ 
  import virtool.file
+ import virtool.utils
- from virtool.handlers.utils import json_response
+ from virtool.handlers.utils import json_response, not_found
  
  
  async def find(req):
      db = req.app["db"]
  
-     cursor = db.files.find({"eof": True}, virtool.file.LIST_PROJECTION)
+     cursor = db.files.find({"ready": True}, virtool.file.LIST_PROJECTION)
  
      found_count = await cursor.count()
  
      documents = [virtool.file.processor(d) for d in await cursor.to_list(15)]
  
      return json_response({
          "documents": documents,
          "found_count": found_count
      })
  
+ 
+ async def remove(req):
+     file_id = req.match_info["file_id"]
+ 
+     file_path = os.path.join(req.app["settings"].get("data_path"), "files", file_id)
+ 
+     delete_result = await req.app["db"].files.delete_one({"_id": file_id})
+ 
+     virtool.utils.rm(file_path)
+ 
+     if delete_result.deleted_count == 0:
+         return not_found("Document does not exist")
+ 
+     await req.app["dispatcher"].dispatch("files", "remove", [file_id])
+ 
+     return json_response({
+         "file_id": file_id,
+         "removed": True
+     })
+ 
Add uploaded file removal endpoint
## Code Before:
import virtool.file
from virtool.handlers.utils import json_response


async def find(req):
    db = req.app["db"]

    cursor = db.files.find({"eof": True}, virtool.file.LIST_PROJECTION)

    found_count = await cursor.count()

    documents = [virtool.file.processor(d) for d in await cursor.to_list(15)]

    return json_response({
        "documents": documents,
        "found_count": found_count
    })

## Instruction:
Add uploaded file removal endpoint
## Code After:
import os

import virtool.file
import virtool.utils
from virtool.handlers.utils import json_response, not_found


async def find(req):
    db = req.app["db"]

    cursor = db.files.find({"ready": True}, virtool.file.LIST_PROJECTION)

    found_count = await cursor.count()

    documents = [virtool.file.processor(d) for d in await cursor.to_list(15)]

    return json_response({
        "documents": documents,
        "found_count": found_count
    })


async def remove(req):
    file_id = req.match_info["file_id"]

    file_path = os.path.join(req.app["settings"].get("data_path"), "files", file_id)

    delete_result = await req.app["db"].files.delete_one({"_id": file_id})

    virtool.utils.rm(file_path)

    if delete_result.deleted_count == 0:
        return not_found("Document does not exist")

    await req.app["dispatcher"].dispatch("files", "remove", [file_id])

    return json_response({
        "file_id": file_id,
        "removed": True
    })
