Skip to content

Commit 58d9ca8

Browse files
committed
Add file list, search, and delete endpoints; remove compose
Expanded UploadController with endpoints to list, search, and delete files in the temp directory, providing full file management (upload, list, search, download, delete). Also removed docker-compose.yml from the project.
1 parent 42bee17 commit 58d9ca8

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

UDToolAPI/Controllers/UploadController.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public class UploadController : ControllerBase
99
{
1010
private static readonly string TempPath = Path.Combine(Path.GetTempPath(), "UDToolAPI");
1111

12+
// Endpoint to upload a file with a specific name
1213
[HttpPost("{fileName}")]
1314
public async Task<IActionResult> Upload(IFormFile file, string fileName)
1415
{
1516
if (file == null || file.Length == 0)
1617
return BadRequest("No file uploaded.");
1718

18-
// Ensure the directory exists
1919
Directory.CreateDirectory(TempPath);
2020

2121
var filePath = Path.Combine(TempPath, fileName);
@@ -26,6 +26,20 @@ public async Task<IActionResult> Upload(IFormFile file, string fileName)
2626
return Ok(new { message = "File uploaded successfully.", filePath });
2727
}
2828

29+
// Endpoint to list all files in the temp directory
30+
[HttpGet("list")]
31+
public IActionResult List()
32+
{
33+
if (!Directory.Exists(TempPath))
34+
return Ok(new List<string>());
35+
36+
var fileNames = Directory.GetFiles(TempPath)
37+
.Select(Path.GetFileName)
38+
.ToList();
39+
return Ok(fileNames);
40+
}
41+
42+
// Endpoint to download a file by name
2943
[HttpGet("{fileName}")]
3044
public IActionResult Download(string fileName)
3145
{
@@ -40,6 +54,8 @@ public IActionResult Download(string fileName)
4054
var fileBytes = System.IO.File.ReadAllBytes(filePath);
4155
return File(fileBytes, "application/octet-stream", fileName);
4256
}
57+
58+
// Endpoint to find files containing the search term in their name
4359
[HttpGet("search/{searchTerm}")]
4460
public IActionResult Search(string searchTerm)
4561
{
@@ -49,5 +65,22 @@ public IActionResult Search(string searchTerm)
4965
var fileNames = files.Select(Path.GetFileName).ToArray();
5066
return Ok(fileNames);
5167
}
68+
69+
// Endpoint to delete a file by name
70+
[HttpDelete("{fileName}")]
71+
public IActionResult Delete(string fileName)
72+
{
73+
if (string.IsNullOrEmpty(fileName))
74+
return BadRequest("File name is required.");
75+
76+
var filePath = Path.Combine(TempPath, fileName);
77+
78+
if (!System.IO.File.Exists(filePath))
79+
return NotFound("File not found.");
80+
81+
System.IO.File.Delete(filePath);
82+
83+
return Ok(new { message = "File deleted successfully." });
84+
}
5285
}
5386
}

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.8'
2-
31
services:
42
udtoolapi:
53
build:

0 commit comments

Comments
 (0)