feat: admin/drive/* をサポート

pull/105/head
yupix 10 months ago
parent 86cc8edb72
commit d098b91eca
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -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",
@ -815,43 +815,43 @@
"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",

@ -1,4 +1,8 @@
## SUPPORTED ENDPOINTS (54/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
@ -19,6 +23,13 @@
- [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
@ -73,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
@ -172,13 +179,6 @@
- [ ] /clips/favorite
- [ ] /clips/unfavorite
- [ ] /clips/my-favorites
- [ ] /drive/folders
- [ ] /drive/folders/create
- [ ] /drive/folders/delete
- [ ] /drive/folders/find
- [ ] /drive/folders/show
- [ ] /drive/folders/update
- [ ] /drive/stream
- [ ] /email-address/available
- [ ] /endpoint
- [ ] /endpoints

@ -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

@ -7,6 +7,7 @@ from mipac.actions.admins.admin import AdminActions
from mipac.http import HTTPClient
from mipac.manager.admins.ad import AdminAdvertisingManager, AdminAdvertisingModelManager
from mipac.manager.admins.announcement import AdminAnnouncementManager
from mipac.manager.admins.drive import AdminDriveManager
from mipac.manager.admins.emoji import AdminEmojiManager
from mipac.manager.admins.invite import AdminInviteManager
from mipac.manager.admins.moderator import AdminModeratorManager
@ -32,6 +33,7 @@ class AdminManager(AbstractManager):
)
self.role: AdminRolesManager = AdminRolesManager(session=session, client=client)
self.invite: AdminInviteManager = AdminInviteManager(session=session, client=client)
self.drive: AdminDriveManager = AdminDriveManager(session=session, client=client)
@property
def action(self) -> AdminActions:

@ -0,0 +1,20 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from mipac.abstract.manager import AbstractManager
from mipac.actions.admins.drive import AdminDriveActions
from mipac.http import HTTPClient
if TYPE_CHECKING:
from mipac.manager.client import ClientManager
class AdminDriveManager(AbstractManager):
def __init__(self, *, session: HTTPClient, client: ClientManager):
self.__session: HTTPClient = session
self.__client: ClientManager = client
@property
def action(self) -> AdminDriveActions:
return AdminDriveActions(session=self.__session, client=self.__client)
Loading…
Cancel
Save