1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-08-10 22:41:43 +02:00

Main build (Jenkins)

This commit is contained in:
Vitaly the Alpaca (bot)
2025-02-04 20:58:03 +03:00
parent c358aeb247
commit eb84c9e940
20 changed files with 6793 additions and 6985 deletions

View File

@@ -17,7 +17,7 @@ import TabItem from '@theme/TabItem';
| Project | --proj | String | ✔ | Project filepath |
| OintLibrary | --lib | String | ✔ | Library name in CLI command format |
| OintFunction | --func | String | ✔ | OpenIntegrations function name |
| Method | --method | String | ✖ | HTTP method that will process the handler: GET, POST, MULTIPART |
| Method | --method | String | ✖ | HTTP method that will process the handler: GET, POST, FORM |
Returns: Structure Of KeyAndValue - Result of handler creation

View File

@@ -18,7 +18,7 @@ import TabItem from '@theme/TabItem';
| HandlerKey | --handler | String | ✔ | Handler key |
| OintLibrary | --lib | String | ✖ | Library name in CLI command format |
| OintFunction | --func | String | ✖ | OpenIntegrations function name |
| Method | --method | String | ✖ | HTTP method that will process the handler: GET, POST, MULTIPART |
| Method | --method | String | ✖ | HTTP method that will process the handler: GET, POST, FORM |
Returns: Structure Of KeyAndValue - Result of handler modification

View File

@@ -17,7 +17,7 @@ import TabItem from '@theme/TabItem';
| Проект | --proj | Строка | ✔ | Путь к файлу проекта |
| БиблиотекаОПИ | --lib | Строка | ✔ | Имя библиотеки в CLI формате |
| ФункцияОПИ | --func | Строка | ✔ | Имя функции Открытого пакета интеграций |
| Метод | --method | Строка | ✖ | HTTP метод, который будет обрабатывать обработчик: GET, POST, MULTIPART |
| Метод | --method | Строка | ✖ | HTTP метод, который будет обрабатывать обработчик: GET, POST, FORM |
Возвращаемое значение: Структура Из КлючИЗначение - Результат добавления обработчика

View File

@@ -18,7 +18,7 @@ import TabItem from '@theme/TabItem';
| КлючОбработчика | --handler | Строка | ✔ | Ключ обработчика |
| БиблиотекаОПИ | --lib | Строка | ✖ | Имя библиотеки в CLI формате |
| ФункцияОПИ | --func | Строка | ✖ | Имя функции Открытого пакета интеграций |
| Метод | --method | Строка | ✖ | HTTP метод, который будет обрабатывать обработчик: GET, POST, MULTIPART |
| Метод | --method | Строка | ✖ | HTTP метод, который будет обрабатывать обработчик: GET, POST, FORM |
Возвращаемое значение: Структура Из КлючИЗначение - Результат изменения обработчика

File diff suppressed because it is too large Load Diff

View File

