Hey @mhmodTayel,
Here is an approach that I would explore more for this kind of functionality.
- Get a list of media file in the uploads using GET /api/upload/files > Upload | Strapi Documentation
- Get all media attached on all entities in collection-types & single types.
- Filter out the results of step 1 that exist in step 2. You are left with an array that has media that are not attached.
- Using DELETE /api/upload/files/:id to delete the resulted array from step 3 recursively.
Hope this is helpful to get you started.
Cheers!