Skip to content

Commit b286098

Browse files
authored
Merge pull request #105 from yupix/feat/v13/drive
Feat/v13/drive
2 parents f30f0e5 + d098b91 commit b286098

File tree

23 files changed

+1479
-134
lines changed

23 files changed

+1479
-134
lines changed

compiler/datas/endpoints.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,25 @@
101101
"path": "/admin/drive/clean-remote-files",
102102
"request_body_hash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
103103
"response_body_hash": "df9c0f9df08effe88b00991f12e46077998bd6d6c3442ec518e5f463680a2c54",
104-
"status": "notSupported"
104+
"status": "supported"
105105
},
106106
"/admin/drive/cleanup": {
107107
"path": "/admin/drive/cleanup",
108108
"request_body_hash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
109109
"response_body_hash": "df9c0f9df08effe88b00991f12e46077998bd6d6c3442ec518e5f463680a2c54",
110-
"status": "notSupported"
110+
"status": "supported"
111111
},
112112
"/admin/drive/files": {
113113
"path": "/admin/drive/files",
114114
"request_body_hash": "9ebcea5313a97912edcd89706b8a7ea82b795b8cb3d9e33a8666b4f1103e0a22",
115115
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
116-
"status": "notSupported"
116+
"status": "supported"
117117
},
118118
"/admin/drive/show-file": {
119119
"path": "/admin/drive/show-file",
120120
"request_body_hash": "469dab9342135333df7936e6dd1a691a975e6b5c205b5ab3040be3bf31a18a17",
121121
"response_body_hash": "d94c18840a05c740b14f2ef553f09c0a2a278a698b21b8cc5cb79a5a7f8dfa25",
122-
"status": "notSupported"
122+
"status": "supported"
123123
},
124124
"/admin/emoji/add-aliases-bulk": {
125125
"path": "/admin/emoji/add-aliases-bulk",
@@ -749,109 +749,109 @@
749749
"path": "/drive",
750750
"request_body_hash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
751751
"response_body_hash": "3d1b96d30d248d61c4b1eee203b84f2bad48d6c200851942e368b88104166b1b",
752-
"status": "notSupported"
752+
"status": "supported"
753753
},
754754
"/drive/files": {
755755
"path": "/drive/files",
756756
"request_body_hash": "b07070c472a648963651db6e280e39b490558d9adb92ce7db9d05590178353b9",
757757
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
758-
"status": "notSupported"
758+
"status": "supported"
759759
},
760760
"/drive/files/attached-notes": {
761761
"path": "/drive/files/attached-notes",
762762
"request_body_hash": "483cf6378fc3db55c9c3acfb484f77012c0e9ab2abf81bef519089ad0ae27a03",
763763
"response_body_hash": "507fab37c26ecb65a55f1f6f11ac18dc875d5594d656588a4c15b396cd35414f",
764-
"status": "notSupported"
764+
"status": "supported"
765765
},
766766
"/drive/files/check-existence": {
767767
"path": "/drive/files/check-existence",
768768
"request_body_hash": "ea75dd1736f53c4238eada5abf871fea88c144b71f03fdaf9f7e56024322a2f3",
769769
"response_body_hash": "dd9c6671e5d139f32b17da6b74c2c6498de7ec65cf072b2df951e8c2be5eb477",
770-
"status": "notSupported"
770+
"status": "supported"
771771
},
772772
"/drive/files/create": {
773773
"path": "/drive/files/create",
774774
"request_body_hash": "ee93867da40daf79738829f3bfb7532aad7c60d97f7e54c3f2843ca00fe8cfb9",
775775
"response_body_hash": "28d7477d5157e558c4ab3a0c2e2491c17fefc80ad803879a9f38c8fffec27e2c",
776-
"status": "notSupported"
776+
"status": "supported"
777777
},
778778
"/drive/files/delete": {
779779
"path": "/drive/files/delete",
780780
"request_body_hash": "d7c20d1b69b13b8c3bdce034764d6b159e21e14eb20dc6f001c023ed47973e4c",
781781
"response_body_hash": "01c3864371cb588f305a706f8083f52d6bb7d249280aa302dfef644c27531a67",
782-
"status": "notSupported"
782+
"status": "supported"
783783
},
784784
"/drive/files/find-by-hash": {
785785
"path": "/drive/files/find-by-hash",
786786
"request_body_hash": "ea75dd1736f53c4238eada5abf871fea88c144b71f03fdaf9f7e56024322a2f3",
787787
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
788-
"status": "notSupported"
788+
"status": "supported"
789789
},
790790
"/drive/files/find": {
791791
"path": "/drive/files/find",
792792
"request_body_hash": "be819aa65c197bbe301a63e26be5bc04e6c2a774fce630c23d710a4a2a38e4cf",
793793
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
794-
"status": "notSupported"
794+
"status": "supported"
795795
},
796796
"/drive/files/show": {
797797
"path": "/drive/files/show",
798798
"request_body_hash": "469dab9342135333df7936e6dd1a691a975e6b5c205b5ab3040be3bf31a18a17",
799799
"response_body_hash": "977e40bbf78c7880fbcfeeaf886ab76a912d931e9f46707cb55f2cac64c912d2",
800-
"status": "notSupported"
800+
"status": "supported"
801801
},
802802
"/drive/files/update": {
803803
"path": "/drive/files/update",
804804
"request_body_hash": "c2f7cb37c89d08770d768c1737d2b1dc5cb1491ca1eacd4729ecd8d9f0701b72",
805805
"response_body_hash": "1c935759ba3714e4fc6f6c50ec7505ec744a75714d14ff521ea6a8a2b79f5638",
806-
"status": "notSupported"
806+
"status": "supported"
807807
},
808808
"/drive/files/upload-from-url": {
809809
"path": "/drive/files/upload-from-url",
810810
"request_body_hash": "6a82791ea48bc99f67991548b827191c536ab8f4c08732f95a06f66b910a2167",
811811
"response_body_hash": "aead474d2cf0cb02f40e88b806a7f993e6dc1567de6897b7d278c9cc96109291",
812-
"status": "notSupported"
812+
"status": "supported"
813813
},
814814
"/drive/folders": {
815815
"path": "/drive/folders",
816816
"request_body_hash": "163479964ef668b9c9cd22dc1e66d6802c8c39333935f25db4856b75f49c4fc1",
817817
"response_body_hash": "f6400fb425c732cf542f468e2ff22ee8e4d36d83215e7f62e0d193f05febe8ec",
818-
"status": "notSupported"
818+
"status": "supported"
819819
},
820820
"/drive/folders/create": {
821821
"path": "/drive/folders/create",
822822
"request_body_hash": "704fe9fb2fb297fb5ca12b43d10db5f98c593ae7285c93ba3036f3937ec35170",
823823
"response_body_hash": "221664a7a1649aac74388f963da64899b866f1f94e8f064edc4e99b2669170db",
824-
"status": "notSupported"
824+
"status": "supported"
825825
},
826826
"/drive/folders/delete": {
827827
"path": "/drive/folders/delete",
828828
"request_body_hash": "7ddbf084df376fe1ced074c9454678879e8908a99fe0432fb2abaadfa597afec",
829829
"response_body_hash": "c558d54c2fd862408f9556860946477010c0c5b6896032e5e3674ee638e2011b",
830-
"status": "notSupported"
830+
"status": "supported"
831831
},
832832
"/drive/folders/find": {
833833
"path": "/drive/folders/find",
834834
"request_body_hash": "574816af65798e0bd7e0b75836b95942423d7f4abe90f6e7f589ca84b6398a32",
835835
"response_body_hash": "f6400fb425c732cf542f468e2ff22ee8e4d36d83215e7f62e0d193f05febe8ec",
836-
"status": "notSupported"
836+
"status": "supported"
837837
},
838838
"/drive/folders/show": {
839839
"path": "/drive/folders/show",
840840
"request_body_hash": "7ddbf084df376fe1ced074c9454678879e8908a99fe0432fb2abaadfa597afec",
841841
"response_body_hash": "2af351d06be9588d35f8d01cd87b292bc624a7e766d694c769c699096628a4ce",
842-
"status": "notSupported"
842+
"status": "supported"
843843
},
844844
"/drive/folders/update": {
845845
"path": "/drive/folders/update",
846846
"request_body_hash": "b6f56d4e2737010dcf22a28754fbd127c4b3cdc61db501412d8da2ab9f002295",
847847
"response_body_hash": "e98b858e48224fef52ae844a57f5adb5b18c0bf7155471ee27d423b947be52a1",
848-
"status": "notSupported"
848+
"status": "supported"
849849
},
850850
"/drive/stream": {
851851
"path": "/drive/stream",
852852
"request_body_hash": "bcc9a12d16667bf8e0beeb82f256a9c3acc694244f87fd588eada0896704f2e9",
853853
"response_body_hash": "576b61217cbc7e929e6656690e9898c5b933ac5b2629b0a4f7e2389d65315ab1",
854-
"status": "notSupported"
854+
"status": "supported"
855855
},
856856
"/email-address/available": {
857857
"path": "/email-address/available",

compiler/datas/support_status.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## SUPPORTED ENDPOINTS (43/322)
1+
## SUPPORTED ENDPOINTS (65/322)
2+
- [x] /admin/drive/clean-remote-files
3+
- [x] /admin/drive/cleanup
4+
- [x] /admin/drive/files
5+
- [x] /admin/drive/show-file
26
- [x] /admin/get-index-stats
37
- [x] /admin/get-table-stats
48
- [x] /admin/get-user-ips
@@ -8,6 +12,24 @@
812
- [x] /admin/show-moderation-logs
913
- [x] /admin/unsuspend-user
1014
- [x] /admin/update-user-note
15+
- [x] /drive
16+
- [x] /drive/files
17+
- [x] /drive/files/attached-notes
18+
- [x] /drive/files/check-existence
19+
- [x] /drive/files/create
20+
- [x] /drive/files/delete
21+
- [x] /drive/files/find-by-hash
22+
- [x] /drive/files/find
23+
- [x] /drive/files/show
24+
- [x] /drive/files/update
25+
- [x] /drive/files/upload-from-url
26+
- [x] /drive/folders
27+
- [x] /drive/folders/create
28+
- [x] /drive/folders/delete
29+
- [x] /drive/folders/find
30+
- [x] /drive/folders/show
31+
- [x] /drive/folders/update
32+
- [x] /drive/stream
1133
- [x] /i
1234
- [x] /invite/create
1335
- [x] /invite/delete
@@ -62,10 +84,6 @@
6284
- [ ] /admin/avatar-decorations/list
6385
- [ ] /admin/avatar-decorations/update
6486
- [ ] /admin/delete-all-files-of-a-user
65-
- [ ] /admin/drive/clean-remote-files
66-
- [ ] /admin/drive/cleanup
67-
- [ ] /admin/drive/files
68-
- [ ] /admin/drive/show-file
6987
- [ ] /admin/emoji/add-aliases-bulk
7088
- [ ] /admin/emoji/add
7189
- [ ] /admin/emoji/copy
@@ -161,24 +179,6 @@
161179
- [ ] /clips/favorite
162180
- [ ] /clips/unfavorite
163181
- [ ] /clips/my-favorites
164-
- [ ] /drive
165-
- [ ] /drive/files
166-
- [ ] /drive/files/attached-notes
167-
- [ ] /drive/files/check-existence
168-
- [ ] /drive/files/create
169-
- [ ] /drive/files/delete
170-
- [ ] /drive/files/find-by-hash
171-
- [ ] /drive/files/find
172-
- [ ] /drive/files/show
173-
- [ ] /drive/files/update
174-
- [ ] /drive/files/upload-from-url
175-
- [ ] /drive/folders
176-
- [ ] /drive/folders/create
177-
- [ ] /drive/folders/delete
178-
- [ ] /drive/folders/find
179-
- [ ] /drive/folders/show
180-
- [ ] /drive/folders/update
181-
- [ ] /drive/stream
182182
- [ ] /email-address/available
183183
- [ ] /endpoint
184184
- [ ] /endpoints

mipac/actions/admins/drive.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Any, Literal
4+
5+
from mipac.abstract.action import AbstractAction
6+
from mipac.http import HTTPClient, Route
7+
from mipac.models.drive import File
8+
from mipac.types.drive import IFile
9+
10+
if TYPE_CHECKING:
11+
from mipac.manager.client import ClientManager
12+
13+
14+
class AdminDriveActions(AbstractAction):
15+
def __init__(self, *, session: HTTPClient, client: ClientManager):
16+
self.__session: HTTPClient = session
17+
self.__client: ClientManager = client
18+
19+
async def clean_remote_files(self) -> bool:
20+
"""Clean remote files
21+
22+
Endpoint: `/api/admin/drive/clean-remote-files`
23+
24+
Returns
25+
-------
26+
bool
27+
Whether the remote files were cleaned
28+
"""
29+
30+
res: bool = await self.__session.request(
31+
Route("POST", "/api/admin/drive/clean-remote-files"), auth=True
32+
)
33+
return res
34+
35+
async def cleanup(self) -> bool:
36+
"""Clean up the drive
37+
38+
Endpoint: `/api/admin/drive/cleanup`
39+
40+
Returns
41+
-------
42+
bool
43+
Whether the drive was cleaned up
44+
"""
45+
46+
res: bool = await self.__session.request(
47+
Route("POST", "/api/admin/drive/cleanup"), auth=True
48+
)
49+
return res
50+
51+
async def get_files(
52+
self,
53+
limit: int = 10,
54+
since_id: str | None = None,
55+
until_id: str | None = None,
56+
user_id: str | None = None,
57+
type: str | None = None,
58+
origin: Literal["combined", "local", "remote"] = "local",
59+
hostname: str | None = None,
60+
) -> list[File]:
61+
"""Get all files
62+
63+
Endpoint: `/api/admin/drive/files`
64+
65+
Parameters
66+
----------
67+
limit: int
68+
The number of files to get
69+
since_id: str
70+
The id of the file to start from
71+
until_id: str
72+
The id of the file to end at
73+
type: str
74+
The type of file to get
75+
user_id: str
76+
The id of the user to get files from
77+
origin: Literal['combined', 'local', 'remote']
78+
The origin of the files
79+
hostname: str
80+
The hostname of the files
81+
82+
Returns
83+
-------
84+
list[File]
85+
A list of files
86+
"""
87+
88+
data = {
89+
"limit": limit,
90+
"sinceId": since_id,
91+
"untilId": until_id,
92+
"type": type,
93+
"userId": user_id,
94+
"origin": origin,
95+
"hostname": hostname,
96+
}
97+
raw_files: list[IFile] = await self.__session.request(
98+
Route("POST", "/api/admin/drive/files"), auth=True, json=data
99+
)
100+
return [File(raw_file=file, client=self.__client) for file in raw_files]
101+
102+
async def show_file(self, file_id: str, url: str | None = None):
103+
"""Show a file
104+
105+
Endpoint: `/api/admin/drive/files/show`
106+
107+
Parameters
108+
----------
109+
file_id: str
110+
The id of the file to show
111+
url: str
112+
The url of the file to show
113+
114+
Returns
115+
-------
116+
dict[str, Any]
117+
The file
118+
"""
119+
120+
data = {
121+
"fileId": file_id,
122+
"url": url,
123+
}
124+
# TODO: IFileではなく、ほぼほぼデータベースの中身が返ってくるのでそれに合わせた型とモデルを作る
125+
raw_file: dict[str, Any] = await self.__session.request(
126+
Route("POST", "/api/admin/drive/show-file"), auth=True, json=data
127+
)
128+
return raw_file

0 commit comments

Comments
 (0)