@@ -116,7 +116,7 @@ EndFunction
// Project - String - Project filepath - proj
// OintLibrary - String - Library name in CLI command format - lib
// OintFunction - String - OpenIntegrations function name - func
// Method - String - HTTP method that will process the handler: GET, POST, MULTIPART - method
// Method - String - HTTP method that will process the handler: GET, POST, FORM - method
//
// Returns:
// Structure Of KeyAndValue - Result of handler creation
@@ -126,6 +126,7 @@ Function AddRequestsHandler(Val Project, Val OintLibrary, Val OintFunction, Val
OPI_TypeConversion.GetLine(OintFunction);
OPI_TypeConversion.GetLine(Method);
Method = Upper(Method);
Result = CheckProjectExistence(Project);
If Not Result["result"] Then
@@ -134,10 +135,14 @@ Function AddRequestsHandler(Val Project, Val OintLibrary, Val OintFunction, Val
Project = Result["path"];
EndIf;
If Not Method = "GET" And Not Method = "POST" And Not Method = "FORM" Then
Return FormResponse(False, StrTemplate("Unsupported method %1!", Method));
EndIf;
SecretKey = GetHandlerUniqueKey(Project);
If TypeOf(SecretKey) = Type("Map") Then
SecretKey.Insert("message", "Failed to generate a handler UID. Try again");
SecretKey.Insert("message", "Failed to generate a handler UID. Try again!");
Return SecretKey;
EndIf;
@@ -241,7 +246,7 @@ Function GetRequestsHandler(Val Project, Val HandlerKey) Export
Else
If RecordsCount = 0 Then
Result = FormResponse(False, "Handler not found");
Result = FormResponse(False, "Handler not found!");
EndIf;
EndIf;
@@ -309,7 +314,7 @@ EndFunction
// HandlerKey - String - Handler key - handler
// OintLibrary - String - Library name in CLI command format - lib
// OintFunction - String - OpenIntegrations function name - func
// Method - String - HTTP method that will process the handler: GET, POST, MULTIPART - method
// Method - String - HTTP method that will process the handler: GET, POST, FORM - method
//
// Returns:
// Structure Of KeyAndValue - Result of handler modification
@@ -509,16 +514,16 @@ Function CheckProjectExistence(Path)
OPI_Tools.RestoreEscapeSequences(Path);
ProjectFile = New File(Path);
Text = "The project file exists";
Text = "The project file already exists!";
Result = True;
If Not ProjectFile.Exist() Then
Text = "Project file not found at the specified path";
Text = "Project file not found at the specified path!";
Result = False;
EndIf;
If ProjectFile.IsDirectory() Then
Text = "A directory path was passed, not a project file";
Text = "A directory path was passed, not a project file!";
Result = False;
EndIf;
@@ -557,7 +562,7 @@ Function NormalizeProject(Path)
Result = CreateNewProject(FullPath);
If Result["result"] Then
Text = "The project file was created successfully";
Text = "The project file has been successfully created!";
Response = FormResponse(True, Text, FullPath);
Else
Response = Result;
@@ -565,7 +570,7 @@ Function NormalizeProject(Path)
Else
Text = "The project file at the specified path already exists";
Text = "The project file at the specified path already exists!";
Response = FormResponse(False, Text, FullPath);
EndIf;
@@ -717,7 +722,7 @@ Function UpdateHandlerFields(Val Project, Val HandlerKey, Val RecordStructure)
, Project);
Else
Result = FormResponse(False, "Nothing to change");
Result = FormResponse(False, "Nothing to change!");
EndIf;
Return Result;

View File

@@ -79,7 +79,7 @@
NewLine.Метод = "AddRequestsHandler";
NewLine.МетодПоиска = "ADDREQUESTSHANDLER";
NewLine.Параметр = "--method";
NewLine.Описание = "HTTP method that will process the handler: GET, POST, MULTIPART (optional, def. val. - GET)";
NewLine.Описание = "HTTP method that will process the handler: GET, POST, FORM (optional, def. val. - GET)";
NewLine.Область = "Handlers configuration";
@@ -183,7 +183,7 @@
NewLine.Метод = "UpdateRequestsHandler";
NewLine.МетодПоиска = "UPDATEREQUESTSHANDLER";
NewLine.Параметр = "--method";
NewLine.Описание = "HTTP method that will process the handler: GET, POST, MULTIPART (optional, def. val. - Empty value)";
NewLine.Описание = "HTTP method that will process the handler: GET, POST, FORM (optional, def. val. - Empty value)";
NewLine.Область = "Handlers configuration";

View File

@@ -60,12 +60,24 @@ Procedure MainHandler(Context, NexHandler) Export
Result = ProcessRequest(Context);
Except
Error = BriefErrorDescription(ErrorInfo());
Information = ErrorInfo();
Result = New Structure("result,error", False, Information.Description);
If StrFind(Information.SourceLine, "Raise") = 0 Then
ModuleFile = New File(Information.ModuleName);
ExceptionStructure = New Structure;
ExceptionStructure.Insert("module", ModuleFile.Name);
ExceptionStructure.Insert("row" , Information.LineNumber);
ExceptionStructure.Insert("code" , TrimAll(Information.SourceLine));
Result.Insert("exception", ExceptionStructure);
EndIf;
Context.Response.StatusCode = 500;
Result = New Structure("result,error", False, "OneScript exception " + Error);
EndTry;
JSON = OPI_Tools.JSONString(Result);
@@ -74,6 +86,7 @@ Procedure MainHandler(Context, NexHandler) Export
Context.Response.Write(JSON);
#EndIf
EndProcedure
Function ProcessRequest(Context)
@@ -108,7 +121,7 @@ Function ExecuteProcessing(Context, Handler)
Method = Upper(Context.Request.Method);
HandlerMethod = Upper(Handler["method"]);
MethodForCheck = ?(HandlerMethod = "MULTIPART", "POST", HandlerMethod);
MethodForCheck = ?(HandlerMethod = "FORM", "POST", HandlerMethod);
If Not Method = MethodForCheck Then
Return ProcessingError(Context, 405, "Method " + Method + " is not available for this handler!");
@@ -122,9 +135,9 @@ Function ExecuteProcessing(Context, Handler)
Result = ExecuteProcessinPost(Context, Handler);
ElsIf HandlerMethod = "MULTIPART" Then
ElsIf HandlerMethod = "FORM" Then
Result = ExecuteProcessinMultipart(Context, Handler);
Result = ExecuteProcessingFormData(Context, Handler);
Else
@@ -160,7 +173,7 @@ Function ExecuteProcessinPost(Context, Handler)
EndFunction
Function ExecuteProcessinMultipart(Context, Handler)
Function ExecuteProcessingFormData(Context, Handler)
#If Client Then
Raise "The method is not available on the client!";
@@ -168,10 +181,11 @@ Function ExecuteProcessinMultipart(Context, Handler)
Request = Context.Request;
Body = Request.Body;
Headers = Request.Headers;
If Not ValueIsFilled(Request.Form) Then
Raise "No form data found!";
EndIf;
Parameters = OPI_Tools.ParseMultipart(Body, Headers);
Parameters = OPI_Tools.ParseFormData(Request.Form);
Return ExecuteUniversalProcessing(Context, Handler, Parameters);
@@ -207,9 +221,26 @@ Function ExecuteUniversalProcessing(Context, Handler, Parameters)
ParametersBoiler.Insert(CurrentKey, TFN);
ElsIf TypeOf(CurrentValue) = Type("FormFile") Then
//@skip-check missing-temporary-file-deletion
TFN = GetTempFileName();
StreamOfFile = CurrentValue.OpenReadStream();
WritingStream = New FileStream(TFN, FileOpenMode.OpenOrCreate);
StreamOfFile.CopyTo(WritingStream);
StreamOfFile.Close();
WritingStream.Close();
TFArray.Add(TFN);
ParametersBoiler.Insert(CurrentKey, TFN);
Else
OPI_TypeConversion.GetLine(CurrentValue);
ParametersBoiler.Insert(CurrentValue, TFN);
ParametersBoiler.Insert(CurrentKey, CurrentValue);
EndIf;
EndDo;

View File

@@ -1166,52 +1166,20 @@ Function IsPrimitiveType(Val Value) Export
EndFunction
#EndRegion
Function ParseFormData(Val Form) Export
#Region Multipart
DataMap = New Map;
Files = Form.Files;
// by Vitaly Cherkasov (cherkasovvitalik)
// https://infostart.ru/1c/articles/1522786/
For Each Field In Form Do
Function ParseMultipart(Val Headers, Val Body) Export
DataMap.Insert(Field.Key, Field.Value);
DataMap = New Map;
Delimiter = GetMultipartMessageSeparator(Headers);
EndDo;
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 + "=="));
For Each File In Files Do
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);
PartData = GetMessageName(PartHeaders);
PartName = PartData["name"];
FileName = PartData["filename"];
CurrentData = PartReading.Read().GetBinaryData();
If Not ValueIsFilled(FileName) Then
CurrentData = ПолучитьСтрокуИзДвоичныхДанных(CurrentData);
EndIf;
DataMap.Insert(PartName, CurrentData);
PartReading.Close();
Stream.Close();
DataMap.Insert(File.Name, File);
EndDo;
@@ -1219,106 +1187,6 @@ Function ParseMultipart(Val Headers, Val Body) Export
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");
ReturnStructure = New Structure("name,filename");
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]);
PropertyName = Lower(PropertyName);
If PropertyName = "name" Then
ReturnStructure["name"] = TrimAll(Parts[1]);
ElsIf PropertyName = "filename"Then
ReturnStructure["filename"] = TrimAll(Parts[1]);
Else
Continue;
EndIf;
EndDo;
If Not ValueIsFilled(ReturnStructure["name"]) Then
Raise ExceptionText;
Else
Return ReturnStructure;
EndIf;
EndFunction
#EndRegion
#EndRegion

