mirror of
https://github.com/arabianq/yndx-disk.git
synced 2026-04-27 22:21:23 +00:00
first_commit
This commit is contained in:
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<Languages>
|
||||||
|
<language minSize="108" name="Python" />
|
||||||
|
</Languages>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
Generated
+4
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (yandex_disk_rest_api)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/yandex_disk_rest_api.iml" filepath="$PROJECT_DIR$/.idea/yandex_disk_rest_api.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12 (.venv)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
from .test import *
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class YandexDiskAPIException(Exception):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import asyncio
|
||||||
|
import httpx
|
||||||
|
import yndx_disk.utils as utils
|
||||||
|
import yndx_disk.exceptions as exceptions
|
||||||
|
|
||||||
|
BASE_URL = "https://cloud-api.yandex.net/v1/disk/resources"
|
||||||
|
|
||||||
|
|
||||||
|
async def delete(token: str, path: str, fields: str = "", md5: str = "", force_async: bool = False,
|
||||||
|
permanently: bool = False, timeout: int = 30):
|
||||||
|
url = BASE_URL
|
||||||
|
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
response = await client.delete(
|
||||||
|
url=url,
|
||||||
|
headers=utils.generate_headers(token=token),
|
||||||
|
params={
|
||||||
|
"path": path,
|
||||||
|
"fields": fields,
|
||||||
|
"md5": md5,
|
||||||
|
"force_async": force_async,
|
||||||
|
"permanently": permanently,
|
||||||
|
},
|
||||||
|
timeout=timeout
|
||||||
|
)
|
||||||
|
|
||||||
|
response_json = response.json()
|
||||||
|
|
||||||
|
match response.status_code:
|
||||||
|
case 200:
|
||||||
|
return response_json
|
||||||
|
case _:
|
||||||
|
raise exceptions.YandexDiskAPIException(response.status_code, response_json.get("description", ""))
|
||||||
|
|
||||||
|
|
||||||
|
async def get_info(token: str, path: str, fields: str = "", preview_size: str = "", sort: str = "",
|
||||||
|
preview_crop: bool = False, limit: int = 100, offset: int = 0, timeout: int = 30):
|
||||||
|
url = BASE_URL
|
||||||
|
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
response = await client.get(
|
||||||
|
url=url,
|
||||||
|
headers=utils.generate_headers(token=token),
|
||||||
|
params={
|
||||||
|
"path": path,
|
||||||
|
"fields": fields,
|
||||||
|
"preview_size": preview_size,
|
||||||
|
"sort": sort,
|
||||||
|
"preview_crop": preview_crop,
|
||||||
|
"limit": limit,
|
||||||
|
"offset": offset,
|
||||||
|
},
|
||||||
|
timeout=timeout
|
||||||
|
)
|
||||||
|
|
||||||
|
response_json = response.json()
|
||||||
|
|
||||||
|
match response.status_code:
|
||||||
|
case 200:
|
||||||
|
return response_json
|
||||||
|
case _:
|
||||||
|
raise exceptions.YandexDiskAPIException(response.status_code, response_json.get("description", ""))
|
||||||
|
|
||||||
|
async def update_info(token: str, path: str, body: dict, fields: str = "", timeout: int = 30):
|
||||||
|
url = BASE_URL
|
||||||
|
|
||||||
|
async def mkdir(token: str, path: str, fields: str = "", timeout: int = 30):
|
||||||
|
url = BASE_URL
|
||||||
|
|
||||||
|
async def copy(token: str, from_path: str, to_path: str, fields: str = "", force_async: bool = False,
|
||||||
|
overwrite: bool = False, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/copy"
|
||||||
|
|
||||||
|
async def get_url(token: str, path: str, fields: str = "", timeout: int = 30):
|
||||||
|
url = BASE_URL + "/download"
|
||||||
|
|
||||||
|
async def get_all_files(token: str, fields: str = "", media_type: str = "", preview_size: str = "", sort: str = "",
|
||||||
|
preview_crop: bool = False, limit: int = 100, offset: int = 0, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/files"
|
||||||
|
|
||||||
|
async def get_last_uploads(token: str, fields: str = "", media_type: str = "", preview_size: str = "",
|
||||||
|
preview_crop: bool = False, limit: int = 100, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/last-uploaded"
|
||||||
|
|
||||||
|
async def move(token: str, from_path: str, to_path: str, fields: str = "", force_async: bool = False,
|
||||||
|
overwrite: bool = False, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/move"
|
||||||
|
|
||||||
|
async def get_all_public(token: str, fields: str = "", preview_size: str = "", type_filter: str = "",
|
||||||
|
preview_crop: bool = False, limit: int = 100, offset: int = 0, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/public"
|
||||||
|
|
||||||
|
async def publish(token: str, path: str, body: dict, fields: str = "", allow_address_access: bool = False,
|
||||||
|
timeout: int = 30):
|
||||||
|
url = BASE_URL + "/publish"
|
||||||
|
|
||||||
|
async def unpublish(token: str, path: str, fields: str = "", timeout: int = 30):
|
||||||
|
url = BASE_URL + "/unpublish"
|
||||||
|
|
||||||
|
async def get_upload_url(token: str, path: str, fields: str = "", overwrite: bool = False, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/upload"
|
||||||
|
|
||||||
|
async def upload(token: str, upload_url: str, fields: str = "", disable_redirects: bool = False, timeout: int = 30):
|
||||||
|
url = BASE_URL + "/upload"
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_HEADERS = {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"Authorization": "OAuth {token}",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def generate_headers(token: str) -> dict:
|
||||||
|
headers = DEFAULT_HEADERS.copy()
|
||||||
|
|
||||||
|
headers["Authorization"] = f"OAuth {token}"
|
||||||
|
|
||||||
|
return headers
|
||||||
|
|
||||||
|
|
||||||
|
def parse_path(path: str) -> str:
|
||||||
|
if path.startswith("/"):
|
||||||
|
path = "disk:/" + path[1:]
|
||||||
|
elif not path.startswith("disk:/"):
|
||||||
|
path = "disk:/" + path
|
||||||
|
|
||||||
|
path = Path(path) # Some kind of check is path valid or not =P
|
||||||
|
|
||||||
|
return str(path)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user