1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using LJLib.Client;
- using LJLib.Net.SPI.Client;
- using LJLib.Net.SPI.Com;
- using LJProxy.Models;
- using LJProxy.Settings;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using System.IO;
- using System.Text;
- using Newtonsoft.Json.Linq;
- using LJProxy.Services;
- using Microsoft.AspNetCore.Http.Extensions;
- namespace LJProxy.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class L1SvrController : Controller
- {
- private static object _syncRoot = new object();
- public static AppSettings _appSettingModel;
- private LJClientPoolService _ljClient;
- public L1SvrController(LJClientPoolService ljClient)
- {
- _ljClient = ljClient;
- }
- [Route("svr/{apiName}")]
- [HttpPost]
- [HttpGet]
- public async Task<IActionResult> Svr(string apiName)
- {
- string requestBody;
- using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
- {
- requestBody = await reader.ReadToEndAsync();
- }
- var url = Request.GetDisplayUrl();
- var pathStart = "/api/l1svr/svr/";
- var idx = url.IndexOf(pathStart, StringComparison.OrdinalIgnoreCase);
- string gateway = string.Empty;
- if (idx > 0)
- gateway = url.Substring(0, idx + 1);
- if (!string.IsNullOrEmpty(requestBody))
- {
- var reqObj = JObject.Parse(requestBody);
- reqObj["gateway"] = gateway;
- requestBody = JsonConvert.SerializeObject(reqObj);
- }
- var rslt = _ljClient.Pool.DoExcute(apiName, requestBody);
- return Content(rslt, "application/json");
- }
- [HttpPost]
- [Route("uploadfiles")]
- public IActionResult UploadFiles()
- {
- string token = string.Empty;
- if (Request.Headers.ContainsKey("Authorization"))
- {
- token = Request.Headers["Authorization"];
- }
- var files = Request.Form.Files;
- if (files != null && files.Count > 0)
- {
- UploadFilesRequest requestObj = new UploadFilesRequest();
- List<FileInfoModel> fileList = new List<FileInfoModel>();
- requestObj.token = token;
- foreach (var file in files)
- {
- FileInfoModel fileInfo = new FileInfoModel();
- fileInfo.FileName = file.FileName;
- using (var fs = file.OpenReadStream())
- {
- byte[] buffer = new byte[fs.Length];
- fs.Read(buffer, 0, buffer.Length);
- fileInfo.FileData = Convert.ToBase64String(buffer);
- }
- fileList.Add(fileInfo);
- }
- requestObj.FileList = fileList;
- var requestBody = JsonConvert.SerializeObject(requestObj);
- var rslt = _ljClient.Pool.DoExcute(requestObj.GetApiName(), requestBody);
- return Content(rslt, "application/json");
- }
- else
- {
- return NotFound();
- }
-
- }
- }
- }
|