View File

@@ -116,7 +116,7 @@ EndFunction
// Project - String - Project filepath - proj
// OintLibrary - String - Library name in CLI command format - lib
// OintFunction - String - OpenIntegrations function name - func
// Method - String - HTTP method that will process the handler: GET, POST, MULTIPART - method
// Method - String - HTTP method that will process the handler: GET, POST, FORM - method
//
// Returns:
// Structure Of KeyAndValue - Result of handler creation
@@ -126,6 +126,7 @@ Function AddRequestsHandler(Val Project, Val OintLibrary, Val OintFunction, Val
OPI_TypeConversion.GetLine(OintFunction);
OPI_TypeConversion.GetLine(Method);
Method = Upper(Method);
Result = CheckProjectExistence(Project);
If Not Result["result"] Then
@@ -134,10 +135,14 @@ Function AddRequestsHandler(Val Project, Val OintLibrary, Val OintFunction, Val
Project = Result["path"];
EndIf;
If Not Method = "GET" And Not Method = "POST" And Not Method = "FORM" Then
Return FormResponse(False, StrTemplate("Unsupported method %1!", Method));
EndIf;
SecretKey = GetHandlerUniqueKey(Project);
If TypeOf(SecretKey) = Type("Map") Then
SecretKey.Insert("message", "Failed to generate a handler UID. Try again");
SecretKey.Insert("message", "Failed to generate a handler UID. Try again!");
Return SecretKey;
EndIf;
@@ -241,7 +246,7 @@ Function GetRequestsHandler(Val Project, Val HandlerKey) Export
Else
If RecordsCount = 0 Then
Result = FormResponse(False, "Handler not found");
Result = FormResponse(False, "Handler not found!");
EndIf;
EndIf;
@@ -309,7 +314,7 @@ EndFunction
// HandlerKey - String - Handler key - handler
// OintLibrary - String - Library name in CLI command format - lib
// OintFunction - String - OpenIntegrations function name - func
// Method - String - HTTP method that will process the handler: GET, POST, MULTIPART - method
// Method - String - HTTP method that will process the handler: GET, POST, FORM - method
//
// Returns:
// Structure Of KeyAndValue - Result of handler modification
@@ -509,16 +514,16 @@ Function CheckProjectExistence(Path)
OPI_Tools.RestoreEscapeSequences(Path);
ProjectFile = New File(Path);
Text = "The project file exists";
Text = "The project file already exists!";
Result = True;
If Not ProjectFile.Exists() Then
Text = "Project file not found at the specified path";
Text = "Project file not found at the specified path!";
Result = False;
EndIf;
If ProjectFile.IsDirectory() Then
Text = "A directory path was passed, not a project file";
Text = "A directory path was passed, not a project file!";
Result = False;
EndIf;
@@ -557,7 +562,7 @@ Function NormalizeProject(Path)
Result = CreateNewProject(FullPath);
If Result["result"] Then
Text = "The project file was created successfully";
Text = "The project file has been successfully created!";
Response = FormResponse(True, Text, FullPath);
Else
Response = Result;
@@ -565,7 +570,7 @@ Function NormalizeProject(Path)
Else
Text = "The project file at the specified path already exists";
Text = "The project file at the specified path already exists!";
Response = FormResponse(False, Text, FullPath);
EndIf;
@@ -717,7 +722,7 @@ Function UpdateHandlerFields(Val Project, Val HandlerKey, Val RecordStructure)
, Project);
Else
Result = FormResponse(False, "Nothing to change");
Result = FormResponse(False, "Nothing to change!");
EndIf;
Return Result;

View File

@@ -1166,52 +1166,20 @@ Function IsPrimitiveType(Val Value) Export
EndFunction
#EndRegion
Function ParseFormData(Val Form) Export
#Region Multipart
DataMap = New Map;
Files = Form.Files;
// by Vitaly Cherkasov (cherkasovvitalik)
// https://infostart.ru/1c/articles/1522786/
For Each Field In Form Do
Function ParseMultipart(Val Headers, Val Body) Export
DataMap.Insert(Field.Key, Field.Value);
DataMap = New Map;
Delimiter = GetMultipartMessageSeparator(Headers);
EndDo;
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 + "=="));
For Each File In Files Do
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);
PartData = GetMessageName(PartHeaders);
PartName = PartData["name"];
FileName = PartData["filename"];
CurrentData = PartReading.Read().GetBinaryData();
If Not ValueIsFilled(FileName) Then
CurrentData = GetStringFromBinaryData(CurrentData);
EndIf;
DataMap.Insert(PartName, CurrentData);
PartReading.Close();
Stream.Close();
DataMap.Insert(File.Name, File);
EndDo;
@@ -1219,106 +1187,6 @@ Function ParseMultipart(Val Headers, Val Body) Export
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");
ReturnStructure = New Structure("name,filename");
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]);
PropertyName = Lower(PropertyName);
If PropertyName = "name" Then
ReturnStructure["name"] = TrimAll(Parts[1]);
ElsIf PropertyName = "filename"Then
ReturnStructure["filename"] = TrimAll(Parts[1]);
Else
Continue;
EndIf;
EndDo;
If Not ValueIsFilled(ReturnStructure["name"]) Then
Raise ExceptionText;
Else
Return ReturnStructure;
EndIf;
EndFunction
#EndRegion
#EndRegion

