Skip to content

Commit

Permalink
Merge pull request #105 from yupix/feat/v13/drive
Browse files Browse the repository at this point in the history
Feat/v13/drive
  • Loading branch information
yupix authored Dec 3, 2023
2 parents f30f0e5 + d098b91 commit b286098
Show file tree
Hide file tree
Showing 23 changed files with 1,479 additions and 134 deletions.
44 changes: 22 additions & 22 deletions compiler/datas/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@
"path": "/admin/drive/clean-remote-files",
"request_body_hash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
"response_body_hash": "df9c0f9df08effe88b00991f12e46077998bd6d6c3442ec518e5f463680a2c54",
"status": "notSupported"
"status": "supported"
},
"/admin/drive/cleanup": {
"path": "/admin/drive/cleanup",
"request_body_hash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
"response_body_hash": "df9c0f9df08effe88b00991f12e46077998bd6d6c3442ec518e5f463680a2c54",
"status": "notSupported"
"status": "supported"
},
"/admin/drive/files": {
"path": "/admin/drive/files",
"request_body_hash": "9ebcea5313a97912edcd89706b8a7ea82b795b8cb3d9e33a8666b4f1103e0a22",
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
"status": "notSupported"
"status": "supported"
},
"/admin/drive/show-file": {
"path": "/admin/drive/show-file",
"request_body_hash": "469dab9342135333df7936e6dd1a691a975e6b5c205b5ab3040be3bf31a18a17",
"response_body_hash": "d94c18840a05c740b14f2ef553f09c0a2a278a698b21b8cc5cb79a5a7f8dfa25",
"status": "notSupported"
"status": "supported"
},
"/admin/emoji/add-aliases-bulk": {
"path": "/admin/emoji/add-aliases-bulk",
Expand Down Expand Up @@ -749,109 +749,109 @@
"path": "/drive",
"request_body_hash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
"response_body_hash": "3d1b96d30d248d61c4b1eee203b84f2bad48d6c200851942e368b88104166b1b",
"status": "notSupported"
"status": "supported"
},
"/drive/files": {
"path": "/drive/files",
"request_body_hash": "b07070c472a648963651db6e280e39b490558d9adb92ce7db9d05590178353b9",
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
"status": "notSupported"
"status": "supported"
},
"/drive/files/attached-notes": {
"path": "/drive/files/attached-notes",
"request_body_hash": "483cf6378fc3db55c9c3acfb484f77012c0e9ab2abf81bef519089ad0ae27a03",
"response_body_hash": "507fab37c26ecb65a55f1f6f11ac18dc875d5594d656588a4c15b396cd35414f",
"status": "notSupported"
"status": "supported"
},
"/drive/files/check-existence": {
"path": "/drive/files/check-existence",
"request_body_hash": "ea75dd1736f53c4238eada5abf871fea88c144b71f03fdaf9f7e56024322a2f3",
"response_body_hash": "dd9c6671e5d139f32b17da6b74c2c6498de7ec65cf072b2df951e8c2be5eb477",
"status": "notSupported"
"status": "supported"
},
"/drive/files/create": {
"path": "/drive/files/create",
"request_body_hash": "ee93867da40daf79738829f3bfb7532aad7c60d97f7e54c3f2843ca00fe8cfb9",
"response_body_hash": "28d7477d5157e558c4ab3a0c2e2491c17fefc80ad803879a9f38c8fffec27e2c",
"status": "notSupported"
"status": "supported"
},
"/drive/files/delete": {
"path": "/drive/files/delete",
"request_body_hash": "d7c20d1b69b13b8c3bdce034764d6b159e21e14eb20dc6f001c023ed47973e4c",
"response_body_hash": "01c3864371cb588f305a706f8083f52d6bb7d249280aa302dfef644c27531a67",
"status": "notSupported"
"status": "supported"
},
"/drive/files/find-by-hash": {
"path": "/drive/files/find-by-hash",
"request_body_hash": "ea75dd1736f53c4238eada5abf871fea88c144b71f03fdaf9f7e56024322a2f3",
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
"status": "notSupported"
"status": "supported"
},
"/drive/files/find": {
"path": "/drive/files/find",
"request_body_hash": "be819aa65c197bbe301a63e26be5bc04e6c2a774fce630c23d710a4a2a38e4cf",
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
"status": "notSupported"
"status": "supported"
},
"/drive/files/show": {
"path": "/drive/files/show",
"request_body_hash": "469dab9342135333df7936e6dd1a691a975e6b5c205b5ab3040be3bf31a18a17",
"response_body_hash": "977e40bbf78c7880fbcfeeaf886ab76a912d931e9f46707cb55f2cac64c912d2",
"status": "notSupported"
"status": "supported"
},
"/drive/files/update": {
"path": "/drive/files/update",
"request_body_hash": "c2f7cb37c89d08770d768c1737d2b1dc5cb1491ca1eacd4729ecd8d9f0701b72",
"response_body_hash": "1c935759ba3714e4fc6f6c50ec7505ec744a75714d14ff521ea6a8a2b79f5638",
"status": "notSupported"
"status": "supported"
},
"/drive/files/upload-from-url": {
"path": "/drive/files/upload-from-url",
"request_body_hash": "6a82791ea48bc99f67991548b827191c536ab8f4c08732f95a06f66b910a2167",
"response_body_hash": "aead474d2cf0cb02f40e88b806a7f993e6dc1567de6897b7d278c9cc96109291",
"status": "notSupported"
"status": "supported"
},
"/drive/folders": {
"path": "/drive/folders",
"request_body_hash": "163479964ef668b9c9cd22dc1e66d6802c8c39333935f25db4856b75f49c4fc1",
"response_body_hash": "f6400fb425c732cf542f468e2ff22ee8e4d36d83215e7f62e0d193f05febe8ec",
"status": "notSupported"
"status": "supported"
},
"/drive/folders/create": {
"path": "/drive/folders/create",
"request_body_hash": "704fe9fb2fb297fb5ca12b43d10db5f98c593ae7285c93ba3036f3937ec35170",
"response_body_hash": "221664a7a1649aac74388f963da64899b866f1f94e8f064edc4e99b2669170db",
"status": "notSupported"
"status": "supported"
},
"/drive/folders/delete": {
"path": "/drive/folders/delete",
"request_body_hash": "7ddbf084df376fe1ced074c9454678879e8908a99fe0432fb2abaadfa597afec",
"response_body_hash": "c558d54c2fd862408f9556860946477010c0c5b6896032e5e3674ee638e2011b",
"status": "notSupported"
"status": "supported"
},
"/drive/folders/find": {
"path": "/drive/folders/find",
"request_body_hash": "574816af65798e0bd7e0b75836b95942423d7f4abe90f6e7f589ca84b6398a32",
"response_body_hash": "f6400fb425c732cf542f468e2ff22ee8e4d36d83215e7f62e0d193f05febe8ec",
"status": "notSupported"
"status": "supported"
},
"/drive/folders/show": {
"path": "/drive/folders/show",
"request_body_hash": "7ddbf084df376fe1ced074c9454678879e8908a99fe0432fb2abaadfa597afec",
"response_body_hash": "2af351d06be9588d35f8d01cd87b292bc624a7e766d694c769c699096628a4ce",
"status": "notSupported"
"status": "supported"
},
"/drive/folders/update": {
"path": "/drive/folders/update",
"request_body_hash": "b6f56d4e2737010dcf22a28754fbd127c4b3cdc61db501412d8da2ab9f002295",
"response_body_hash": "e98b858e48224fef52ae844a57f5adb5b18c0bf7155471ee27d423b947be52a1",
"status": "notSupported"
"status": "supported"
},
"/drive/stream": {
"path": "/drive/stream",
"request_body_hash": "bcc9a12d16667bf8e0beeb82f256a9c3acc694244f87fd588eada0896704f2e9",
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
"status": "notSupported"
"status": "supported"
},
"/email-address/available": {
"path": "/email-address/available",
Expand Down
46 changes: 23 additions & 23 deletions compiler/datas/support_status.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## SUPPORTED ENDPOINTS (43/322)
## SUPPORTED ENDPOINTS (65/322)
- [x] /admin/drive/clean-remote-files
- [x] /admin/drive/cleanup
- [x] /admin/drive/files
- [x] /admin/drive/show-file
- [x] /admin/get-index-stats
- [x] /admin/get-table-stats
- [x] /admin/get-user-ips
Expand All @@ -8,6 +12,24 @@
- [x] /admin/show-moderation-logs
- [x] /admin/unsuspend-user
- [x] /admin/update-user-note
- [x] /drive
- [x] /drive/files
- [x] /drive/files/attached-notes
- [x] /drive/files/check-existence
- [x] /drive/files/create
- [x] /drive/files/delete
- [x] /drive/files/find-by-hash
- [x] /drive/files/find
- [x] /drive/files/show
- [x] /drive/files/update
- [x] /drive/files/upload-from-url
- [x] /drive/folders
- [x] /drive/folders/create
- [x] /drive/folders/delete
- [x] /drive/folders/find
- [x] /drive/folders/show
- [x] /drive/folders/update
- [x] /drive/stream
- [x] /i
- [x] /invite/create
- [x] /invite/delete
Expand Down Expand Up @@ -62,10 +84,6 @@
- [ ] /admin/avatar-decorations/list
- [ ] /admin/avatar-decorations/update
- [ ] /admin/delete-all-files-of-a-user
- [ ] /admin/drive/clean-remote-files
- [ ] /admin/drive/cleanup
- [ ] /admin/drive/files
- [ ] /admin/drive/show-file
- [ ] /admin/emoji/add-aliases-bulk
- [ ] /admin/emoji/add
- [ ] /admin/emoji/copy
Expand Down Expand Up @@ -161,24 +179,6 @@
- [ ] /clips/favorite
- [ ] /clips/unfavorite
- [ ] /clips/my-favorites
- [ ] /drive
- [ ] /drive/files
- [ ] /drive/files/attached-notes
- [ ] /drive/files/check-existence
- [ ] /drive/files/create
- [ ] /drive/files/delete
- [ ] /drive/files/find-by-hash
- [ ] /drive/files/find
- [ ] /drive/files/show
- [ ] /drive/files/update
- [ ] /drive/files/upload-from-url
- [ ] /drive/folders
- [ ] /drive/folders/create
- [ ] /drive/folders/delete
- [ ] /drive/folders/find
- [ ] /drive/folders/show
- [ ] /drive/folders/update
- [ ] /drive/stream
- [ ] /email-address/available
- [ ] /endpoint
- [ ] /endpoints
Expand Down
128 changes: 128 additions & 0 deletions mipac/actions/admins/drive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Literal

from mipac.abstract.action import AbstractAction
from mipac.http import HTTPClient, Route
from mipac.models.drive import File
from mipac.types.drive import IFile

if TYPE_CHECKING:
from mipac.manager.client import ClientManager


class AdminDriveActions(AbstractAction):
def __init__(self, *, session: HTTPClient, client: ClientManager):
self.__session: HTTPClient = session
self.__client: ClientManager = client

async def clean_remote_files(self) -> bool:
"""Clean remote files
Endpoint: `/api/admin/drive/clean-remote-files`
Returns
-------
bool
Whether the remote files were cleaned
"""

res: bool = await self.__session.request(
Route("POST", "/api/admin/drive/clean-remote-files"), auth=True
)
return res

async def cleanup(self) -> bool:
"""Clean up the drive
Endpoint: `/api/admin/drive/cleanup`
Returns
-------
bool
Whether the drive was cleaned up
"""

res: bool = await self.__session.request(
Route("POST", "/api/admin/drive/cleanup"), auth=True
)
return res

async def get_files(
self,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
user_id: str | None = None,
type: str | None = None,
origin: Literal["combined", "local", "remote"] = "local",
hostname: str | None = None,
) -> list[File]:
"""Get all files
Endpoint: `/api/admin/drive/files`
Parameters
----------
limit: int
The number of files to get
since_id: str
The id of the file to start from
until_id: str
The id of the file to end at
type: str
The type of file to get
user_id: str
The id of the user to get files from
origin: Literal['combined', 'local', 'remote']
The origin of the files
hostname: str
The hostname of the files
Returns
-------
list[File]
A list of files
"""

data = {
"limit": limit,
"sinceId": since_id,
"untilId": until_id,
"type": type,
"userId": user_id,
"origin": origin,
"hostname": hostname,
}
raw_files: list[IFile] = await self.__session.request(
Route("POST", "/api/admin/drive/files"), auth=True, json=data
)
return [File(raw_file=file, client=self.__client) for file in raw_files]

async def show_file(self, file_id: str, url: str | None = None):
"""Show a file
Endpoint: `/api/admin/drive/files/show`
Parameters
----------
file_id: str
The id of the file to show
url: str
The url of the file to show
Returns
-------
dict[str, Any]
The file
"""

data = {
"fileId": file_id,
"url": url,
}
# TODO: IFileではなく、ほぼほぼデータベースの中身が返ってくるのでそれに合わせた型とモデルを作る
raw_file: dict[str, Any] = await self.__session.request(
Route("POST", "/api/admin/drive/show-file"), auth=True, json=data
)
return raw_file
Loading

0 comments on commit b286098

Please sign in to comment.