Added Swagger.

This commit is contained in:
Jared Goodwin 2019-04-02 17:42:33 -07:00
parent 954843ef63
commit e5ded4585f
11 changed files with 52 additions and 76 deletions

View File

@ -7,6 +7,7 @@ using Remotely_ScreenCast.Linux.X11Interop;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
namespace Remotely_ScreenCast.Linux
@ -15,7 +16,6 @@ namespace Remotely_ScreenCast.Linux
{
public static Conductor Conductor { get; private set; }
public static IntPtr Display { get; } = LibX11.XOpenDisplay(null);
//public static CursorIconWatcher CursorIconWatcher { get; private set; }
public static void Main(string[] args)
{
try
@ -26,8 +26,6 @@ namespace Remotely_ScreenCast.Linux
Conductor.Connect().Wait();
Conductor.SetMessageHandlers(new X11Input(Display));
Conductor.ScreenCastInitiated += ScreenCastInitiated;
//CursorIconWatcher = new CursorIconWatcher(Conductor);
//CursorIconWatcher.OnChange += CursorIconWatcher_OnChange;
Conductor.OutgoingMessages.SendDeviceInfo(Conductor.ServiceID, Environment.MachineName).Wait();
Conductor.OutgoingMessages.NotifyRequesterUnattendedReady(Conductor.RequesterID).Wait();
Conductor.StartWaitForViewerTimer();
@ -43,12 +41,12 @@ namespace Remotely_ScreenCast.Linux
}
}
private static void ScreenCastInitiated(object sender, Tuple<string, string> viewerAndRequester)
private static async void ScreenCastInitiated(object sender, Tuple<string, string> viewerAndRequester)
{
try
{
var capturer = new X11Capture(Display);
//await Conductor.OutgoingMessages.SendCursorChange(CursorIconWatcher.GetCurrentCursor(), new List<string>() { viewerAndRequester.Item1 });
await Conductor.OutgoingMessages.SendCursorChange(new Core.Models.CursorInfo(null, Point.Empty, "default"), new List<string>() { viewerAndRequester.Item1 });
ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, capturer, Conductor);
}
catch (Exception ex)
@ -57,11 +55,6 @@ namespace Remotely_ScreenCast.Linux
}
}
//public static async void CursorIconWatcher_OnChange(object sender, CursorInfo cursor)
//{
// await Conductor.OutgoingMessages.SendCursorChange(cursor, Conductor.Viewers.Keys.ToList());
//}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Logger.Write((Exception)e.ExceptionObject);

View File

@ -63,6 +63,12 @@ namespace Win32
XDOWN = 0x0080,
XUP = 0x0100
}
public enum MonitorState
{
MonitorStateOn = -1,
MonitorStateOff = 2,
MonitorStateStandBy = 1
}
[Flags]
public enum KEYEVENTF : uint
{
@ -1238,6 +1244,9 @@ namespace Win32
[DllImport("user32.dll")]
public static extern short VkKeyScan(char ch);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
#endregion
}
}

View File

@ -136,5 +136,9 @@ namespace Win32
CloseDesktop(inputDesktop);
return desktopName;
}
public static void SetMonitorState(MonitorState state)
{
User32.SendMessage(0xFFFF, 0x112, 0xF170, (int)state);
}
}
}

View File

