Added web order hard copy save to local hdd

from external server.
This commit is contained in:
james262 2023-11-10 15:14:17 -05:00
parent ecb0873f7f
commit 8181f31d27
2 changed files with 129 additions and 38 deletions

View File

@ -1,22 +1,32 @@
using Microsoft.AspNetCore.Mvc; using System.Web;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using CVRLIB.CARTS; using CVRLIB.CARTS;
using static CVRLIB.CVSTRINGS.TextFuncs; using static CVRLIB.CVSTRINGS.TextFuncs;
using Newtonsoft.Json;
using CVRLIB; using CVRLIB;
using CVRLIB.Generic;
namespace VSERVERWS.Controllers {
//https://vserverws.cvr.cvrco.ca/api/cart/CartStatus using ZXing;
using Newtonsoft.Json;
[Route("api/Cart/[action]")]
[ApiController]
public class CartController : ControllerBase { namespace VSERVERWS.Controllers;
//https://vserverws.cvr.cvrco.ca/api/cart/CartStatus
[Route("api/Cart/[action]")]
[ApiController]
public class CartController : ControllerBase {
@ -29,6 +39,88 @@ namespace VSERVERWS.Controllers {
} }
//https://localhost:7210/api/Cart/SubmitCartHTML?id=1337&source=beta%2Ecvr%2Ecvrco%2Eca
[HttpPost]
[Consumes("text/plain")]
public async Task<IActionResult> SubmitCartHTML(string id, string source) {
var rTOR = new TryOperationResult();
var isEncrypted = false;
var tdata = "";
var data = "";
var HTML_PATH = Program.XDRIVE + "\\CVRCO\\BU\\Carts\\HTML";
var inSource = HttpUtility.UrlDecode(source);
if (!string.IsNullOrEmpty(inSource)) {
HTML_PATH = HTML_PATH + "\\" + inSource;
if (!Directory.Exists(HTML_PATH)) {
Directory.CreateDirectory(HTML_PATH);
}
} else {
rTOR.AddResult(false, "READ_SOURCE", "no source provided!");
return new JsonResult(rTOR);
}
using (var SR = new StreamReader(Request.Body)) {
data = await SR.ReadToEndAsync();
}
if (!Directory.Exists(HTML_PATH)) {
Directory.CreateDirectory(HTML_PATH);
}
if (!tdata.Contains("<html>")) { isEncrypted = true; }
try {
if (isEncrypted) {
tdata = NonSecureDecryptHexStringToString(data);
}
if (!tdata.Contains("<html>")) {
throw new Exception("Invalid html string");
}
using (var FS = new FileStream(HTML_PATH + "\\" + id + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)) {
using (var SW = new StreamWriter(FS)) {
if (isEncrypted) {
await SW.WriteAsync(data);
} else {
await SW.WriteAsync(NonSecureEncryptStringToHexString(tdata));
}
};
};
rTOR.AddResult(true, "TRY_SAVE_HTML_CART");
} catch (Exception ex) {
rTOR.AddResult(false, "TRY_SAVE_HTML_CART", ex.Message, ex);
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
return new JsonResult(rTOR);
}
[HttpPost] [HttpPost]
@ -69,5 +161,4 @@ namespace VSERVERWS.Controllers {
}
} }

View File

@ -97,7 +97,7 @@ public partial class Program {
if (Directory.Exists("X:\\Shares\\cvrdata")) { if (Directory.Exists("X:\\Shares\\cvrdata")) {
return "X:\\Shares\\cvrdata"; return "X:\\Shares\\cvrdata";
} else { } else {
return "X:\\"; return "X:";
} }
} }
} }