View File

@@ -60,12 +60,24 @@ Procedure MainHandler(Context, NexHandler) Export
Result = ProcessRequest(Context);
Except
Error = BriefErrorDescription(ErrorInfo());
Information = ErrorInfo();
Result = New Structure("result,error", False, Information.Description);
If StrFind(Information.SourceLine, "Raise") = 0 Then
ModuleFile = New File(Information.ModuleName);
ExceptionStructure = New Structure;
ExceptionStructure.Insert("module", ModuleFile.Name);
ExceptionStructure.Insert("row" , Information.LineNumber);
ExceptionStructure.Insert("code" , TrimAll(Information.SourceLine));
Result.Insert("exception", ExceptionStructure);
EndIf;
Context.Response.StatusCode = 500;
Result = New Structure("result,error", False, "OneScript exception " + Error);
EndTry;
JSON = OPI_Tools.JSONString(Result);
@@ -74,6 +86,7 @@ Procedure MainHandler(Context, NexHandler) Export
Context.Response.Write(JSON);
#EndIf
EndProcedure
Function ProcessRequest(Context)
@@ -108,7 +121,7 @@ Function ExecuteProcessing(Context, Handler)
Method = Upper(Context.Request.Method);
HandlerMethod = Upper(Handler["method"]);
MethodForCheck = ?(HandlerMethod = "MULTIPART", "POST", HandlerMethod);
MethodForCheck = ?(HandlerMethod = "FORM", "POST", HandlerMethod);
If Not Method = MethodForCheck Then
Return ProcessingError(Context, 405, "Method " + Method + " is not available for this handler!");
@@ -122,9 +135,9 @@ Function ExecuteProcessing(Context, Handler)
Result = ExecuteProcessinPost(Context, Handler);
ElsIf HandlerMethod = "MULTIPART" Then
ElsIf HandlerMethod = "FORM" Then
Result = ExecuteProcessinMultipart(Context, Handler);
Result = ExecuteProcessingFormData(Context, Handler);
Else
@@ -160,7 +173,7 @@ Function ExecuteProcessinPost(Context, Handler)
EndFunction
Function ExecuteProcessinMultipart(Context, Handler)
Function ExecuteProcessingFormData(Context, Handler)
#If Client Then
Raise "The method is not available on the client!";
@@ -168,10 +181,11 @@ Function ExecuteProcessinMultipart(Context, Handler)
Request = Context.Request;
Body = Request.Body;
Headers = Request.Headers;
If Not ValueIsFilled(Request.Form) Then
Raise "No form data found!";
EndIf;
Parameters = OPI_Tools.ParseMultipart(Body, Headers);
Parameters = OPI_Tools.ParseFormData(Request.Form);
Return ExecuteUniversalProcessing(Context, Handler, Parameters);
@@ -207,9 +221,26 @@ Function ExecuteUniversalProcessing(Context, Handler, Parameters)
ParametersBoiler.Insert(CurrentKey, TFN);
ElsIf TypeOf(CurrentValue) = Type("FormFile") Then
//@skip-check missing-temporary-file-deletion
TFN = GetTempFileName();
StreamOfFile = CurrentValue.OpenReadStream();
WritingStream = New FileStream(TFN, FileOpenMode.OpenOrCreate);
StreamOfFile.CopyTo(WritingStream);
StreamOfFile.Close();
WritingStream.Close();
TFArray.Add(TFN);
ParametersBoiler.Insert(CurrentKey, TFN);
Else
OPI_TypeConversion.GetLine(CurrentValue);
ParametersBoiler.Insert(CurrentValue, TFN);
ParametersBoiler.Insert(CurrentKey, CurrentValue);
EndIf;
EndDo;

