1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-03-31 22:05:13 +02:00

Преобразование OPI -> OInt (workflow)

This commit is contained in:
Vitaly the Alpaca 2024-07-02 09:18:44 +00:00 committed by Vitaly the Alpaca (bot)
parent ed371d82b0
commit 92f2541b2b
11 changed files with 4143 additions and 3819 deletions
service/dictionaries
src
en
OInt
core/Modules
tests/Modules/internal
tools/Modules/internal/Modules
OPI/src/CommonModules
OPI_Bitrix24
OPI_Tests
OPI_Tools
cli/data/Classes/internal/Classes
ru
OInt
lib.config
tests/Modules/internal
cli/data/Classes/internal/Classes

File diff suppressed because it is too large Load Diff

@ -1217,6 +1217,59 @@ Function RenameFolder(Val URL, Val FolderID, Val Name, Val Token = "") Export
EndFunction
// Upload file to the folder
// Upload local file to the folder
//
// Parameters:
// URL - String - URL of webhook or a Bitrix24 domain, when token used - url
// Name - String - File name with extension - title
// File - String, BinaryData - File for upload - file
// FolderID - String - Folder identifier - folderid
// Token - String - Access token, when not-webhook method used - token
//
// Returns:
// Map Of KeyAndValue - serialized JSON of answer from Bitrix24 API
Function UploadFileToFolder(Val URL
, Val Name
, Val File
, Val FolderID
, Val Token = "") Export
OPI_TypeConversion.GetLine(Name);
OPI_TypeConversion.GetBinaryData(File);
Parameters = NormalizeAuth(URL, Token, "disk.folder.uploadFile");
OPI_Tools.AddField("id", FolderID, "String", Parameters);
Response = OPI_Tools.Get(URL, Parameters);
Result = Response["result"];
If ValueIsFilled(Result) Then
FieldName = Result["field"];
UploadURL = Result["uploadUrl"];
If ValueIsFilled(FieldName) And ValueIsFilled(UploadURL) Then
FieldName = TrimAll(FieldName);
UploadURL = TrimAll(UploadURL);
FileName = FieldName + "|" + Name;
FileMapping = New Map;
FileMapping.Insert(FileName, File);
Response = OPI_Tools.PostMultipart(UploadURL, , FileMapping);
EndIf;
EndIf;
Return Response;
EndFunction
// Get fields structure for folder items filter
// Returns filter structure for child folder items
//

@ -2934,13 +2934,14 @@ Procedure B24_WorkingWithDrive() Export
Bitrix24_GetFolderExternalLink(TestParameters);
Bitrix24_CreateSubfolder(TestParameters);
Bitrix24_CopyFolder(TestParameters);
Bitrxi24_UploadFileToFolder(TestParameters);
Bitrix24_GetFolderFilterStructure(TestParameters);
Bitrix24_GetFolderItems(TestParameters);
Bitrix24_MoveFolder(TestParameters);
Bitrxi24_MarkFolderAsDeleted(TestParameters);
Bitrix24_RestoreFolder(TestParameters);
Bitrix24_DeleteFolder(TestParameters);
EndProcedure
#EndRegion
@ -3296,7 +3297,7 @@ Procedure Check_VKCampaign(Val Result)
Result = Result["response"][0];
OPI_TestDataRetrieval.ExpectsThat(Result).ИмеетТип("Map");
OPI_TestDataRetrieval.ExpectsThat(Result["error_code"]).ИмеетТип("Number").Равно(602);
OPI_TestDataRetrieval.ExpectsThat(Result["error_code"]).ИмеетТип("Number").Равно(603);
OPI_TestDataRetrieval.ExpectsThat(Result["id"]).ИмеетТип("Number").Заполнено();
EndProcedure
@ -4809,7 +4810,7 @@ Procedure VK_CreateAdCampaign(FunctionParameters)
OPI_TestDataRetrieval.WriteLog(Result, "CreateAdvertisingCampaign", "VK");
Check_VKCampaign(Result);
Check_Map(Result);
CampaignID = Result["response"][0]["id"];
OPI_TestDataRetrieval.WriteParameter("VK_AdsCampaignID", CampaignID);
@ -7245,6 +7246,43 @@ Procedure Bitrix24_RenameFolder(FunctionParameters)
EndProcedure
Procedure Bitrxi24_UploadFileToFolder(FunctionParameters)
Filename2 = "Picture2.jpg";
Name = "Picture1.jpg";
Image2 = FunctionParameters["Picture"]; // Local path, URL or Binary Data
Image = FunctionParameters["Picture2"]; // Local path, URL or Binary Data
DestinationID = FunctionParameters["Bitrix24_FolderID"];
URL = FunctionParameters["Bitrix24_URL"];
Result = OPI_Bitrix24.UploadFileToFolder(URL, Filename2, Image2, DestinationID);
OPI_TestDataRetrieval.WriteLog(Result, "UploadFileToFolder (wh)", "Bitrix24");
Check_BitrixFile(Result); // SKIP
FileID = Result["result"]["ID"]; // SKIP
OPI_Bitrix24.DeleteFile(URL, FileID); // SKIP
URL = FunctionParameters["Bitrix24_Domain"];
Token = FunctionParameters["Bitrix24_Token"];
Result = OPI_Bitrix24.UploadFileToFolder(URL, Name, Image, DestinationID, Token);
// END
OPI_TestDataRetrieval.WriteLog(Result, "UploadFileToFolder", "Bitrix24");
Check_BitrixFile(Result);
FileID = Result["result"]["ID"];
Result = OPI_Bitrix24.DeleteFile(URL, FileID, Token);
EndProcedure
#EndRegion
#Region YandexDisk

