Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ayon_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
LinkDirection,
CreateLinkData,
CreateLinkResponseData,
CreateLinksResponseItem,
EventFilter,
EventStatus,
EnrollEventData,
Expand Down Expand Up @@ -7561,7 +7562,7 @@ def create_link(
def create_links(
project_name: str,
links: list[CreateLinkData],
) -> None:
) -> list[CreateLinksResponseItem]:
"""Create multiple links in a single request.

Example of link data::
Comment thread
BigRoy marked this conversation as resolved.
Expand All @@ -7579,6 +7580,9 @@ def create_links(
project_name (str): Project where links are created.
links (list[CreateLinkData]): List of link data.

Returns:
list[CreateLinksResponseItem]: Information about created links.

Raises:
ValueError: Link data is invalid.

Expand Down
20 changes: 16 additions & 4 deletions ayon_api/_api_helpers/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
LinkDirection,
CreateLinkData,
CreateLinkResponseData,
CreateLinksResponseItem,
)


Expand Down Expand Up @@ -257,7 +258,7 @@ def create_links(
self,
project_name: str,
links: list[CreateLinkData],
) -> None:
) -> list[CreateLinksResponseItem]:
"""Create multiple links in a single request.

Example of link data::
Expand All @@ -275,20 +276,24 @@ def create_links(
project_name (str): Project where links are created.
links (list[CreateLinkData]): List of link data.

Returns:
list[CreateLinksResponseItem]: Information about created links.

Raises:
ValueError: Link data is invalid.

"""
if not links:
return
return []

for link in links:
self._validate_link_data(link)

if self.get_server_version_tuple() < (1, 15, 8):
created_links = []
for link in links:
link_type, in_type, out_type = link["linkType"].split("|")
self.create_link(
data = self.create_link(
project_name,
link_type,
link["input"],
Expand All @@ -298,13 +303,20 @@ def create_links(
link_name=link.get("name") or None,
data=link.get("data") or None,
)
return
created_links.append({
"id": data["id"],
"input": link["input"],
"output": link["output"],
"linkType": link["linkType"]
})
Comment thread
BigRoy marked this conversation as resolved.
return created_links

response = self.post(
f"projects/{project_name}/links/bulk",
links=links
)
response.raise_for_status()
return response.data["created"]

def delete_link(self, project_name: str, link_id: str) -> None:
"""Remove link by id.
Expand Down
7 changes: 7 additions & 0 deletions ayon_api/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ class CreateLinkResponseData(TypedDict):
id: str


class CreateLinksResponseItem(TypedDict):
id: str
input: str
output: str
linkType: str


class CreateLinkData(TypedDict):
input: str
output: str
Expand Down
Loading