View File

@@ -134,9 +134,9 @@
Иначе
Проект = Результат["path"];
КонецЕсли;
Если Не Метод = "GET" И Не Метод = "POST" И Не Метод = "FORM" Тогда
Возврат СформироватьОтвет(Ложь, СтрШаблон("Неподдерживаемый метод %1!", Метод));
Возврат СформироватьОтвет(Ложь, СтрШаблон("Неподдерживаемый метод %1!", Метод));
КонецЕсли;
СекретныйКлюч = ПолучитьУникальныйКлючОбработчика(Проект);
@@ -310,11 +310,11 @@
// Изменяет значения полей обработчика запросов
//
// Параметры:
// Проект - Строка - Путь к файлу проекта - proj
// КлючОбработчика - Строка - Ключ обработчика - handler
// БиблиотекаОПИ - Строка - Имя библиотеки в CLI формате - lib
// ФункцияОПИ - Строка - Имя функции Открытого пакета интеграций - func
// Метод - Строка - HTTP метод, который будет обрабатывать обработчик: GET, POST, MULTIPART - method
// Проект - Строка - Путь к файлу проекта - proj
// КлючОбработчика - Строка - Ключ обработчика - handler
// БиблиотекаОПИ - Строка - Имя библиотеки в CLI формате - lib
// ФункцияОПИ - Строка - Имя функции Открытого пакета интеграций - func
// Метод - Строка - HTTP метод, который будет обрабатывать обработчик: GET, POST, FORM - method
//
// Возвращаемое значение:
// Структура Из КлючИЗначение - Результат изменения обработчика