@ -817,6 +817,33 @@ Function ConvertParameterToString(Val Value)
EndFunction
Function SplitFileKey(Val FileData, Val ContentType)
DotReplacement = "___";
FileName = StrReplace(FileData, DotReplacement, ".");
NameParts = StrSplit(FileName, "|", False);
If NameParts.Count() = 2 Then
FieldName = NameParts[0];
FileName = NameParts[1];
Else
If ContentType = "image/jpeg" Then
FieldName = "photo";
Else
FieldName = Left(FileName, StrFind(FileName, ".") - 1);
FieldName = ?(ValueIsFilled(FieldName), FieldName, StrReplace(FileData,
DotReplacement, "."));
EndIf;
EndIf;
ReturnStructure = New Structure("FieldName,FileName", FieldName, FileName);
Return ReturnStructure;
EndFunction
Procedure SetRequestBody(Request, Val Parameters, Val JSON)
Collection = TypeOf(Parameters) = Type("Structure")
@ -883,26 +910,19 @@ Procedure WriteMultipartFiles(TextRecord, Val Boundary, Val ContentType, Val Fil
ContentType = TrimAll(ContentType);
LineSeparator = Chars.CR + Chars.LF;
DotReplacement = "___";
For Each File In Files Do
FilePath = StrReplace(File.Key, DotReplacement, ".");
DataStructure = SplitFileKey(File.Key, ContentType);
If ContentType = "image/jpeg" Then
SendingFileName = "photo";
Else
SendingFileName = StrReplace(File.Key, DotReplacement, ".");
SendingFileName = Left(SendingFileName, StrFind(SendingFileName, ".") - 1);
SendingFileName = ?(ValueIsFilled(SendingFileName), SendingFileName, StrReplace(File.Key,
DotReplacement, "."));
EndIf;
FieldName = DataStructure["FieldName"];
FileName = DataStructure["FileName"];
TextRecord.WriteLine("--" + boundary + LineSeparator);
TextRecord.WriteLine("Content-Disposition: form-data; name="""
+ SendingFileName
+ FieldName
+ """; filename="""
+ FilePath
+ FileName
+ """");
TextRecord.WriteLine(LineSeparator);

@ -1217,6 +1217,59 @@ Function RenameFolder(Val URL, Val FolderID, Val Name, Val Token = "") Export
EndFunction
// Upload file to the folder
// Upload local file to the folder
//
// Parameters:
// URL - String - URL of webhook or a Bitrix24 domain, when token used - url
// Name - String - File name with extension - title
// File - String, BinaryData - File for upload - file
// FolderID - String - Folder identifier - folderid
// Token - String - Access token, when not-webhook method used - token
//
// Returns:
// Map Of KeyAndValue - serialized JSON of answer from Bitrix24 API
Function UploadFileToFolder(Val URL
, Val Name
, Val File
, Val FolderID
, Val Token = "") Export
OPI_TypeConversion.GetLine(Name);
OPI_TypeConversion.GetBinaryData(File);
Parameters = NormalizeAuth(URL, Token, "disk.folder.uploadFile");
OPI_Tools.AddField("id", FolderID, "String", Parameters);
Response = OPI_Tools.Get(URL, Parameters);
Result = Response["result"];
If ValueIsFilled(Result) Then
FieldName = Result["field"];
UploadURL = Result["uploadUrl"];
If ValueIsFilled(FieldName) And ValueIsFilled(UploadURL) Then
FieldName = TrimAll(FieldName);
UploadURL = TrimAll(UploadURL);
FileName = FieldName + "|" + Name;
FileMapping = New Map;
FileMapping.Insert(FileName, File);
Response = OPI_Tools.PostMultipart(UploadURL, , FileMapping);
EndIf;
EndIf;
Return Response;
EndFunction
// Get fields structure for folder items filter
// Returns filter structure for child folder items
//

@ -2934,13 +2934,14 @@ Procedure B24_WorkingWithDrive() Export
Bitrix24_GetFolderExternalLink(TestParameters);
Bitrix24_CreateSubfolder(TestParameters);
Bitrix24_CopyFolder(TestParameters);
Bitrxi24_UploadFileToFolder(TestParameters);
Bitrix24_GetFolderFilterStructure(TestParameters);
Bitrix24_GetFolderItems(TestParameters);
Bitrix24_MoveFolder(TestParameters);
Bitrxi24_MarkFolderAsDeleted(TestParameters);
Bitrix24_RestoreFolder(TestParameters);
Bitrix24_DeleteFolder(TestParameters);
EndProcedure
#EndRegion
@ -3296,7 +3297,7 @@ Procedure Check_VKCampaign(Val Result)
Result = Result["response"][0];
OPI_TestDataRetrieval.ExpectsThat(Result).ИмеетТип("Map");
OPI_TestDataRetrieval.ExpectsThat(Result["error_code"]).ИмеетТип("Number").Равно(602);
OPI_TestDataRetrieval.ExpectsThat(Result["error_code"]).ИмеетТип("Number").Равно(603);
OPI_TestDataRetrieval.ExpectsThat(Result["id"]).ИмеетТип("Number").Заполнено();
EndProcedure
@ -4809,7 +4810,7 @@ Procedure VK_CreateAdCampaign(FunctionParameters)
// !OInt OPI_TestDataRetrieval.WriteLog(Result, "CreateAdvertisingCampaign", "VK");
Check_VKCampaign(Result);
Check_Map(Result);
CampaignID = Result["response"][0]["id"];
OPI_TestDataRetrieval.WriteParameter("VK_AdsCampaignID", CampaignID);
@ -7245,6 +7246,43 @@ Procedure Bitrix24_RenameFolder(FunctionParameters)
EndProcedure
Procedure Bitrxi24_UploadFileToFolder(FunctionParameters)
Filename2 = "Picture2.jpg";
Name = "Picture1.jpg";
Image2 = FunctionParameters["Picture"]; // Local path, URL or Binary Data
Image = FunctionParameters["Picture2"]; // Local path, URL or Binary Data
DestinationID = FunctionParameters["Bitrix24_FolderID"];
URL = FunctionParameters["Bitrix24_URL"];
Result = OPI_Bitrix24.UploadFileToFolder(URL, Filename2, Image2, DestinationID);
// !OInt OPI_TestDataRetrieval.WriteLog(Result, "UploadFileInDirectory (хуto)", "Bitrix24");
Check_BitrixFile(Result); // SKIP
FileID = Result["result"]["ID"]; // SKIP
OPI_Bitrix24.DeleteFile(URL, FileID); // SKIP
URL = FunctionParameters["Bitrix24_Domain"];
Token = FunctionParameters["Bitrix24_Token"];
Result = OPI_Bitrix24.UploadFileToFolder(URL, Name, Image, DestinationID, Token);
// END
// !OInt OPI_TestDataRetrieval.WriteLog(Result, "UploadFileInDirectory", "Bitrix24");
Check_BitrixFile(Result);
FileID = Result["result"]["ID"];
Result = OPI_Bitrix24.DeleteFile(URL, FileID, Token);
EndProcedure
#EndRegion
#Region YandexDisk

@ -817,6 +817,33 @@ Function ConvertParameterToString(Val Value)
EndFunction
Function SplitFileKey(Val FileData, Val ContentType)
DotReplacement = "___";
FileName = StrReplace(FileData, DotReplacement, ".");
NameParts = StrSplit(FileName, "|", False);
If NameParts.Count() = 2 Then
FieldName = NameParts[0];
FileName = NameParts[1];
Else
If ContentType = "image/jpeg" Then
FieldName = "photo";
Else
FieldName = Left(FileName, StrFind(FileName, ".") - 1);
FieldName = ?(ValueIsFilled(FieldName), FieldName, StrReplace(FileData,
DotReplacement, "."));
EndIf;
EndIf;
ReturnStructure = New Structure("FieldName,FileName", FieldName, FileName);
Return ReturnStructure;
EndFunction
Procedure SetRequestBody(Request, Val Parameters, Val JSON)
Collection = TypeOf(Parameters) = Type("Structure")
@ -883,26 +910,19 @@ Procedure WriteMultipartFiles(TextRecord, Val Boundary, Val ContentType, Val Fil
ContentType = TrimAll(ContentType);
LineSeparator = Chars.CR + Chars.LF;
DotReplacement = "___";
For Each File In Files Do
FilePath = StrReplace(File.Key, DotReplacement, ".");
DataStructure = SplitFileKey(File.Key, ContentType);
If ContentType = "image/jpeg" Then
SendingFileName = "photo";
Else
SendingFileName = StrReplace(File.Key, DotReplacement, ".");
SendingFileName = Left(SendingFileName, StrFind(SendingFileName, ".") - 1);
SendingFileName = ?(ValueIsFilled(SendingFileName), SendingFileName, StrReplace(File.Key,
DotReplacement, "."));
EndIf;
FieldName = DataStructure["FieldName"];
FileName = DataStructure["FileName"];
TextRecord.WriteLine("--" + boundary + LineSeparator);
TextRecord.WriteLine("Content-Disposition: form-data; name="""
+ SendingFileName
+ FieldName
+ """; filename="""
+ FilePath
+ FileName
+ """");
TextRecord.WriteLine(LineSeparator);

@ -1751,6 +1751,57 @@
NewLine.Область = "Storages and files managment";
NewLine = CompositionTable.Add();
NewLine.Библиотека = "bitrix24";
NewLine.Модуль = "OPI_Bitrix24";
NewLine.Метод = "UploadFileToFolder";
NewLine.МетодПоиска = "UPLOADFILETOFOLDER";
NewLine.Параметр = "--url";
NewLine.Описание = "URL of webhook or a Bitrix24 domain, when token used";
NewLine.Область = "Storages and files managment";
NewLine.ОписаниеМетода = "Upload local file to the folder";
NewLine = CompositionTable.Add();
NewLine.Библиотека = "bitrix24";
NewLine.Модуль = "OPI_Bitrix24";
NewLine.Метод = "UploadFileToFolder";
NewLine.МетодПоиска = "UPLOADFILETOFOLDER";
NewLine.Параметр = "--title";
NewLine.Описание = "File name with extension";
NewLine.Область = "Storages and files managment";
NewLine = CompositionTable.Add();
NewLine.Библиотека = "bitrix24";
NewLine.Модуль = "OPI_Bitrix24";
NewLine.Метод = "UploadFileToFolder";
NewLine.МетодПоиска = "UPLOADFILETOFOLDER";
NewLine.Параметр = "--file";
NewLine.Описание = "File for upload";
NewLine.Область = "Storages and files managment";
NewLine = CompositionTable.Add();
NewLine.Библиотека = "bitrix24";
NewLine.Модуль = "OPI_Bitrix24";
NewLine.Метод = "UploadFileToFolder";
NewLine.МетодПоиска = "UPLOADFILETOFOLDER";
NewLine.Параметр = "--folderid";
NewLine.Описание = "Folder identifier";
NewLine.Область = "Storages and files managment";
NewLine = CompositionTable.Add();
NewLine.Библиотека = "bitrix24";
NewLine.Модуль = "OPI_Bitrix24";
NewLine.Метод = "UploadFileToFolder";
NewLine.МетодПоиска = "UPLOADFILETOFOLDER";
NewLine.Параметр = "--webhook method used";
NewLine.Описание = "token (optional, def. val. - Empty)";
NewLine.Область = "Storages and files managment";
NewLine = CompositionTable.Add();
NewLine.Библиотека = "bitrix24";
NewLine.Модуль = "OPI_Bitrix24";

@ -1,21 +1,21 @@
<package-def>
<module name="OPI_Криптография" file="tools/Modules/internal/Modules/OPI_Криптография.os"/>
<module name="OPI_Notion" file="core/Modules/OPI_Notion.os"/>
<module name="OPI_GoogleCalendar" file="core/Modules/OPI_GoogleCalendar.os"/>
<module name="OPI_ПолучениеДанныхТестов" file="tools/Modules/OPI_ПолучениеДанныхТестов.os"/>
<module name="OPI_Slack" file="core/Modules/OPI_Slack.os"/>
<module name="OPI_Dropbox" file="core/Modules/OPI_Dropbox.os"/>
<module name="OPI_GoogleDrive" file="core/Modules/OPI_GoogleDrive.os"/>
<module name="OPI_VK" file="core/Modules/OPI_VK.os"/>
<module name="OPI_Telegram" file="core/Modules/OPI_Telegram.os"/>
<module name="OPI_Airtable" file="core/Modules/OPI_Airtable.os"/>
<module name="OPI_Bitrix24" file="core/Modules/OPI_Bitrix24.os"/>
<module name="OPI_Dropbox" file="core/Modules/OPI_Dropbox.os"/>
<module name="OPI_GoogleCalendar" file="core/Modules/OPI_GoogleCalendar.os"/>
<module name="OPI_GoogleDrive" file="core/Modules/OPI_GoogleDrive.os"/>
<module name="OPI_GoogleSheets" file="core/Modules/OPI_GoogleSheets.os"/>
<module name="OPI_GoogleWorkspace" file="core/Modules/OPI_GoogleWorkspace.os"/>
<module name="OPI_Notion" file="core/Modules/OPI_Notion.os"/>
<module name="OPI_Slack" file="core/Modules/OPI_Slack.os"/>
<module name="OPI_Telegram" file="core/Modules/OPI_Telegram.os"/>
<module name="OPI_ПреобразованиеТипов" file="tools/Modules/OPI_ПреобразованиеТипов.os"/>
<module name="OPI_Twitter" file="core/Modules/OPI_Twitter.os"/>
<module name="OPI_Инструменты" file="tools/Modules/internal/Modules/OPI_Инструменты.os"/>
<module name="OPI_Viber" file="core/Modules/OPI_Viber.os"/>
<module name="OPI_VK" file="core/Modules/OPI_VK.os"/>
<module name="OPI_YandexDisk" file="core/Modules/OPI_YandexDisk.os"/>
<module name="OPI_YandexID" file="core/Modules/OPI_YandexID.os"/>
<module name="OPI_Инструменты" file="tools/Modules/internal/Modules/OPI_Инструменты.os"/>
<module name="OPI_Криптография" file="tools/Modules/internal/Modules/OPI_Криптография.os"/>
<module name="OPI_ПолучениеДанныхТестов" file="tools/Modules/OPI_ПолучениеДанныхТестов.os"/>
<module name="OPI_ПреобразованиеТипов" file="tools/Modules/OPI_ПреобразованиеТипов.os"/>
<module name="OPI_GoogleWorkspace" file="core/Modules/OPI_GoogleWorkspace.os"/>
</package-def>

@ -3297,7 +3297,7 @@
Результат = Результат["response"][0];
OPI_ПолучениеДанныхТестов.ОжидаетЧто(Результат).ИмеетТип("Соответствие");
OPI_ПолучениеДанныхТестов.ОжидаетЧто(Результат["error_code"]).ИмеетТип("Число").Равно(602);
OPI_ПолучениеДанныхТестов.ОжидаетЧто(Результат["error_code"]).ИмеетТип("Число").Равно(603);
OPI_ПолучениеДанныхТестов.ОжидаетЧто(Результат["id"]).ИмеетТип("Число").Заполнено();
КонецПроцедуры
@ -4810,7 +4810,7 @@
OPI_ПолучениеДанныхТестов.ЗаписатьЛог(Результат, "СоздатьРекламнуюКампанию", "VK");
Проверка_ВККампания(Результат);
Проверка_Соответствие(Результат);
ИДКампании = Результат["response"][0]["id"];
OPI_ПолучениеДанныхТестов.ЗаписатьПараметр("VK_AdsCampaignID", ИДКампании);

@ -1751,6 +1751,57 @@
НоваяСтрока.Область = "Работа с диском и файлами";
НоваяСтрока = ТаблицаСостава.Добавить();
НоваяСтрока.Библиотека = "bitrix24";
НоваяСтрока.Модуль = "OPI_Bitrix24";
НоваяСтрока.Метод = "ЗагрузитьФайлВКаталог";
НоваяСтрока.МетодПоиска = "ЗАГРУЗИТЬФАЙЛВКАТАЛОГ";
НоваяСтрока.Параметр = "--url";
НоваяСтрока.Описание = "URL внешнего вебхука или адрес Bitrix24 при использовании токена";
НоваяСтрока.Область = "Работа с диском и файлами";
НоваяСтрока.ОписаниеМетода = "Загружает переданный файл в каталог";
НоваяСтрока = ТаблицаСостава.Добавить();
НоваяСтрока.Библиотека = "bitrix24";
НоваяСтрока.Модуль = "OPI_Bitrix24";
НоваяСтрока.Метод = "ЗагрузитьФайлВКаталог";
НоваяСтрока.МетодПоиска = "ЗАГРУЗИТЬФАЙЛВКАТАЛОГ";
НоваяСтрока.Параметр = "--title";
НоваяСтрока.Описание = "Наименование файла с расширением для сохранения";
НоваяСтрока.Область = "Работа с диском и файлами";
НоваяСтрока = ТаблицаСостава.Добавить();
НоваяСтрока.Библиотека = "bitrix24";
НоваяСтрока.Модуль = "OPI_Bitrix24";
НоваяСтрока.Метод = "ЗагрузитьФайлВКаталог";
НоваяСтрока.МетодПоиска = "ЗАГРУЗИТЬФАЙЛВКАТАЛОГ";
НоваяСтрока.Параметр = "--file";
НоваяСтрока.Описание = "Файл для загрузки";
НоваяСтрока.Область = "Работа с диском и файлами";
НоваяСтрока = ТаблицаСостава.Добавить();
НоваяСтрока.Библиотека = "bitrix24";
НоваяСтрока.Модуль = "OPI_Bitrix24";
НоваяСтрока.Метод = "ЗагрузитьФайлВКаталог";
НоваяСтрока.МетодПоиска = "ЗАГРУЗИТЬФАЙЛВКАТАЛОГ";
НоваяСтрока.Параметр = "--folderid";
НоваяСтрока.Описание = "Идентификатор каталога для загрузки";
НоваяСтрока.Область = "Работа с диском и файлами";
НоваяСтрока = ТаблицаСостава.Добавить();
НоваяСтрока.Библиотека = "bitrix24";
НоваяСтрока.Модуль = "OPI_Bitrix24";
НоваяСтрока.Метод = "ЗагрузитьФайлВКаталог";
НоваяСтрока.МетодПоиска = "ЗАГРУЗИТЬФАЙЛВКАТАЛОГ";
НоваяСтрока.Параметр = "--token";
НоваяСтрока.Описание = "Токен авторизации, если используется не вебхук (необяз. по ум. - Пустое значение)";
НоваяСтрока.Область = "Работа с диском и файлами";
НоваяСтрока = ТаблицаСостава.Добавить();
НоваяСтрока.Библиотека = "bitrix24";
НоваяСтрока.Модуль = "OPI_Bitrix24";