@ -65,8 +65,8 @@ namespace Remotely_Server.API
return Ok("ok");
}
[HttpDelete("DeleteInvite")]
public IActionResult DeleteInvite([FromBody]string inviteID)
[HttpDelete("DeleteInvite/{inviteID}")]
public IActionResult DeleteInvite(string inviteID)
{
if (!DataService.GetUserByName(User.Identity.Name).IsAdministrator)
{
@ -120,20 +120,20 @@ namespace Remotely_Server.API
}
return Ok(result.Item2);
}
[HttpDelete("RemoveFromOrganization")]
public IActionResult RemoveFromOrganization([FromBody]string userID)
[HttpDelete("RemoveUserFromOrganization/{userID}")]
public IActionResult RemoveUserFromOrganization(string userID)
{
if (!DataService.GetUserByName(User.Identity.Name).IsAdministrator)
{
return Unauthorized();
}
DataService.RemoveFromOrganization(User.Identity.Name, userID);
DataService.RemoveUserFromOrganization(User.Identity.Name, userID);
return Ok("ok");
}
[HttpDelete("RemoveUserPermission/{userID}")]
public IActionResult RemoveUserPermission(string userID, [FromBody]string permissionID)
[HttpDelete("RemovePermissionFromUser/{userID}/{permissionID}")]
public IActionResult RemovePermissionFromUser(string userID, string permissionID)
{
if (!DataService.GetUserByName(User.Identity.Name).IsAdministrator)
{

View File

@ -1,44 +0,0 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.IO;
namespace Remotely_Server.API
{
[Route("api/[controller]")]
public class ScreenCastVersionController : Controller
{
public ScreenCastVersionController(IHostingEnvironment hostingEnv)
{
this.HostingEnv = hostingEnv;
}
public IHostingEnvironment HostingEnv { get; }
// GET: api/<controller>
[HttpGet("{platform}")]
public string Get(string platform)
{
string ext = "";
switch (platform)
{
case "Windows":
ext = "exe";
break;
case "Linux":
ext = "appimage";
break;
default:
break;
}
var filePath = Path.Combine(HostingEnv.WebRootPath, "Downloads", $"Remotely_ScreenCast.{ext}");
if (!System.IO.File.Exists(filePath))
{
return "0.0.0.0";
}
var version = FileVersionInfo.GetVersionInfo(filePath);
return version.FileVersion.ToString();
}
}
}

View File

@ -620,7 +620,7 @@ namespace Remotely_Server.Data
RemotelyContext.SaveChanges();
return true;
}
internal void RemoveFromOrganization(string requesterUserName, string targetUserID)
internal void RemoveUserFromOrganization(string requesterUserName, string targetUserID)
{
var requester = RemotelyContext.Users
.Include(x => x.Organization)

View File

@ -61,6 +61,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>

View File

@ -24,6 +24,7 @@ using Remotely_Library.Services;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Swashbuckle.AspNetCore.Swagger;
namespace Remotely_Server
{
@ -100,6 +101,11 @@ namespace Remotely_Server
})
.AddMessagePackProtocol();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "Remotely API", Version = "v1" });
});
services.AddLogging();
services.AddScoped<IEmailSender, EmailSender>();
services.AddScoped<EmailSender>();
@ -165,7 +171,14 @@ namespace Remotely_Server
options.TransportMaxBufferSize = 2000000;
});
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Remotely API V1");
});
app.UseMvcWithDefaultRoute();
context.Database.Migrate();

View File

@ -134,9 +134,9 @@ document.querySelectorAll(".remove-permission-from-user-button").forEach((remove
xhr.onerror = () => {
showError(xhr);
};
xhr.open("delete", location.origin + `/api/OrganizationManagement/RemoveUserPermission/${userID}`);
xhr.open("delete", `${location.origin}/api/OrganizationManagement/RemovePermissionFromUser/${userID}/${selectedValue}`);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(selectedValue));
xhr.send();
}
});
});
@ -196,7 +196,7 @@ document.querySelectorAll(".remove-user-button").forEach((removeButton) => {
var xhr = new XMLHttpRequest();
xhr.onload = () => {
if (xhr.status == 200) {
document.querySelector(`tr [user='${userID}']`).remove();
document.querySelector(`tr[user='${userID}']`).remove();
}
else if (xhr.status == 400) {
ShowModal("Invalid Request", xhr.responseText);
@ -208,9 +208,9 @@ document.querySelectorAll(".remove-user-button").forEach((removeButton) => {
xhr.onerror = () => {
showError(xhr);
};
xhr.open("delete", location.origin + `/api/OrganizationManagement/RemoveFromOrganization/`);
xhr.open("delete", `${location.origin}/api/OrganizationManagement/RemoveUserFromOrganization/${userID}`);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(userID));
xhr.send();
}
});
});
@ -281,9 +281,9 @@ function deleteInvite(ev) {
xhr.onerror = () => {
showError(xhr);
};
xhr.open("delete", location.origin + `/api/OrganizationManagement/DeleteInvite/`);
xhr.open("delete", location.origin + `/api/OrganizationManagement/DeleteInvite/${inviteID}`);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(inviteID));
xhr.send();
}
function showError(xhr) {
console.error(xhr);

File diff suppressed because one or more lines are too long

View File

@ -141,9 +141,9 @@ document.querySelectorAll(".remove-permission-from-user-button").forEach((remove
xhr.onerror = () => {
showError(xhr);
}
xhr.open("delete", location.origin + `/api/OrganizationManagement/RemoveUserPermission/${userID}`);
xhr.open("delete", `${location.origin}/api/OrganizationManagement/RemovePermissionFromUser/${userID}/${selectedValue}`);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(selectedValue));
xhr.send();
}
})
})
@ -205,7 +205,7 @@ document.querySelectorAll(".remove-user-button").forEach((removeButton: HTMLButt
var xhr = new XMLHttpRequest();
xhr.onload = () => {
if (xhr.status == 200) {
document.querySelector(`tr [user='${userID}']`).remove();
document.querySelector(`tr[user='${userID}']`).remove();
}
else if (xhr.status == 400) {
ShowModal("Invalid Request", xhr.responseText);
@ -217,9 +217,9 @@ document.querySelectorAll(".remove-user-button").forEach((removeButton: HTMLButt
xhr.onerror = () => {
showError(xhr);
}
xhr.open("delete", location.origin + `/api/OrganizationManagement/RemoveFromOrganization/`);
xhr.open("delete", `${location.origin}/api/OrganizationManagement/RemoveUserFromOrganization/${userID}`);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(userID));
xhr.send();
}
})
});