View File

@@ -79,7 +79,7 @@
НоваяСтрока.Метод = "ДобавитьОбработчикЗапросов";
НоваяСтрока.МетодПоиска = "ДОБАВИТЬОБРАБОТЧИКЗАПРОСОВ";
НоваяСтрока.Параметр = "--method";
НоваяСтрока.Описание = "HTTP метод, который будет обрабатывать обработчик: GET, POST, MULTIPART (необяз. по ум. - GET)";
НоваяСтрока.Описание = "HTTP метод, который будет обрабатывать обработчик: GET, POST, FORM (необяз. по ум. - GET)";
НоваяСтрока.Область = "Настройка обработчиков";
@@ -183,7 +183,7 @@
НоваяСтрока.Метод = "ИзменитьОбработчикЗапросов";
НоваяСтрока.МетодПоиска = "ИЗМЕНИТЬОБРАБОТЧИКЗАПРОСОВ";
НоваяСтрока.Параметр = "--method";
НоваяСтрока.Описание = "HTTP метод, который будет обрабатывать обработчик: GET, POST, MULTIPART (необяз. по ум. - Пустое значение)";
НоваяСтрока.Описание = "HTTP метод, который будет обрабатывать обработчик: GET, POST, FORM (необяз. по ум. - Пустое значение)";
НоваяСтрока.Область = "Настройка обработчиков";

