|
@@ -29,6 +29,7 @@ using TEAMModelOS.SDK.Module.AzureBlob.Container;
|
|
|
using TEAMModelOS.Services;
|
|
|
using HTEXLib.Translator;
|
|
|
using HTEXLib.DOCX.Models;
|
|
|
+using System.Collections.Concurrent;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -42,9 +43,9 @@ namespace TEAMModelOS.Controllers
|
|
|
// private readonly IHtexService htexService;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
|
- private List<LangConfig> langConfigs { get; set; }
|
|
|
+ private List<LangConfig> langConfigs { get; set; }
|
|
|
private readonly IHttpClientFactory _clientFactory;
|
|
|
- public ImportController( AzureStorageFactory azureStorage, IWebHostEnvironment webHostEnvironment,
|
|
|
+ public ImportController(AzureStorageFactory azureStorage, IWebHostEnvironment webHostEnvironment,
|
|
|
PPTX2HTEXTranslator PPTX2HTEXTranslator, IHttpClientFactory clientFactory,
|
|
|
DOXC2HTMLTranslator DOXC2HTMLTranslator, HTML2ITEMTranslator HTML2ITEMTranslator)
|
|
|
{
|
|
@@ -68,7 +69,7 @@ namespace TEAMModelOS.Controllers
|
|
|
string text = builder.ToString();
|
|
|
langConfigs = text.ToObject<List<LangConfig>>();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// {"url":"https://***.blob.core.cn/xxx/1.pptx"}
|
|
@@ -100,7 +101,7 @@ namespace TEAMModelOS.Controllers
|
|
|
BlobAuth blobAuth = _azureStorage.GetBlobSasUriRead(ContainerName, BlobName);
|
|
|
var response = await _clientFactory.CreateClient().GetAsync(new Uri(blobAuth.url));
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
- Stream stream= await response.Content.ReadAsStreamAsync();
|
|
|
+ Stream stream = await response.Content.ReadAsStreamAsync();
|
|
|
|
|
|
if (ext.ToLower() == "pptx" || ext.ToLower() == "xml")
|
|
|
{
|
|
@@ -111,7 +112,8 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
return Ok(new { index = "" });
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return BadRequest("不支持该文件类型的解析!");
|
|
|
}
|
|
|
}
|
|
@@ -161,11 +163,12 @@ namespace TEAMModelOS.Controllers
|
|
|
string index = await PPTXTranslator(id, FileName, streamFile);
|
|
|
return Ok(new { index = index });
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return BadRequest("type is not pptx or xml !");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -179,16 +182,16 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("upload-word")]
|
|
|
[RequestSizeLimit(102_400_000_00)] //最大10000m左右
|
|
|
- public IActionResult UploadWord([FromForm] IFormFile file)
|
|
|
+ public IActionResult UploadWord([FromForm] IFormFile file)
|
|
|
{
|
|
|
- // ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
+ // ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
if (!FileType.GetExtention(file.FileName).ToLower().Equals("docx"))
|
|
|
{
|
|
|
- return BadRequest(new Dictionary<string, object> { {"msg", "type is not docx!" },{ "code",ResponseCode.FAILED} });
|
|
|
+ return BadRequest(new Dictionary<string, object> { { "msg", "type is not docx!" }, { "code", ResponseCode.FAILED } });
|
|
|
}
|
|
|
|
|
|
- var doc= _DOXC2HTMLTranslator.Translate(file.OpenReadStream());
|
|
|
- // Dictionary<string, object> model = await ImportExerciseService.UploadWord(_azureStorage, file);
|
|
|
+ var doc = _DOXC2HTMLTranslator.Translate(file.OpenReadStream());
|
|
|
+ // Dictionary<string, object> model = await ImportExerciseService.UploadWord(_azureStorage, file);
|
|
|
return Ok(doc);
|
|
|
}
|
|
|
|
|
@@ -198,7 +201,7 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("parse-html")]
|
|
|
- public IActionResult AnalyzeHtml(JsonElement request)
|
|
|
+ public IActionResult AnalyzeHtml(JsonElement request)
|
|
|
{
|
|
|
//ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
@@ -211,8 +214,8 @@ namespace TEAMModelOS.Controllers
|
|
|
bool flagLang = dict.TryGetValue("lang", out object lang);
|
|
|
if (flag && htmlString != null && !string.IsNullOrEmpty(htmlString.ToString()))
|
|
|
{
|
|
|
- LangConfig langConfig= langConfigs.Where(x => x.Lang == lang.ToString()).FirstOrDefault();
|
|
|
- var exercises= _HTML2ITEMTranslator.Translate(htmlString.ToString(), langConfig);
|
|
|
+ LangConfig langConfig = langConfigs.Where(x => x.Lang == lang.ToString()).FirstOrDefault();
|
|
|
+ var exercises = _HTML2ITEMTranslator.Translate(htmlString.ToString(), langConfig);
|
|
|
return Ok(exercises);
|
|
|
}
|
|
|
else
|
|
@@ -220,7 +223,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
private async Task<string> PPTXTranslator(string id, string FileName, Stream streamFile)
|
|
|
{
|
|
@@ -229,27 +232,23 @@ namespace TEAMModelOS.Controllers
|
|
|
HTEXLib.Htex htex = _PPTX2HTEXTranslator.Translate(streamFile);
|
|
|
htex.name = FileName;
|
|
|
var slides = htex.slides;
|
|
|
- List<Task> tasks = new List<Task>();
|
|
|
- HTEX hTEX = new HTEX() { name = FileName, size = htex.size, thumbnail = htex.thumbnail, id = shaCode };
|
|
|
- Dictionary<string, string> texts = new Dictionary<string, string>();
|
|
|
- List<string> shas = new List<string>();
|
|
|
+ List<Task<string>> tasks = new List<Task<string>>();
|
|
|
+ HTEXIndex index = new HTEXIndex() { name = FileName, size = htex.size, thumbnail = htex.thumbnail, id = shaCode };
|
|
|
+
|
|
|
+ List<KeyValuePair<string, string>> blobslidenames = new List<KeyValuePair<string, string>>();
|
|
|
foreach (var slide in slides)
|
|
|
{
|
|
|
- string text = JsonHelper.ToJson(slide, ignoreNullValue: false);
|
|
|
- string sha = Guid.NewGuid().ToString("N");
|
|
|
- texts.Add(sha, text);
|
|
|
- shas.Add(sha);
|
|
|
+ string json = JsonHelper.ToJson(slide, ignoreNullValue: false);
|
|
|
+ string guid = Guid.NewGuid().ToString("N");
|
|
|
+ blobslidenames.Add(new KeyValuePair<string, string>(guid, json));
|
|
|
}
|
|
|
- Dictionary<string, string> bloburls = new Dictionary<string, string>();
|
|
|
- foreach (var key in texts.Keys)
|
|
|
+ ConcurrentDictionary<string, string> bloburls = new ConcurrentDictionary<string, string>();
|
|
|
+
|
|
|
+ foreach (var key in blobslidenames)
|
|
|
{
|
|
|
- tasks.Add(_azureStorage.UploadFileByContainer(id, texts[key], "res", FileName + "/" + key + ".json", false)
|
|
|
- .ContinueWith((Task<AzureBlobModel> blob) =>
|
|
|
- {
|
|
|
- bloburls.Add(key, blob.Result.BlobUrl);
|
|
|
- })
|
|
|
- );
|
|
|
+ tasks.Add(_azureStorage.UploadFileByContainer(id, key.Value, "res", $"{FileName}/{key.Key}.json" , false));
|
|
|
}
|
|
|
+
|
|
|
await Task.WhenAll(tasks);
|
|
|
List<Sld> slds = new List<Sld>();
|
|
|
foreach (string sha in shas)
|
|
@@ -287,14 +286,15 @@ namespace TEAMModelOS.Controllers
|
|
|
dict.TryAdd(key, str);
|
|
|
}
|
|
|
await Task.WhenAll(tasksFiles);
|
|
|
- hTEX.stores = dict;
|
|
|
- hTEX.slides = slds;
|
|
|
- var blob= await _azureStorage.UploadFileByContainer(id, JsonHelper.ToJson(hTEX, ignoreNullValue: false), "res", FileName + "/" + "index.json", false);
|
|
|
+ index.stores = dict;
|
|
|
+ index.slides = slds;
|
|
|
+ var blob = await _azureStorage.UploadFileByContainer(id, JsonHelper.ToJson(index, ignoreNullValue: false), "res", FileName + "/" + "index.json", false);
|
|
|
return System.Web.HttpUtility.UrlDecode(blob.BlobUrl, Encoding.UTF8);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public class HTEX {
|
|
|
+ public class HTEXIndex
|
|
|
+ {
|
|
|
public string id { get; set; }
|
|
|
public string version { get; set; } = "1.0.20201210";
|
|
|
public string name { get; set; }
|
|
@@ -314,7 +314,8 @@ namespace TEAMModelOS.Controllers
|
|
|
public string scope { get; set; }
|
|
|
public int? multipleRule { get; set; }
|
|
|
}
|
|
|
- public class Sld {
|
|
|
+ public class Sld
|
|
|
+ {
|
|
|
/// <summary>
|
|
|
/// normal,普通的hte页面 single 单选题 multiple 多选题 judge 判断题 complete 填空题 subjective 问答题 compose 综合题
|
|
|
/// </summary>
|
|
@@ -333,7 +334,8 @@ namespace TEAMModelOS.Controllers
|
|
|
public string thumbnail { get; set; }
|
|
|
}
|
|
|
|
|
|
- public class Scoring {
|
|
|
+ public class Scoring
|
|
|
+ {
|
|
|
public double score { get; set; }
|
|
|
public List<string> ans { get; set; } = new List<string>();
|
|
|
}
|