-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from David032/7-skullapi-module
7 SkullAPI Module
- Loading branch information
Showing
16 changed files
with
305 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,3 +368,5 @@ skullOS/skullOs/ | |
skullOS/skullOSselfContained/ | ||
|
||
skullOS/builds/ | ||
|
||
skullOS.API/builds/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using skullOS.API.Data_Objects; | ||
using skullOS.Core; | ||
|
||
namespace skullOS.API.Controllers | ||
{ | ||
[Route("Captures")] | ||
[ApiController] | ||
public class CapturesController : ControllerBase | ||
{ | ||
private readonly ILogger<CapturesController> _logger; | ||
string capturesDirectory; | ||
DirectoryInfo capturesDirectoryInfo; | ||
|
||
public CapturesController(ILogger<CapturesController> logger) | ||
{ | ||
_logger = logger; | ||
FileManager.CreateSkullDirectory(); | ||
capturesDirectory = @FileManager.GetSkullDirectory() + @"/Captures"; | ||
capturesDirectoryInfo = new DirectoryInfo(capturesDirectory); | ||
} | ||
|
||
#region Get | ||
[HttpGet("Directory")] | ||
public string GetDirectory() | ||
{ | ||
return capturesDirectoryInfo.FullName; | ||
} | ||
|
||
[HttpGet("MostRecent")] | ||
public IActionResult GetNewest() | ||
{ | ||
var mostRecentImage = capturesDirectoryInfo.GetFiles().Where(f => f.Extension == ".jpg").OrderByDescending(f => f.LastAccessTime).FirstOrDefault(); | ||
var image = System.IO.File.OpenRead(mostRecentImage.FullName); | ||
return File(image, "image/jpeg"); | ||
} | ||
|
||
[HttpGet("All")] | ||
public List<Capture> GetAll() | ||
{ | ||
List<Capture> Files = new(); | ||
foreach (var item in capturesDirectoryInfo.GetFiles()) | ||
{ | ||
Capture file = new(item.FullName, item.CreationTime.ToShortTimeString()); | ||
Files.Add(file); | ||
} | ||
return Files; | ||
} | ||
|
||
[HttpGet("AllPictures")] | ||
public List<Capture> GetAllPictures() | ||
{ | ||
List<Capture> Files = new(); | ||
foreach (var item in capturesDirectoryInfo.GetFiles().Where(f => f.Extension == ".jpg")) | ||
{ | ||
Capture file = new(item.FullName, item.CreationTime.ToShortTimeString()); | ||
Files.Add(file); | ||
} | ||
return Files; | ||
} | ||
|
||
[HttpGet("AllVideos")] | ||
public List<Capture> GetAllVideos() | ||
{ | ||
List<Capture> Files = new(); | ||
foreach (var item in capturesDirectoryInfo.GetFiles().Where(f => f.Extension == ".mp4")) | ||
{ | ||
Capture file = new(item.FullName, item.CreationTime.ToShortTimeString()); | ||
Files.Add(file); | ||
} | ||
return Files; | ||
} | ||
|
||
[HttpGet("Image")] | ||
public IActionResult GetImage(string fileId) | ||
{ | ||
var file = capturesDirectoryInfo.GetFiles().Where(f => f.Name == fileId).FirstOrDefault(); | ||
var image = System.IO.File.OpenRead(file.FullName); | ||
return File(image, "image/jpeg"); | ||
} | ||
|
||
[HttpGet("Video")] | ||
public IActionResult GetVideo(string fileId) | ||
{ | ||
var file = capturesDirectoryInfo.GetFiles().Where(f => f.Name == fileId).FirstOrDefault(); | ||
var image = System.IO.File.OpenRead(file.FullName); | ||
return File(image, "video/mp4"); | ||
} | ||
#endregion | ||
|
||
[HttpDelete("Delete")] | ||
public bool DeleteCapture(string filePath) | ||
{ | ||
if (!System.IO.File.Exists(filePath)) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
System.IO.File.Delete(filePath); | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace skullOS.API.Data_Objects | ||
{ | ||
public class Capture | ||
{ | ||
private string filename; | ||
private string time; | ||
|
||
public Capture(string Name, string time) | ||
{ | ||
filename = Name; | ||
this.time = time; | ||
} | ||
|
||
public Capture(string Name, DateTime time) | ||
{ | ||
filename = Name; | ||
this.time = time.ToShortTimeString(); | ||
} | ||
|
||
public string Time | ||
{ | ||
get { return time; } | ||
set { time = value; } | ||
} | ||
|
||
public string Filename | ||
{ | ||
get { return filename; } | ||
set { filename = value; } | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
namespace skullOS.API | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
builder.WebHost.UseUrls("http://*:5000;https://*:5001"); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseHttpsRedirection(); | ||
} | ||
|
||
|
||
app.UseAuthorization(); | ||
|
||
|
||
app.MapControllers(); | ||
|
||
app.Run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:24049", | ||
"sslPort": 44308 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5185", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7201;http://localhost:5185", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\skullOS.Core\skullOS.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
API = TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Camera = True | ||
Output = True | ||
Interlink = True | ||
Interlink = True |
Oops, something went wrong.