-
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.
- Loading branch information
Showing
321 changed files
with
208,459 additions
and
157 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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,121 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Net.WebSockets; | ||
using System.Web; | ||
|
||
namespace srvlocal.data_handling | ||
{ | ||
public class AddFiles | ||
{ | ||
public class JSONDATAHANDLER | ||
{ | ||
public static void ProcessRequest(HttpListenerContext context) | ||
{ | ||
string requestMethod = context.Request.HttpMethod; | ||
|
||
if (requestMethod == "POST") | ||
{ | ||
|
||
using (StreamReader reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding)) | ||
{ | ||
string requestBody = reader.ReadToEnd(); | ||
|
||
FileData fileData = Newtonsoft.Json.JsonConvert.DeserializeObject<FileData>(requestBody); | ||
|
||
if (!string.IsNullOrEmpty(fileData.FileName) && !string.IsNullOrEmpty(fileData.Location)) | ||
{ | ||
try | ||
{ | ||
string filePath = Path.Combine(fileData.Location, fileData.FileName); | ||
File.WriteAllText(filePath, string.Empty); | ||
|
||
context.Response.StatusCode = (int)HttpStatusCode.OK; | ||
string responseString = "File added successfully!"; | ||
byte[] buffer = Encoding.UTF8.GetBytes(responseString); | ||
context.Response.ContentLength64 = buffer.Length; | ||
context.Response.OutputStream.Write(buffer, 0, buffer.Length); | ||
} | ||
catch (Exception ex) | ||
{ | ||
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; | ||
string responseString = "Failed to add file: " + ex.Message; | ||
byte[] buffer = Encoding.UTF8.GetBytes(responseString); | ||
context.Response.ContentLength64 = buffer.Length; | ||
context.Response.OutputStream.Write(buffer, 0, buffer.Length); | ||
} | ||
} | ||
else | ||
{ | ||
context.Response.StatusCode = (int)HttpStatusCode.BadRequest; | ||
string responseString = "File name and location are required."; | ||
byte[] buffer = Encoding.UTF8.GetBytes(responseString); | ||
context.Response.ContentLength64 = buffer.Length; | ||
context.Response.OutputStream.Write(buffer, 0, buffer.Length); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
context.Response.StatusCode = (int)HttpStatusCode.NotFound; | ||
context.Response.Close(); | ||
} | ||
} | ||
|
||
public class FileData | ||
{ | ||
public string FileName { get; set; } | ||
public string Location { get; set; } | ||
} | ||
} | ||
|
||
public bool IsReusable => false; | ||
} | ||
|
||
public class DirectoryController | ||
{ | ||
public static void GetSubdirectories(HttpListenerContext context) | ||
{ | ||
string directoryParam = context.Request.QueryString["directory"]; | ||
string decodedDirectory = HttpUtility.UrlDecode(directoryParam); | ||
|
||
try | ||
{ | ||
string[] subdirectories = Directory.GetDirectories(decodedDirectory); | ||
string responseJson = GetSubdirectoriesJson(subdirectories); | ||
|
||
context.Response.StatusCode = (int)HttpStatusCode.OK; | ||
context.Response.ContentType = "application/json"; | ||
byte[] buffer = Encoding.UTF8.GetBytes(responseJson); | ||
context.Response.OutputStream.Write(buffer, 0, buffer.Length); | ||
context.Response.OutputStream.Close(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
string errorJson = GetErrorJson(ex.Message); | ||
|
||
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; | ||
context.Response.ContentType = "application/json"; | ||
byte[] buffer = Encoding.UTF8.GetBytes(errorJson); | ||
context.Response.OutputStream.Write(buffer, 0, buffer.Length); | ||
context.Response.OutputStream.Close(); | ||
} | ||
} | ||
|
||
private static string GetSubdirectoriesJson(string[] subdirectories) | ||
{ | ||
return $"{{ \"subdirectories\": {Newtonsoft.Json.JsonConvert.SerializeObject(subdirectories)} }}"; | ||
} | ||
|
||
private static string GetErrorJson(string errorMessage) | ||
{ | ||
return $"{{ \"error\": \"{errorMessage}\" }}"; | ||
} | ||
} | ||
} | ||
|
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
srvlocal/obj/Debug/net7.0-windows/srvlocal.csproj.CoreCompileInputs.cache
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 +1 @@ | ||
c4bd85d8495a2cc6afc1a3cd381dc0644c287ab0 | ||
4654a5db46084ac836a0274e373df023ed3eb80b |
Binary file not shown.
Binary file not shown.
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
Oops, something went wrong.