View File

@@ -86,7 +86,7 @@
Контекст.Ответ.Записать(JSON);
#КонецЕсли
КонецПроцедуры
Функция ОбработатьЗапрос(Контекст)
@@ -226,8 +226,8 @@
//@skip-check missing-temporary-file-deletion
ИВФ = ПолучитьИмяВременногоФайла();
ПотокФайла = ТекущееЗначение.ОткрытьПотокЧтения();
ПотокЗаписи = Новый ФайловыйПоток(ИВФ, РежимОткрытияФайла.ОткрытьИлиСоздать);
ПотокФайла = ТекущееЗначение.ОткрытьПотокЧтения();
ПотокЗаписи = Новый ФайловыйПоток(ИВФ, РежимОткрытияФайла.ОткрытьИлиСоздать);
ПотокФайла.КопироватьВ(ПотокЗаписи);
@@ -235,7 +235,7 @@
ПотокЗаписи.Закрыть();
МассивВФ.Добавить(ИВФ);
КотелПараметров.Вставить(ТекущийКлюч, ИВФ);
Иначе
@@ -254,9 +254,9 @@
Иначе
ТекстВыполнения = СтруктураВыполнения["Результат"];
Выполнить(ТекстВыполнения);
Ответ = Новый Структура("result,data", Истина, Ответ);

View File

@@ -2169,9 +2169,9 @@
КонецФункции
Функция ПолучитьОбщийМодуль(Знач Имя)
Модуль = Вычислить(Имя);
Возврат Модуль;
КонецФункции

View File

@@ -1169,8 +1169,8 @@
Функция РазобратьFormData(Знач Форма) Экспорт
СоответствиеДанных = Новый Соответствие;
Файлы = Форма.Файлы;
Файлы = Форма.Файлы;
Для Каждого Поле Из Форма Цикл
СоответствиеДанных.Вставить(Поле.Ключ, Поле.Значение);

View File

@@ -1169,8 +1169,8 @@
Функция РазобратьFormData(Знач Форма) Экспорт
СоответствиеДанных = Новый Соответствие;
Файлы = Форма.Файлы;
Файлы = Форма.Файлы;
Для Каждого Поле Из Форма Цикл
СоответствиеДанных.Вставить(Поле.Ключ, Поле.Значение);

View File

@@ -134,9 +134,9 @@
Иначе
Проект = Результат["path"];
КонецЕсли;
Если Не Метод = "GET" И Не Метод = "POST" И Не Метод = "FORM" Тогда
Возврат СформироватьОтвет(Ложь, СтрШаблон("Неподдерживаемый метод %1!", Метод));
Возврат СформироватьОтвет(Ложь, СтрШаблон("Неподдерживаемый метод %1!", Метод));
КонецЕсли;
СекретныйКлюч = ПолучитьУникальныйКлючОбработчика(Проект);

View File

@@ -86,7 +86,7 @@
Контекст.Ответ.Записать(JSON);
#КонецЕсли
КонецПроцедуры
Функция ОбработатьЗапрос(Контекст)
@@ -226,8 +226,8 @@
//@skip-check missing-temporary-file-deletion
ИВФ = ПолучитьИмяВременногоФайла();
ПотокФайла = ТекущееЗначение.ОткрытьПотокЧтения();
ПотокЗаписи = Новый ФайловыйПоток(ИВФ, РежимОткрытияФайла.ОткрытьИлиСоздать);
ПотокФайла = ТекущееЗначение.ОткрытьПотокЧтения();
ПотокЗаписи = Новый ФайловыйПоток(ИВФ, РежимОткрытияФайла.ОткрытьИлиСоздать);
ПотокФайла.КопироватьВ(ПотокЗаписи);
@@ -235,7 +235,7 @@
ПотокЗаписи.Закрыть();
МассивВФ.Добавить(ИВФ);
КотелПараметров.Вставить(ТекущийКлюч, ИВФ);
Иначе