render-lab-tasks-gdrive 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- render_lab_tasks_gdrive-0.1.0/.gitignore +11 -0
- render_lab_tasks_gdrive-0.1.0/LICENSE +21 -0
- render_lab_tasks_gdrive-0.1.0/PKG-INFO +74 -0
- render_lab_tasks_gdrive-0.1.0/README.md +61 -0
- render_lab_tasks_gdrive-0.1.0/pyproject.toml +22 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/__init__.py +1 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/_app.py +3 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/client.py +191 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/copy.py +16 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/create_folder.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/delete.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/download.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/export.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/get_file.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/move.py +16 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/py.typed +0 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/retry.py +3 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/search.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/share.py +18 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/tasks.py +35 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/types.py +90 -0
- render_lab_tasks_gdrive-0.1.0/src/render_lab_tasks_gdrive/upload.py +18 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Render Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: render-lab-tasks-gdrive
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: gdrive tasks for Render Workflows
|
|
5
|
+
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: httpx<0.29,>=0.28
|
|
10
|
+
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.1
|
|
11
|
+
Requires-Dist: render==1.0.1
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# render-lab-tasks-gdrive
|
|
15
|
+
|
|
16
|
+
Python port of all 10 registered tasks in the pinned TypeScript pack at
|
|
17
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
18
|
+
|
|
19
|
+
Install this distribution and its dependencies:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install render-lab-tasks-gdrive==0.1.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import definitions from `render_lab_tasks_gdrive.tasks`; combine `app` objects
|
|
26
|
+
with `Workflows.from_workflows(...)`. JSON fields retain TS spelling; functions
|
|
27
|
+
use snake_case. Package root imports are inert.
|
|
28
|
+
|
|
29
|
+
## Tasks
|
|
30
|
+
|
|
31
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `gdrive.copy` | `copy` |
|
|
34
|
+
| `gdrive.createFolder` | `create_folder` |
|
|
35
|
+
| `gdrive.delete` | `delete` |
|
|
36
|
+
| `gdrive.download` | `download` |
|
|
37
|
+
| `gdrive.export` | `export` |
|
|
38
|
+
| `gdrive.getFile` | `get_file` |
|
|
39
|
+
| `gdrive.move` | `move` |
|
|
40
|
+
| `gdrive.search` | `search` |
|
|
41
|
+
| `gdrive.share` | `share` |
|
|
42
|
+
| `gdrive.upload` | `upload` |
|
|
43
|
+
|
|
44
|
+
## Dependencies and retries
|
|
45
|
+
|
|
46
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
47
|
+
module exports typed `Port`, `Deps`, and `Client` classes. Inject a fake port, or
|
|
48
|
+
pass a caller-owned `httpx.AsyncClient` to `Client`. Default dependencies close
|
|
49
|
+
their client after one operation. Credentials resolve at first use. Transport
|
|
50
|
+
retries are disabled; `retry.py` owns durable policies. DTO types are in `.types`.
|
|
51
|
+
Requires core >=0.1.1.
|
|
52
|
+
|
|
53
|
+
## Environment
|
|
54
|
+
|
|
55
|
+
| Variable | Contract |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `GOOGLE_ACCESS_TOKEN` | Optional pre-issued token; takes precedence. |
|
|
58
|
+
| `GOOGLE_CLIENT_ID` | Required with secret and refresh token when no access token is supplied. |
|
|
59
|
+
| `GOOGLE_CLIENT_SECRET` | OAuth client secret for refresh. |
|
|
60
|
+
| `GOOGLE_REFRESH_TOKEN` | Refresh token granted the scopes for the operations you use. |
|
|
61
|
+
|
|
62
|
+
## Verification and limitations
|
|
63
|
+
|
|
64
|
+
Google Drive v3 supports text uploads/downloads and exports through this surface.
|
|
65
|
+
Python caps inline text at 1 MiB and rejects malformed MIME headers or multipart
|
|
66
|
+
boundary collisions. Search returns one page. Upload/createFolder/copy retain the
|
|
67
|
+
TS three-retry policy and may duplicate a resource after an ambiguous response.
|
|
68
|
+
Sharing changes permissions; test against a dedicated folder and account.
|
|
69
|
+
|
|
70
|
+
Shared fixtures execute the actual pinned TS implementations and compare Python
|
|
71
|
+
outputs and requests. Sanity's SDK calls are translated into separately asserted
|
|
72
|
+
REST requests. These are hermetic checks, not real account or hosted verification.
|
|
73
|
+
See [the testing backlog](https://github.com/render-lab/render-tasks-python/issues/1)
|
|
74
|
+
and the root verification tracker. Licensed under MIT.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# render-lab-tasks-gdrive
|
|
2
|
+
|
|
3
|
+
Python port of all 10 registered tasks in the pinned TypeScript pack at
|
|
4
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
5
|
+
|
|
6
|
+
Install this distribution and its dependencies:
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pip install render-lab-tasks-gdrive==0.1.0
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Import definitions from `render_lab_tasks_gdrive.tasks`; combine `app` objects
|
|
13
|
+
with `Workflows.from_workflows(...)`. JSON fields retain TS spelling; functions
|
|
14
|
+
use snake_case. Package root imports are inert.
|
|
15
|
+
|
|
16
|
+
## Tasks
|
|
17
|
+
|
|
18
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| `gdrive.copy` | `copy` |
|
|
21
|
+
| `gdrive.createFolder` | `create_folder` |
|
|
22
|
+
| `gdrive.delete` | `delete` |
|
|
23
|
+
| `gdrive.download` | `download` |
|
|
24
|
+
| `gdrive.export` | `export` |
|
|
25
|
+
| `gdrive.getFile` | `get_file` |
|
|
26
|
+
| `gdrive.move` | `move` |
|
|
27
|
+
| `gdrive.search` | `search` |
|
|
28
|
+
| `gdrive.share` | `share` |
|
|
29
|
+
| `gdrive.upload` | `upload` |
|
|
30
|
+
|
|
31
|
+
## Dependencies and retries
|
|
32
|
+
|
|
33
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
34
|
+
module exports typed `Port`, `Deps`, and `Client` classes. Inject a fake port, or
|
|
35
|
+
pass a caller-owned `httpx.AsyncClient` to `Client`. Default dependencies close
|
|
36
|
+
their client after one operation. Credentials resolve at first use. Transport
|
|
37
|
+
retries are disabled; `retry.py` owns durable policies. DTO types are in `.types`.
|
|
38
|
+
Requires core >=0.1.1.
|
|
39
|
+
|
|
40
|
+
## Environment
|
|
41
|
+
|
|
42
|
+
| Variable | Contract |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `GOOGLE_ACCESS_TOKEN` | Optional pre-issued token; takes precedence. |
|
|
45
|
+
| `GOOGLE_CLIENT_ID` | Required with secret and refresh token when no access token is supplied. |
|
|
46
|
+
| `GOOGLE_CLIENT_SECRET` | OAuth client secret for refresh. |
|
|
47
|
+
| `GOOGLE_REFRESH_TOKEN` | Refresh token granted the scopes for the operations you use. |
|
|
48
|
+
|
|
49
|
+
## Verification and limitations
|
|
50
|
+
|
|
51
|
+
Google Drive v3 supports text uploads/downloads and exports through this surface.
|
|
52
|
+
Python caps inline text at 1 MiB and rejects malformed MIME headers or multipart
|
|
53
|
+
boundary collisions. Search returns one page. Upload/createFolder/copy retain the
|
|
54
|
+
TS three-retry policy and may duplicate a resource after an ambiguous response.
|
|
55
|
+
Sharing changes permissions; test against a dedicated folder and account.
|
|
56
|
+
|
|
57
|
+
Shared fixtures execute the actual pinned TS implementations and compare Python
|
|
58
|
+
outputs and requests. Sanity's SDK calls are translated into separately asserted
|
|
59
|
+
REST requests. These are hermetic checks, not real account or hosted verification.
|
|
60
|
+
See [the testing backlog](https://github.com/render-lab/render-tasks-python/issues/1)
|
|
61
|
+
and the root verification tracker. Licensed under MIT.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "render-lab-tasks-gdrive"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "gdrive tasks for Render Workflows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dependencies = ["render==1.0.1", "httpx>=0.28,<0.29", "render-lab-tasks-core>=0.1.1,<0.2"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/render-lab/render-tasks-python"
|
|
17
|
+
|
|
18
|
+
[tool.uv.sources]
|
|
19
|
+
render-lab-tasks-core = { workspace = true }
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/render_lab_tasks_gdrive"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Import .tasks explicitly to register durable tasks."""
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Injected vendor interface and one-attempt async HTTP adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from collections.abc import AsyncIterator, Mapping
|
|
8
|
+
from contextlib import asynccontextmanager
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from typing import Any, Protocol
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
from render_lab_tasks_core.bounded import MAX_TEXT_BYTES, assert_byte_limit
|
|
14
|
+
from render_lab_tasks_core.google_auth import GoogleAccessToken
|
|
15
|
+
from render_lab_tasks_core.http import HttpClient, enc, nullish, pick, query
|
|
16
|
+
|
|
17
|
+
from . import types as t
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def drive_file(row: Any) -> t.DriveFile:
|
|
21
|
+
return {
|
|
22
|
+
"id": nullish(row.get("id"), ""),
|
|
23
|
+
"name": nullish(row.get("name"), ""),
|
|
24
|
+
"mimeType": nullish(row.get("mimeType"), ""),
|
|
25
|
+
"webViewLink": nullish(row.get("webViewLink"), ""),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Port(Protocol):
|
|
30
|
+
async def copy(self, input: t.CopyInput) -> t.DriveFile: ...
|
|
31
|
+
async def create_folder(self, input: t.CreateFolderInput) -> t.DriveFile: ...
|
|
32
|
+
async def delete(self, input: t.DeleteInput) -> t.DeleteResult: ...
|
|
33
|
+
async def download(self, input: t.DownloadInput) -> t.DownloadResult: ...
|
|
34
|
+
async def export(self, input: t.ExportInput) -> t.ExportResult: ...
|
|
35
|
+
async def get_file(self, input: t.GetFileInput) -> t.DriveFile: ...
|
|
36
|
+
async def move(self, input: t.MoveInput) -> t.DriveFile: ...
|
|
37
|
+
async def search(self, input: t.SearchInput) -> list[t.DriveFile]: ...
|
|
38
|
+
async def share(self, input: t.ShareInput) -> t.ShareResult: ...
|
|
39
|
+
async def upload(self, input: t.UploadInput) -> t.UploadResult: ...
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class Deps:
|
|
44
|
+
gdrive: Port
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Client:
|
|
48
|
+
def __init__(self, http: httpx.AsyncClient, env: Mapping[str, str] | None = None) -> None:
|
|
49
|
+
self.env = os.environ if env is None else env
|
|
50
|
+
self.auth = GoogleAccessToken(http, self.env)
|
|
51
|
+
self.api = HttpClient(
|
|
52
|
+
http, "https://www.googleapis.com", auth=self.auth.headers, label="Google Drive"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
async def upload(self, input: t.UploadInput) -> t.UploadResult:
|
|
56
|
+
mime = input.get("mimeType", "text/plain")
|
|
57
|
+
if "\r" in mime or "\n" in mime:
|
|
58
|
+
raise ValueError("mimeType must not contain CR or LF")
|
|
59
|
+
metadata: dict[str, Any] = {"name": input["name"], "mimeType": mime}
|
|
60
|
+
if "parentId" in input:
|
|
61
|
+
metadata["parents"] = [input["parentId"]]
|
|
62
|
+
content = input["content"]
|
|
63
|
+
assert_byte_limit("gdrive.upload content", content.encode(), MAX_TEXT_BYTES)
|
|
64
|
+
boundary = "render-tasks-gdrive-boundary"
|
|
65
|
+
if boundary in content:
|
|
66
|
+
raise ValueError("content must not contain the multipart boundary")
|
|
67
|
+
body = "\r\n".join(
|
|
68
|
+
[
|
|
69
|
+
"--" + boundary,
|
|
70
|
+
"Content-Type: application/json; charset=UTF-8",
|
|
71
|
+
"",
|
|
72
|
+
json.dumps(metadata, ensure_ascii=False, separators=(",", ":")),
|
|
73
|
+
"--" + boundary,
|
|
74
|
+
"Content-Type: " + mime,
|
|
75
|
+
"",
|
|
76
|
+
content,
|
|
77
|
+
"--" + boundary + "--",
|
|
78
|
+
]
|
|
79
|
+
)
|
|
80
|
+
data = await self.api.call(
|
|
81
|
+
"/upload/drive/v3/files?uploadType=multipart&fields=id,webViewLink",
|
|
82
|
+
method="POST",
|
|
83
|
+
raw_body=body,
|
|
84
|
+
headers={"content-type": "multipart/related; boundary=" + boundary},
|
|
85
|
+
)
|
|
86
|
+
return {
|
|
87
|
+
"fileId": nullish(data.get("id"), ""),
|
|
88
|
+
"webViewLink": nullish(data.get("webViewLink"), ""),
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async def search(self, input: t.SearchInput) -> list[t.DriveFile]:
|
|
92
|
+
params: dict[str, Any] = {
|
|
93
|
+
"q": input["query"],
|
|
94
|
+
"fields": "files(id,name,mimeType,webViewLink)",
|
|
95
|
+
}
|
|
96
|
+
if "limit" in input:
|
|
97
|
+
params["pageSize"] = input["limit"]
|
|
98
|
+
data = await self.api.call("/drive/v3/files?" + query(params))
|
|
99
|
+
return [drive_file(row) for row in data.get("files", [])]
|
|
100
|
+
|
|
101
|
+
async def export(self, input: t.ExportInput) -> t.ExportResult:
|
|
102
|
+
content = await self.api.call(
|
|
103
|
+
"/drive/v3/files/"
|
|
104
|
+
+ enc(input["fileId"])
|
|
105
|
+
+ "/export?"
|
|
106
|
+
+ query({"mimeType": input["mimeType"]}),
|
|
107
|
+
response_type="text",
|
|
108
|
+
)
|
|
109
|
+
assert_byte_limit("gdrive.export content", content.encode(), MAX_TEXT_BYTES)
|
|
110
|
+
return {"fileId": input["fileId"], "content": content}
|
|
111
|
+
|
|
112
|
+
async def download(self, input: t.DownloadInput) -> t.DownloadResult:
|
|
113
|
+
content = await self.api.call(
|
|
114
|
+
"/drive/v3/files/" + enc(input["fileId"]) + "?alt=media", response_type="text"
|
|
115
|
+
)
|
|
116
|
+
assert_byte_limit("gdrive.download content", content.encode(), MAX_TEXT_BYTES)
|
|
117
|
+
return {"fileId": input["fileId"], "content": content}
|
|
118
|
+
|
|
119
|
+
async def get_file(self, input: t.GetFileInput) -> t.DriveFile:
|
|
120
|
+
return drive_file(
|
|
121
|
+
await self.api.call(
|
|
122
|
+
"/drive/v3/files/" + enc(input["fileId"]) + "?fields=id,name,mimeType,webViewLink"
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
async def share(self, input: t.ShareInput) -> t.ShareResult:
|
|
127
|
+
row = await self.api.call(
|
|
128
|
+
"/drive/v3/files/" + enc(input["fileId"]) + "/permissions",
|
|
129
|
+
method="POST",
|
|
130
|
+
body=pick(input, "role", "type", "emailAddress"),
|
|
131
|
+
)
|
|
132
|
+
return {
|
|
133
|
+
"permissionId": nullish(row.get("id"), ""),
|
|
134
|
+
"role": nullish(row.get("role"), ""),
|
|
135
|
+
"type": nullish(row.get("type"), ""),
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async def create_folder(self, input: t.CreateFolderInput) -> t.DriveFile:
|
|
139
|
+
body: dict[str, Any] = {
|
|
140
|
+
"name": input["name"],
|
|
141
|
+
"mimeType": "application/vnd.google-apps.folder",
|
|
142
|
+
}
|
|
143
|
+
if "parentId" in input:
|
|
144
|
+
body["parents"] = [input["parentId"]]
|
|
145
|
+
return drive_file(
|
|
146
|
+
await self.api.call(
|
|
147
|
+
"/drive/v3/files?fields=id,name,mimeType,webViewLink", method="POST", body=body
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
async def move(self, input: t.MoveInput) -> t.DriveFile:
|
|
152
|
+
params = pick(input, "addParents", "removeParents")
|
|
153
|
+
params["fields"] = "id,name,mimeType,webViewLink"
|
|
154
|
+
return drive_file(
|
|
155
|
+
await self.api.call(
|
|
156
|
+
"/drive/v3/files/" + enc(input["fileId"]) + "?" + query(params), method="PATCH"
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
async def copy(self, input: t.CopyInput) -> t.DriveFile:
|
|
161
|
+
return drive_file(
|
|
162
|
+
await self.api.call(
|
|
163
|
+
"/drive/v3/files/"
|
|
164
|
+
+ enc(input["fileId"])
|
|
165
|
+
+ "/copy?fields=id,name,mimeType,webViewLink",
|
|
166
|
+
method="POST",
|
|
167
|
+
body=pick(input, "name"),
|
|
168
|
+
)
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
async def delete(self, input: t.DeleteInput) -> t.DeleteResult:
|
|
172
|
+
await self.api.call(
|
|
173
|
+
"/drive/v3/files/" + enc(input["fileId"]), method="DELETE", response_type="text"
|
|
174
|
+
)
|
|
175
|
+
return {"id": input["fileId"], "deleted": True}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@asynccontextmanager
|
|
179
|
+
async def dependencies(deps: Deps | None) -> AsyncIterator[Deps]:
|
|
180
|
+
if deps is not None:
|
|
181
|
+
yield deps
|
|
182
|
+
else:
|
|
183
|
+
async with httpx.AsyncClient(
|
|
184
|
+
timeout=30, transport=httpx.AsyncHTTPTransport(retries=0)
|
|
185
|
+
) as http:
|
|
186
|
+
yield Deps(gdrive=Client(http))
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
GdrivePort = Port
|
|
190
|
+
GdriveClient = Client
|
|
191
|
+
GdriveDeps = Deps
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import CopyInput, DriveFile
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def copy_impl(ctx: TaskContext, input: CopyInput, *, deps: Deps | None = None) -> DriveFile:
|
|
10
|
+
async with dependencies(deps) as resolved:
|
|
11
|
+
return await resolved.gdrive.copy(input)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.task(name="gdrive.copy", retry=GDRIVE_RETRY)
|
|
15
|
+
async def copy(ctx: TaskContext, input: CopyInput) -> DriveFile:
|
|
16
|
+
return await copy_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import CreateFolderInput, DriveFile
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_folder_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateFolderInput, *, deps: Deps | None = None
|
|
11
|
+
) -> DriveFile:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.create_folder(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.createFolder", retry=GDRIVE_RETRY)
|
|
17
|
+
async def create_folder(ctx: TaskContext, input: CreateFolderInput) -> DriveFile:
|
|
18
|
+
return await create_folder_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import DeleteInput, DeleteResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def delete_impl(
|
|
10
|
+
ctx: TaskContext, input: DeleteInput, *, deps: Deps | None = None
|
|
11
|
+
) -> DeleteResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.delete(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.delete", retry=GDRIVE_RETRY)
|
|
17
|
+
async def delete(ctx: TaskContext, input: DeleteInput) -> DeleteResult:
|
|
18
|
+
return await delete_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import DownloadInput, DownloadResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def download_impl(
|
|
10
|
+
ctx: TaskContext, input: DownloadInput, *, deps: Deps | None = None
|
|
11
|
+
) -> DownloadResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.download(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.download", retry=GDRIVE_RETRY)
|
|
17
|
+
async def download(ctx: TaskContext, input: DownloadInput) -> DownloadResult:
|
|
18
|
+
return await download_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import ExportInput, ExportResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def export_impl(
|
|
10
|
+
ctx: TaskContext, input: ExportInput, *, deps: Deps | None = None
|
|
11
|
+
) -> ExportResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.export(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.export", retry=GDRIVE_RETRY)
|
|
17
|
+
async def export(ctx: TaskContext, input: ExportInput) -> ExportResult:
|
|
18
|
+
return await export_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import DriveFile, GetFileInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_file_impl(
|
|
10
|
+
ctx: TaskContext, input: GetFileInput, *, deps: Deps | None = None
|
|
11
|
+
) -> DriveFile:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.get_file(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.getFile", retry=GDRIVE_RETRY)
|
|
17
|
+
async def get_file(ctx: TaskContext, input: GetFileInput) -> DriveFile:
|
|
18
|
+
return await get_file_impl(ctx, input)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import DriveFile, MoveInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def move_impl(ctx: TaskContext, input: MoveInput, *, deps: Deps | None = None) -> DriveFile:
|
|
10
|
+
async with dependencies(deps) as resolved:
|
|
11
|
+
return await resolved.gdrive.move(input)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.task(name="gdrive.move", retry=GDRIVE_RETRY)
|
|
15
|
+
async def move(ctx: TaskContext, input: MoveInput) -> DriveFile:
|
|
16
|
+
return await move_impl(ctx, input)
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import DriveFile, SearchInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def search_impl(
|
|
10
|
+
ctx: TaskContext, input: SearchInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[DriveFile]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.search(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.search", retry=GDRIVE_RETRY)
|
|
17
|
+
async def search(ctx: TaskContext, input: SearchInput) -> list[DriveFile]:
|
|
18
|
+
return await search_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import ShareInput, ShareResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def share_impl(
|
|
10
|
+
ctx: TaskContext, input: ShareInput, *, deps: Deps | None = None
|
|
11
|
+
) -> ShareResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.share(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.share", retry=GDRIVE_RETRY)
|
|
17
|
+
async def share(ctx: TaskContext, input: ShareInput) -> ShareResult:
|
|
18
|
+
return await share_impl(ctx, input)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from ._app import app
|
|
2
|
+
from .copy import copy, copy_impl
|
|
3
|
+
from .create_folder import create_folder, create_folder_impl
|
|
4
|
+
from .delete import delete, delete_impl
|
|
5
|
+
from .download import download, download_impl
|
|
6
|
+
from .export import export, export_impl
|
|
7
|
+
from .get_file import get_file, get_file_impl
|
|
8
|
+
from .move import move, move_impl
|
|
9
|
+
from .search import search, search_impl
|
|
10
|
+
from .share import share, share_impl
|
|
11
|
+
from .upload import upload, upload_impl
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"app",
|
|
15
|
+
"copy",
|
|
16
|
+
"copy_impl",
|
|
17
|
+
"create_folder",
|
|
18
|
+
"create_folder_impl",
|
|
19
|
+
"delete",
|
|
20
|
+
"delete_impl",
|
|
21
|
+
"download",
|
|
22
|
+
"download_impl",
|
|
23
|
+
"export",
|
|
24
|
+
"export_impl",
|
|
25
|
+
"get_file",
|
|
26
|
+
"get_file_impl",
|
|
27
|
+
"move",
|
|
28
|
+
"move_impl",
|
|
29
|
+
"search",
|
|
30
|
+
"search_impl",
|
|
31
|
+
"share",
|
|
32
|
+
"share_impl",
|
|
33
|
+
"upload",
|
|
34
|
+
"upload_impl",
|
|
35
|
+
]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""JSON contracts ported from the pinned TypeScript pack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal, NotRequired, TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DriveFile(TypedDict):
|
|
9
|
+
id: str
|
|
10
|
+
name: str
|
|
11
|
+
mimeType: str
|
|
12
|
+
webViewLink: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class UploadInput(TypedDict):
|
|
16
|
+
name: str
|
|
17
|
+
content: str
|
|
18
|
+
mimeType: NotRequired[str]
|
|
19
|
+
parentId: NotRequired[str]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class UploadResult(TypedDict):
|
|
23
|
+
fileId: str
|
|
24
|
+
webViewLink: str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SearchInput(TypedDict):
|
|
28
|
+
query: str
|
|
29
|
+
limit: NotRequired[float]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ExportInput(TypedDict):
|
|
33
|
+
fileId: str
|
|
34
|
+
mimeType: str
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ExportResult(TypedDict):
|
|
38
|
+
fileId: str
|
|
39
|
+
content: str
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class GetFileInput(TypedDict):
|
|
43
|
+
fileId: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class DownloadInput(TypedDict):
|
|
47
|
+
fileId: str
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class DownloadResult(TypedDict):
|
|
51
|
+
fileId: str
|
|
52
|
+
content: str
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ShareInput(TypedDict):
|
|
56
|
+
fileId: str
|
|
57
|
+
role: str
|
|
58
|
+
type: str
|
|
59
|
+
emailAddress: NotRequired[str]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ShareResult(TypedDict):
|
|
63
|
+
permissionId: str
|
|
64
|
+
role: str
|
|
65
|
+
type: str
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class CreateFolderInput(TypedDict):
|
|
69
|
+
name: str
|
|
70
|
+
parentId: NotRequired[str]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class MoveInput(TypedDict):
|
|
74
|
+
fileId: str
|
|
75
|
+
addParents: NotRequired[str]
|
|
76
|
+
removeParents: NotRequired[str]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class CopyInput(TypedDict):
|
|
80
|
+
fileId: str
|
|
81
|
+
name: NotRequired[str]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class DeleteInput(TypedDict):
|
|
85
|
+
fileId: str
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class DeleteResult(TypedDict):
|
|
89
|
+
id: str
|
|
90
|
+
deleted: Literal[True]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GDRIVE_RETRY
|
|
6
|
+
from .types import UploadInput, UploadResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def upload_impl(
|
|
10
|
+
ctx: TaskContext, input: UploadInput, *, deps: Deps | None = None
|
|
11
|
+
) -> UploadResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gdrive.upload(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gdrive.upload", retry=GDRIVE_RETRY)
|
|
17
|
+
async def upload(ctx: TaskContext, input: UploadInput) -> UploadResult:
|
|
18
|
+
return await upload_impl(ctx, input)
|