# coding: utf-8 """ PeerTube The PeerTube API is built on HTTP(S) and is RESTful. You can use your favorite HTTP/REST library for your programming language to use PeerTube. The spec API is fully compatible with [openapi-generator](https://github.com/OpenAPITools/openapi-generator/wiki/API-client-generator-HOWTO) which generates a client SDK in the language of your choice - we generate some client SDKs automatically: - [Python](https://framagit.org/framasoft/peertube/clients/python) - [Go](https://framagit.org/framasoft/peertube/clients/go) - [Kotlin](https://framagit.org/framasoft/peertube/clients/kotlin) See the [REST API quick start](https://docs.joinpeertube.org/api/rest-getting-started) for a few examples of using the PeerTube API. # Authentication When you sign up for an account on a PeerTube instance, you are given the possibility to generate sessions on it, and authenticate there using an access token. Only __one access token can currently be used at a time__. ## Roles Accounts are given permissions based on their role. There are three roles on PeerTube: Administrator, Moderator, and User. See the [roles guide](https://docs.joinpeertube.org/admin/managing-users#roles) for a detail of their permissions. # Errors The API uses standard HTTP status codes to indicate the success or failure of the API call, completed by a [RFC7807-compliant](https://tools.ietf.org/html/rfc7807) response body. ``` HTTP 1.1 404 Not Found Content-Type: application/problem+json; charset=utf-8 { \"detail\": \"Video not found\", \"docs\": \"https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo\", \"status\": 404, \"title\": \"Not Found\", \"type\": \"about:blank\" } ``` We provide error `type` values for [a growing number of cases](https://github.com/Chocobozzz/PeerTube/blob/develop/packages/models/src/server/core-error-code.enum.ts), but it is still optional. Types are used to disambiguate errors that bear the same status code and are non-obvious: ``` HTTP 1.1 403 Forbidden Content-Type: application/problem+json; charset=utf-8 { \"detail\": \"Cannot get this video regarding follow constraints\", \"docs\": \"https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo\", \"status\": 403, \"title\": \"Forbidden\", \"type\": \"https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints\" } ``` Here a 403 error could otherwise mean that the video is private or blocklisted. ### Validation errors Each parameter is evaluated on its own against a set of rules before the route validator proceeds with potential testing involving parameter combinations. Errors coming from validation errors appear earlier and benefit from a more detailed error description: ``` HTTP 1.1 400 Bad Request Content-Type: application/problem+json; charset=utf-8 { \"detail\": \"Incorrect request parameters: id\", \"docs\": \"https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo\", \"instance\": \"/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180\", \"invalid-params\": { \"id\": { \"location\": \"params\", \"msg\": \"Invalid value\", \"param\": \"id\", \"value\": \"9c9de5e8-0a1e-484a-b099-e80766180\" } }, \"status\": 400, \"title\": \"Bad Request\", \"type\": \"about:blank\" } ``` Where `id` is the name of the field concerned by the error, within the route definition. `invalid-params..location` can be either 'params', 'body', 'header', 'query' or 'cookies', and `invalid-params..value` reports the value that didn't pass validation whose `invalid-params..msg` is about. ### Deprecated error fields Some fields could be included with previous versions. They are still included but their use is deprecated: - `error`: superseded by `detail` - `code`: superseded by `type` (which is now an URI) # Rate limits We are rate-limiting all endpoints of PeerTube's API. Custom values can be set by administrators: | Endpoint (prefix: `/api/v1`) | Calls | Time frame | |------------------------------|---------------|--------------| | `/*` | 50 | 10 seconds | | `POST /users/token` | 15 | 5 minutes | | `POST /users/register` | 2* | 5 minutes | | `POST /users/ask-send-verify-email` | 3 | 5 minutes | Depending on the endpoint, *failed requests are not taken into account. A service limit is announced by a `429 Too Many Requests` status code. You can get details about the current state of your rate limit by reading the following headers: | Header | Description | |-------------------------|------------------------------------------------------------| | `X-RateLimit-Limit` | Number of max requests allowed in the current time period | | `X-RateLimit-Remaining` | Number of remaining requests in the current time period | | `X-RateLimit-Reset` | Timestamp of end of current time period as UNIX timestamp | | `Retry-After` | Seconds to delay after the first `429` is received | # CORS This API features [Cross-Origin Resource Sharing (CORS)](https://fetch.spec.whatwg.org/), allowing cross-domain communication from the browser for some routes: | Endpoint | |------------------------- ---| | `/api/*` | | `/download/*` | | `/lazy-static/*` | | `/.well-known/webfinger` | In addition, all routes serving ActivityPub are CORS-enabled for all origins. The version of the OpenAPI document: 5.2.0 Generated by OpenAPI Generator (https://openapi-generator.tech) Do not edit the class manually. """ # noqa: E501 from __future__ import annotations from inspect import getfullargspec import json import pprint import re # noqa: F401 from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from typing import Optional from peertube.models.vod_audio_merge_transcoding1 import VODAudioMergeTranscoding1 from peertube.models.vod_web_video_transcoding1 import VODWebVideoTranscoding1 from peertube.models.vodhls_transcoding1 import VODHLSTranscoding1 from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self from pydantic import Field RUNNERJOBPAYLOAD_ANY_OF_SCHEMAS = ["VODAudioMergeTranscoding1", "VODHLSTranscoding1", "VODWebVideoTranscoding1"] class RunnerJobPayload(BaseModel): """ RunnerJobPayload """ # data type: VODWebVideoTranscoding1 anyof_schema_1_validator: Optional[VODWebVideoTranscoding1] = None # data type: VODHLSTranscoding1 anyof_schema_2_validator: Optional[VODHLSTranscoding1] = None # data type: VODAudioMergeTranscoding1 anyof_schema_3_validator: Optional[VODAudioMergeTranscoding1] = None if TYPE_CHECKING: actual_instance: Optional[Union[VODAudioMergeTranscoding1, VODHLSTranscoding1, VODWebVideoTranscoding1]] = None else: actual_instance: Any = None any_of_schemas: List[str] = Field(default=Literal["VODAudioMergeTranscoding1", "VODHLSTranscoding1", "VODWebVideoTranscoding1"]) model_config = { "validate_assignment": True, "protected_namespaces": (), } def __init__(self, *args, **kwargs) -> None: if args: if len(args) > 1: raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) else: super().__init__(**kwargs) @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): instance = RunnerJobPayload.model_construct() error_messages = [] # validate data type: VODWebVideoTranscoding1 if not isinstance(v, VODWebVideoTranscoding1): error_messages.append(f"Error! Input type `{type(v)}` is not `VODWebVideoTranscoding1`") else: return v # validate data type: VODHLSTranscoding1 if not isinstance(v, VODHLSTranscoding1): error_messages.append(f"Error! Input type `{type(v)}` is not `VODHLSTranscoding1`") else: return v # validate data type: VODAudioMergeTranscoding1 if not isinstance(v, VODAudioMergeTranscoding1): error_messages.append(f"Error! Input type `{type(v)}` is not `VODAudioMergeTranscoding1`") else: return v if error_messages: # no match raise ValueError("No match found when setting the actual_instance in RunnerJobPayload with anyOf schemas: VODAudioMergeTranscoding1, VODHLSTranscoding1, VODWebVideoTranscoding1. Details: " + ", ".join(error_messages)) else: return v @classmethod def from_dict(cls, obj: Dict[str, Any]) -> Self: return cls.from_json(json.dumps(obj)) @classmethod def from_json(cls, json_str: str) -> Self: """Returns the object represented by the json string""" instance = cls.model_construct() error_messages = [] # anyof_schema_1_validator: Optional[VODWebVideoTranscoding1] = None try: instance.actual_instance = VODWebVideoTranscoding1.from_json(json_str) return instance except (ValidationError, ValueError) as e: error_messages.append(str(e)) # anyof_schema_2_validator: Optional[VODHLSTranscoding1] = None try: instance.actual_instance = VODHLSTranscoding1.from_json(json_str) return instance except (ValidationError, ValueError) as e: error_messages.append(str(e)) # anyof_schema_3_validator: Optional[VODAudioMergeTranscoding1] = None try: instance.actual_instance = VODAudioMergeTranscoding1.from_json(json_str) return instance except (ValidationError, ValueError) as e: error_messages.append(str(e)) if error_messages: # no match raise ValueError("No match found when deserializing the JSON string into RunnerJobPayload with anyOf schemas: VODAudioMergeTranscoding1, VODHLSTranscoding1, VODWebVideoTranscoding1. Details: " + ", ".join(error_messages)) else: return instance def to_json(self) -> str: """Returns the JSON representation of the actual instance""" if self.actual_instance is None: return "null" if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): return self.actual_instance.to_json() else: return json.dumps(self.actual_instance) def to_dict(self) -> Optional[Union[Dict[str, Any], VODAudioMergeTranscoding1, VODHLSTranscoding1, VODWebVideoTranscoding1]]: """Returns the dict representation of the actual instance""" if self.actual_instance is None: return None if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): return self.actual_instance.to_dict() else: return self.actual_instance def to_str(self) -> str: """Returns the string representation of the actual instance""" return pprint.pformat(self.model_dump())