mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-04-17 12:06:34 +02:00
Main build (Jenkins)
This commit is contained in:
parent
3687dab26a
commit
4ec224d366
12496
service/dictionaries/en.json
vendored
12496
service/dictionaries/en.json
vendored
File diff suppressed because it is too large
Load Diff
4
src/en/OInt/core/Modules/OPI_Telegram.os
vendored
4
src/en/OInt/core/Modules/OPI_Telegram.os
vendored
@ -283,9 +283,9 @@ Function ProcessTMAData(Val DataString, Val Token) Export
|
||||
|
||||
Return ReturnMapping;
|
||||
|
||||
#Else
|
||||
|
||||
Return Undefined;
|
||||
#EndIf
|
||||
|
||||
|
||||
EndFunction
|
||||
|
||||
|
@ -52,6 +52,8 @@ Var OPIObject Export;
|
||||
|
||||
Procedure MainHandler(Context, NexHandler) Export
|
||||
|
||||
|
||||
|
||||
Try
|
||||
Result = ProcessRequest(Context);
|
||||
Except
|
||||
@ -60,7 +62,7 @@ Procedure MainHandler(Context, NexHandler) Export
|
||||
|
||||
Context.Response.StatusCode = 500;
|
||||
|
||||
Result = New Structure("result,error", False, "OneScript exception: " + Error);
|
||||
Result = New Structure("result,error", False, "OneScript exception " + Error);
|
||||
|
||||
EndTry;
|
||||
|
||||
@ -69,6 +71,10 @@ Procedure MainHandler(Context, NexHandler) Export
|
||||
Context.Response.ContentType = "application/json;charset=UTF8";
|
||||
Context.Response.Write(JSON);
|
||||
|
||||
|
||||
Raise "The method is not available on the client!";
|
||||
|
||||
|
||||
EndProcedure
|
||||
|
||||
Function ProcessRequest(Context)
|
||||
@ -102,15 +108,19 @@ EndFunction
|
||||
Function ExecuteProcessing(Context, Handler)
|
||||
|
||||
Method = Upper(Context.Request.Method);
|
||||
HandlerMethod = Upper(Handler["method"]);
|
||||
MethodForCheck = ?(HandlerMethod = "MULTIPART", "POST", HandlerMethod);
|
||||
|
||||
If Not Method = Upper(Handler["method"]) Then
|
||||
Return ProcessingError(Context, 405, "Method not allowed for this handler");
|
||||
If Not Method = MethodForCheck Then
|
||||
Return ProcessingError(Context, 405, "Method " + Method + " is not available for this handler!");
|
||||
EndIf;
|
||||
|
||||
If Method = "GET" Then
|
||||
If HandlerMethod = "GET" Then
|
||||
Result = ExecuteProcessingGet(Context, Handler);
|
||||
ElsIf HandlerMethod = "POST" Then
|
||||
Result = ExecuteProcessinPost(Context, Handler);
|
||||
Else
|
||||
Result = ProcessingError(Context, 405, "Method not allowed for this handler");
|
||||
Result = ProcessingError(Context, 405, "Method " + Method + " is not available for this handler!");
|
||||
EndIf;
|
||||
|
||||
Return Result;
|
||||
@ -123,6 +133,61 @@ Function ExecuteProcessingGet(Context, Handler)
|
||||
Parameters = Request.Parameters;
|
||||
Arguments = Handler["args"];
|
||||
|
||||
ParametersBoiler = FormParametersBoiler(Arguments, Parameters);
|
||||
|
||||
Return ExecuteUniversalProcessing(Context
|
||||
, Handler["library"]
|
||||
, Handler["function"]
|
||||
, ParametersBoiler);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExecuteProcessinPost(Context, Handler)
|
||||
|
||||
Request = Context.Request;
|
||||
Arguments = Handler["args"];
|
||||
|
||||
Body = Request.Body;
|
||||
JSONReader = New JSONReader();
|
||||
JSONReader.OpenStream(Body);
|
||||
|
||||
Parameters = ReadJSON(JSONReader, True);
|
||||
JSONReader.Close();
|
||||
|
||||
ParametersBoiler = FormParametersBoiler(Arguments, Parameters);
|
||||
|
||||
Return ExecuteUniversalProcessing(Context
|
||||
, Handler["library"]
|
||||
, Handler["function"]
|
||||
, ParametersBoiler);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExecuteUniversalProcessing(Context, Command, Method, Parameters)
|
||||
|
||||
ExecutionStructure = OPIObject.FormMethodCallString(Parameters, Command, Method);
|
||||
|
||||
Response = Undefined;
|
||||
|
||||
If ExecutionStructure["Error"] Then
|
||||
Response = New Structure("result,error", False, "Error in the name of a command or handler function!");
|
||||
Else
|
||||
|
||||
ExecutionText = ExecutionStructure["Result"];
|
||||
|
||||
Execute(ExecutionText);
|
||||
|
||||
|
||||
Response = New Structure("result,data", True, Response);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormParametersBoiler(Arguments, Parameters)
|
||||
|
||||
StrictArguments = New Map;
|
||||
NonStrictArguments = New Map;
|
||||
|
||||
@ -157,33 +222,7 @@ Function ExecuteProcessingGet(Context, Handler)
|
||||
ParametersBoiler.Insert(Argument.Key, Argument.Value);
|
||||
EndDo;
|
||||
|
||||
Return ExecuteUniversalProcessing(Context
|
||||
, Handler["library"]
|
||||
, Handler["function"]
|
||||
, ParametersBoiler);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExecuteUniversalProcessing(Context, Command, Method, Parameters)
|
||||
|
||||
ExecutionStructure = OPIObject.FormMethodCallString(Parameters, Command, Method);
|
||||
|
||||
Response = Undefined;
|
||||
|
||||
If ExecutionStructure["Error"] Then
|
||||
Response = New Structure("result,error", False, "Error in a handler command or method");
|
||||
Else
|
||||
|
||||
ExecutionText = ExecutionStructure["Result"];
|
||||
|
||||
Execute(ExecutionText);
|
||||
|
||||
|
||||
Response = New Structure("result,data", True, Response);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
Return ParametersBoiler;
|
||||
|
||||
EndFunction
|
||||
|
||||
|
@ -1168,6 +1168,144 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Multipart
|
||||
|
||||
// by Vitaly Cherkasov (cherkasovvitalik)
|
||||
// https://infostart.ru/1c/articles/1522786/
|
||||
|
||||
Function ParseMultipart(Val Headers, Val Body) Export
|
||||
|
||||
DataMap = New Map;
|
||||
Delimiter = GetMultipartMessageSeparator(Headers);
|
||||
|
||||
Markers = New Array();
|
||||
Markers.Add(ПолучитьБуферДвоичныхДанныхИзСтроки("==" + Delimiter));
|
||||
Markers.Add(ПолучитьБуферДвоичныхДанныхИзСтроки("==" + Delimiter + Chars.LF));
|
||||
Markers.Add(ПолучитьБуферДвоичныхДанныхИзСтроки("==" + Delimiter + Chars.CR));
|
||||
Markers.Add(ПолучитьБуферДвоичныхДанныхИзСтроки("==" + Delimiter + Chars.CR + Chars.LF));
|
||||
Markers.Add(ПолучитьБуферДвоичныхДанныхИзСтроки("==" + Delimiter + "=="));
|
||||
|
||||
DataReader = New DataReader(Body);
|
||||
DataReader.SkipTo(Markers);
|
||||
|
||||
CommonBinaryDataBuffer = DataReader.ReadIntoBinaryDataBuffer();
|
||||
BinaryBuffers = CommonBinaryDataBuffer.Split(Markers);
|
||||
|
||||
For Each Buffer In BinaryBuffers Do
|
||||
|
||||
Stream = New MemoryStream(Buffer);
|
||||
PartReading = New DataReader(Stream);
|
||||
|
||||
PartHeaders = ReadHeaders(PartReading);
|
||||
PartName = GetMessageName(PartHeaders);
|
||||
CurrentData = PartReading.Read().GetBinaryData();
|
||||
|
||||
DataMap.Insert(PartName, CurrentData);
|
||||
|
||||
PartReading.Close();
|
||||
Stream.Close();
|
||||
|
||||
EndDo;
|
||||
|
||||
Return DataMap;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ReadHeaders(Reading)
|
||||
|
||||
Headers = New Map;
|
||||
|
||||
While True Do
|
||||
|
||||
CurrentRow = Reading.ReadLine();
|
||||
|
||||
If CurrentRow = "" Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
Parts = StrSplit(CurrentRow, ":");
|
||||
|
||||
HeaderName = TrimAll(Parts[0]);
|
||||
Value = TrimAll(Parts[1]);
|
||||
|
||||
Headers.Insert(HeaderName, Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetMultipartMessageSeparator(Headers)
|
||||
|
||||
ExceptionText = "For Multipart requests correct Content-Type with boundary is required!";
|
||||
ContentType = Headers.Get("Content-Type");
|
||||
|
||||
If Not ValueIsFilled(ContentType) Then
|
||||
Raise ExceptionText;
|
||||
EndIf;
|
||||
|
||||
Properties = StrSplit(ContentType, ";", False);
|
||||
Border = Undefined;
|
||||
|
||||
For Each Property In Properties Do
|
||||
|
||||
Parts = StrSplit(Property, "=", False);
|
||||
PropertyName = TrimAll(Parts[0]);
|
||||
|
||||
If PropertyName <> "boundary" Then
|
||||
Continue;
|
||||
EndIf;
|
||||
|
||||
Border = TrimAll(Parts[1]);
|
||||
Break;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Not ValueIsFilled(Border) Then
|
||||
Raise ExceptionText;
|
||||
Else
|
||||
Return Border;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetMessageName(Headers)
|
||||
|
||||
ExceptionText = "Content-Disposition of one of the parts is not found or has invalid format!";
|
||||
Description = Headers.Get("Content-Disposition");
|
||||
|
||||
If Not ValueIsFilled(Description) Then
|
||||
Raise ExceptionText;
|
||||
EndIf;
|
||||
|
||||
Properties = StrSplit(Description, ";", False);
|
||||
Name = Undefined;
|
||||
|
||||
For Each Property In Properties Do
|
||||
|
||||
Parts = StrSplit(Property, "=", False);
|
||||
PropertyName = TrimAll(Parts[0]);
|
||||
|
||||
If PropertyName <> "name" And PropertyName <> "Name" Then
|
||||
Continue;
|
||||
EndIf;
|
||||
|
||||
Name = TrimAll(Parts[1]);
|
||||
Break;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Not ValueIsFilled(Name) Then
|
||||
Raise ExceptionText;
|
||||
Else
|
||||
Return Name;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
138
src/en/OPI/src/CommonModules/OPI_Tools/Module.bsl
vendored
138
src/en/OPI/src/CommonModules/OPI_Tools/Module.bsl
vendored
@ -1168,6 +1168,144 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Multipart
|
||||
|
||||
// by Vitaly Cherkasov (cherkasovvitalik)
|
||||
// https://infostart.ru/1c/articles/1522786/
|
||||
|
||||
Function ParseMultipart(Val Headers, Val Body) Export
|
||||
|
||||
DataMap = New Map;
|
||||
Delimiter = GetMultipartMessageSeparator(Headers);
|
||||
|
||||
Markers = New Array();
|
||||
Markers.Add(GetBinaryDataBufferFromString("==" + Delimiter));
|
||||
Markers.Add(GetBinaryDataBufferFromString("==" + Delimiter + Chars.LF));
|
||||
Markers.Add(GetBinaryDataBufferFromString("==" + Delimiter + Chars.CR));
|
||||
Markers.Add(GetBinaryDataBufferFromString("==" + Delimiter + Chars.CR + Chars.LF));
|
||||
Markers.Add(GetBinaryDataBufferFromString("==" + Delimiter + "=="));
|
||||
|
||||
DataReader = New DataReader(Body);
|
||||
DataReader.SkipTo(Markers);
|
||||
|
||||
CommonBinaryDataBuffer = DataReader.ReadIntoBinaryDataBuffer();
|
||||
BinaryBuffers = CommonBinaryDataBuffer.Split(Markers);
|
||||
|
||||
For Each Buffer In BinaryBuffers Do
|
||||
|
||||
Stream = New MemoryStream(Buffer);
|
||||
PartReading = New DataReader(Stream);
|
||||
|
||||
PartHeaders = ReadHeaders(PartReading);
|
||||
PartName = GetMessageName(PartHeaders);
|
||||
CurrentData = PartReading.Read().GetBinaryData();
|
||||
|
||||
DataMap.Insert(PartName, CurrentData);
|
||||
|
||||
PartReading.Close();
|
||||
Stream.Close();
|
||||
|
||||
EndDo;
|
||||
|
||||
Return DataMap;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ReadHeaders(Reading)
|
||||
|
||||
Headers = New Map;
|
||||
|
||||
While True Do
|
||||
|
||||
CurrentRow = Reading.ReadLine();
|
||||
|
||||
If CurrentRow = "" Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
Parts = StrSplit(CurrentRow, ":");
|
||||
|
||||
HeaderName = TrimAll(Parts[0]);
|
||||
Value = TrimAll(Parts[1]);
|
||||
|
||||
Headers.Insert(HeaderName, Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetMultipartMessageSeparator(Headers)
|
||||
|
||||
ExceptionText = "For Multipart requests correct Content-Type with boundary is required!";
|
||||
ContentType = Headers.Get("Content-Type");
|
||||
|
||||
If Not ValueIsFilled(ContentType) Then
|
||||
Raise ExceptionText;
|
||||
EndIf;
|
||||
|
||||
Properties = StrSplit(ContentType, ";", False);
|
||||
Border = Undefined;
|
||||
|
||||
For Each Property In Properties Do
|
||||
|
||||
Parts = StrSplit(Property, "=", False);
|
||||
PropertyName = TrimAll(Parts[0]);
|
||||
|
||||
If PropertyName <> "boundary" Then
|
||||
Continue;
|
||||
EndIf;
|
||||
|
||||
Border = TrimAll(Parts[1]);
|
||||
Break;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Not ValueIsFilled(Border) Then
|
||||
Raise ExceptionText;
|
||||
Else
|
||||
Return Border;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetMessageName(Headers)
|
||||
|
||||
ExceptionText = "Content-Disposition of one of the parts is not found or has invalid format!";
|
||||
Description = Headers.Get("Content-Disposition");
|
||||
|
||||
If Not ValueIsFilled(Description) Then
|
||||
Raise ExceptionText;
|
||||
EndIf;
|
||||
|
||||
Properties = StrSplit(Description, ";", False);
|
||||
Name = Undefined;
|
||||
|
||||
For Each Property In Properties Do
|
||||
|
||||
Parts = StrSplit(Property, "=", False);
|
||||
PropertyName = TrimAll(Parts[0]);
|
||||
|
||||
If PropertyName <> "name" And PropertyName <> "Name" Then
|
||||
Continue;
|
||||
EndIf;
|
||||
|
||||
Name = TrimAll(Parts[1]);
|
||||
Break;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Not ValueIsFilled(Name) Then
|
||||
Raise ExceptionText;
|
||||
Else
|
||||
Return Name;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
@ -52,6 +52,8 @@ Var OPIObject Export;
|
||||
|
||||
Procedure MainHandler(Context, NexHandler) Export
|
||||
|
||||
#If Host Or ThickClientOrdinaryApplication Or ExternalConnection Then
|
||||
|
||||
Try
|
||||
Result = ProcessRequest(Context);
|
||||
Except
|
||||
@ -60,7 +62,7 @@ Procedure MainHandler(Context, NexHandler) Export
|
||||
|
||||
Context.Response.StatusCode = 500;
|
||||
|
||||
Result = New Structure("result,error", False, "OneScript exception: " + Error);
|
||||
Result = New Structure("result,error", False, "OneScript exception " + Error);
|
||||
|
||||
EndTry;
|
||||
|
||||
@ -69,6 +71,10 @@ Procedure MainHandler(Context, NexHandler) Export
|
||||
Context.Response.ContentType = "application/json;charset=UTF8";
|
||||
Context.Response.Write(JSON);
|
||||
|
||||
#Else
|
||||
Raise "The method is not available on the client!";
|
||||
#EndIf
|
||||
|
||||
EndProcedure
|
||||
|
||||
Function ProcessRequest(Context)
|
||||
@ -102,15 +108,19 @@ EndFunction
|
||||
Function ExecuteProcessing(Context, Handler)
|
||||
|
||||
Method = Upper(Context.Request.Method);
|
||||
HandlerMethod = Upper(Handler["method"]);
|
||||
MethodForCheck = ?(HandlerMethod = "MULTIPART", "POST", HandlerMethod);
|
||||
|
||||
If Not Method = Upper(Handler["method"]) Then
|
||||
Return ProcessingError(Context, 405, "Method not allowed for this handler");
|
||||
If Not Method = MethodForCheck Then
|
||||
Return ProcessingError(Context, 405, "Method " + Method + " is not available for this handler!");
|
||||
EndIf;
|
||||
|
||||
If Method = "GET" Then
|
||||
If HandlerMethod = "GET" Then
|
||||
Result = ExecuteProcessingGet(Context, Handler);
|
||||
ElsIf HandlerMethod = "POST" Then
|
||||
Result = ExecuteProcessinPost(Context, Handler);
|
||||
Else
|
||||
Result = ProcessingError(Context, 405, "Method not allowed for this handler");
|
||||
Result = ProcessingError(Context, 405, "Method " + Method + " is not available for this handler!");
|
||||
EndIf;
|
||||
|
||||
Return Result;
|
||||
@ -123,6 +133,61 @@ Function ExecuteProcessingGet(Context, Handler)
|
||||
Parameters = Request.Parameters;
|
||||
Arguments = Handler["args"];
|
||||
|
||||
ParametersBoiler = FormParametersBoiler(Arguments, Parameters);
|
||||
|
||||
Return ExecuteUniversalProcessing(Context
|
||||
, Handler["library"]
|
||||
, Handler["function"]
|
||||
, ParametersBoiler);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExecuteProcessinPost(Context, Handler)
|
||||
|
||||
Request = Context.Request;
|
||||
Arguments = Handler["args"];
|
||||
|
||||
Body = Request.Body;
|
||||
JSONReader = New JSONReader();
|
||||
JSONReader.OpenStream(Body);
|
||||
|
||||
Parameters = ReadJSON(JSONReader, True);
|
||||
JSONReader.Close();
|
||||
|
||||
ParametersBoiler = FormParametersBoiler(Arguments, Parameters);
|
||||
|
||||
Return ExecuteUniversalProcessing(Context
|
||||
, Handler["library"]
|
||||
, Handler["function"]
|
||||
, ParametersBoiler);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExecuteUniversalProcessing(Context, Command, Method, Parameters)
|
||||
|
||||
ExecutionStructure = OPIObject.FormMethodCallString(Parameters, Command, Method);
|
||||
|
||||
Response = Undefined;
|
||||
|
||||
If ExecutionStructure["Error"] Then
|
||||
Response = New Structure("result,error", False, "Error in the name of a command or handler function!");
|
||||
Else
|
||||
|
||||
ExecutionText = ExecutionStructure["Result"];
|
||||
SetSafeMode(True);
|
||||
Execute(ExecutionText);
|
||||
SetSafeMode(False);
|
||||
|
||||
Response = New Structure("result,data", True, Response);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormParametersBoiler(Arguments, Parameters)
|
||||
|
||||
StrictArguments = New Map;
|
||||
NonStrictArguments = New Map;
|
||||
|
||||
@ -157,33 +222,7 @@ Function ExecuteProcessingGet(Context, Handler)
|
||||
ParametersBoiler.Insert(Argument.Key, Argument.Value);
|
||||
EndDo;
|
||||
|
||||
Return ExecuteUniversalProcessing(Context
|
||||
, Handler["library"]
|
||||
, Handler["function"]
|
||||
, ParametersBoiler);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExecuteUniversalProcessing(Context, Command, Method, Parameters)
|
||||
|
||||
ExecutionStructure = OPIObject.FormMethodCallString(Parameters, Command, Method);
|
||||
|
||||
Response = Undefined;
|
||||
|
||||
If ExecutionStructure["Error"] Then
|
||||
Response = New Structure("result,error", False, "Error in a handler command or method");
|
||||
Else
|
||||
|
||||
ExecutionText = ExecutionStructure["Result"];
|
||||
SetSafeMode(True);
|
||||
Execute(ExecutionText);
|
||||
SetSafeMode(False);
|
||||
|
||||
Response = New Structure("result,data", True, Response);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
Return ParametersBoiler;
|
||||
|
||||
EndFunction
|
||||
|
||||
|
@ -1176,7 +1176,7 @@
|
||||
Функция РазобратьMultipart(Знач Заголовки, Знач Тело) Экспорт
|
||||
|
||||
СоответствиеДанных = Новый Соответствие;
|
||||
Разделитель = ПолучитьРазделительСоставногоСообщения(заголовки);
|
||||
Разделитель = ПолучитьРазделительСоставногоСообщения(Заголовки);
|
||||
|
||||
Маркеры = Новый Массив();
|
||||
Маркеры.Добавить(ПолучитьБуферДвоичныхДанныхИзСтроки("==" + Разделитель));
|
||||
@ -1197,7 +1197,7 @@
|
||||
ЧтениеЧасти = Новый ЧтениеДанных(Поток);
|
||||
|
||||
ЗаголовкиЧасти = ПрочитатьЗаголовки(ЧтениеЧасти);
|
||||
ИмяЧасти = ПолучитьИмяСообщения(заголовкиЧасти);
|
||||
ИмяЧасти = ПолучитьИмяСообщения(ЗаголовкиЧасти);
|
||||
ТекущиеДанные = ЧтениеЧасти.Прочитать().ПолучитьДвоичныеДанные();
|
||||
|
||||
СоответствиеДанных.Вставить(ИмяЧасти, ТекущиеДанные);
|
||||
|
Loading…
x
Reference in New Issue
Block a user