add to git
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
################################################################################
|
||||||
|
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
/.vs/CodeEditorApi
|
||||||
|
/Application/.config
|
||||||
|
/Application/.vs/CodeEditorApi
|
||||||
|
/Application/bin
|
||||||
|
/Application/obj
|
||||||
|
/Application/Properties
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Database\" />
|
||||||
|
<Folder Include="Database\9ec274a6-f2a1-4629-b52a-a0d5e72eb4b2\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<NameOfLastUsedPublishProfile>C:\Projects\code-editor-api\Application\Properties\PublishProfiles\FTPProfile.pubxml</NameOfLastUsedPublishProfile>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.33627.172
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {1746F93F-3E42-4832-B5C1-834781B0426F}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using CodeEditorApi.Helpers;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace CodeEditorApi.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class SessionController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<SessionController> _logger;
|
||||||
|
|
||||||
|
public SessionController(ILogger<SessionController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("create")]
|
||||||
|
public Session CreateSession([FromBody] Session newSession)
|
||||||
|
{
|
||||||
|
return SessionFiles.Create(newSession.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("set")]
|
||||||
|
public void SetData([FromBody] SessionData data)
|
||||||
|
{
|
||||||
|
SessionFiles.Save(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("all")]
|
||||||
|
public IEnumerable<Session> Sessions()
|
||||||
|
{
|
||||||
|
return SessionFiles.Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("data/{sessionId}")]
|
||||||
|
public IEnumerable<SessionData> SessionData(Guid sessionId)
|
||||||
|
{
|
||||||
|
return SessionFiles.Get(sessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
console.log("HELLO");
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
var myJs = true;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
var myJs = true; var myOtherThing = 'string'
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
var myJs = true; var myOtherThing = 'string'
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
console.log("Hello")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
console.log("Hello 2.01")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
console.log("Hello 3.1")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
console.log("Hello 3.1");
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
box(10, 10, 10, 10)
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.WebSockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace CodeEditorApi.Helpers
|
||||||
|
{
|
||||||
|
public static class SessionFiles
|
||||||
|
{
|
||||||
|
private static string sessionPath = "database/";
|
||||||
|
public static Session Create(Guid sessionId)
|
||||||
|
{
|
||||||
|
if (CheckForDirectoryExists(sessionId))
|
||||||
|
{
|
||||||
|
throw new Exception("Session already exists");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CreateDirectory(sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetSession(sessionPath + "/" + sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Save(SessionData data)
|
||||||
|
{
|
||||||
|
if (!CheckForDirectoryExists(data.SessionId))
|
||||||
|
{
|
||||||
|
CreateDirectory(data.SessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteFile(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Session[] Get()
|
||||||
|
{
|
||||||
|
var dir = Directory.GetDirectories(sessionPath);
|
||||||
|
var res = new List<Session>();
|
||||||
|
|
||||||
|
foreach (var folder in dir)
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(folder);
|
||||||
|
|
||||||
|
res.Add(GetSession(folder));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SessionData[] Get(Guid sessionId)
|
||||||
|
{
|
||||||
|
var fileNames = Directory.GetFiles(sessionPath + "/" + sessionId);
|
||||||
|
var res = new List<SessionData>();
|
||||||
|
|
||||||
|
foreach (var fileName in fileNames)
|
||||||
|
{
|
||||||
|
res.Add(GetSessionData(sessionId, fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool CheckForDirectoryExists(Guid sessionId)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(sessionPath + sessionId))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool CreateDirectory(Guid sessionId)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(sessionPath + sessionId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool CreateFile(SessionData data)
|
||||||
|
{
|
||||||
|
if (!File.Exists(sessionPath + data.FileName))
|
||||||
|
{
|
||||||
|
using (FileStream fs = File.Create(sessionPath + data.FileName))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool WriteFile(SessionData data)
|
||||||
|
{
|
||||||
|
CreateFile(data);
|
||||||
|
using (StreamWriter sw = File.CreateText(sessionPath + data.FileName))
|
||||||
|
{
|
||||||
|
sw.Write(data.Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataType GetExtension(string fileName)
|
||||||
|
{
|
||||||
|
if (fileName.EndsWith(".js"))
|
||||||
|
{
|
||||||
|
return DataType.Javascript;
|
||||||
|
}
|
||||||
|
else if (fileName.EndsWith(".css"))
|
||||||
|
{
|
||||||
|
return DataType.CSS;
|
||||||
|
}
|
||||||
|
else if (fileName.EndsWith(".html"))
|
||||||
|
{
|
||||||
|
return DataType.HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DataType.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Session GetSession(string path)
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(path);
|
||||||
|
|
||||||
|
var strId = path.Substring(path.LastIndexOf("/") + 1);
|
||||||
|
|
||||||
|
var session = new Session
|
||||||
|
{
|
||||||
|
Id = Guid.Parse(strId),
|
||||||
|
NumberOfChanges = files.Length
|
||||||
|
};
|
||||||
|
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SessionData GetSessionData(Guid sessionId, string path)
|
||||||
|
{
|
||||||
|
SessionData sessionData;
|
||||||
|
|
||||||
|
using (StreamReader sr = new StreamReader(path))
|
||||||
|
{
|
||||||
|
var content = sr.ReadToEnd();
|
||||||
|
|
||||||
|
sessionData = new SessionData
|
||||||
|
{
|
||||||
|
SessionId = sessionId,
|
||||||
|
Data = content,
|
||||||
|
Type = GetExtension(path),
|
||||||
|
Timestamp = DateTime.Now
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return sessionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetFormattedDate(DateTime date)
|
||||||
|
{
|
||||||
|
return date.ToString("yyyy-MM-ddTHH-mm-ss-fff");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateTime GetDateFromFormat(string date)
|
||||||
|
{
|
||||||
|
CultureInfo provider = CultureInfo.InvariantCulture;
|
||||||
|
return DateTime.ParseExact(date, "yyyy-MM-ddTHH-mm-ss-fff", provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.UseCors(options =>
|
||||||
|
{
|
||||||
|
options.AllowAnyHeader();
|
||||||
|
options.AllowAnyMethod();
|
||||||
|
options.AllowAnyOrigin();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.Run();
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace CodeEditorApi
|
||||||
|
{
|
||||||
|
public class Session
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public int NumberOfChanges { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
namespace CodeEditorApi
|
||||||
|
{
|
||||||
|
public class SessionData
|
||||||
|
{
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
public Guid SessionId { get; set; }
|
||||||
|
public object Data { get; set; } = default!;
|
||||||
|
public DataType Type { get; set; }
|
||||||
|
|
||||||
|
public string FileName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return SessionId.ToString() + "/" + Helpers.SessionFiles.GetFormattedDate(Timestamp) + FileExtension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FileExtension {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Type == DataType.Javascript)
|
||||||
|
{
|
||||||
|
return ".js";
|
||||||
|
}
|
||||||
|
else if (Type == DataType.CSS)
|
||||||
|
{
|
||||||
|
return ".css";
|
||||||
|
}
|
||||||
|
else if (Type == DataType.HTML)
|
||||||
|
{
|
||||||
|
return ".html";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ".txt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DataType
|
||||||
|
{
|
||||||
|
Javascript,
|
||||||
|
HTML,
|
||||||
|
CSS,
|
||||||
|
Text
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.33627.172
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeEditorApi", "Application\CodeEditorApi.csproj", "{FEB9C73E-0A8D-4105-A3AD-4740DF9D0998}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{FEB9C73E-0A8D-4105-A3AD-4740DF9D0998}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{FEB9C73E-0A8D-4105-A3AD-4740DF9D0998}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{FEB9C73E-0A8D-4105-A3AD-4740DF9D0998}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{FEB9C73E-0A8D-4105-A3AD-4740DF9D0998}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {1746F93F-3E42-4832-B5C1-834781B0426F}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user