-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
file.ts
265 lines (244 loc) · 5.25 KB
/
file.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
* 文件操作
* @packageDocumentation
*/
import type { AxiosResponse } from 'axios'
import type { Api, Contact } from '..'
import type { MiraiApiHttp } from './index'
export type FileInfoResponse = AxiosResponse<
Api.Response.ResponseType<FileInfo>
>
export interface BaseFileOptions {
/**
* 文件 ID
*/
id: string
/**
* 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
*/
path?: string
/**
* 群号或好友QQ号
*/
target?: number
/**
* 群号
*/
group?: number
/**
* 好友QQ号
*/
qq?: number
}
/**
* 群文件信息
*/
export interface FileInfo {
/**
* 文件名字
*/
name: string
/**
* 文件 ID
*/
id: string
/**
* 文件对象, 递归类型. null 为存在根目录
*/
parent: FileInfo
/**
* 群信息或好友信息
*/
contact: Contact.User
/**
* 是否文件
*/
isFile: boolean
/**
* 是否文件夹
*/
isDirectory: boolean
/**
* 文件下载信息
*/
downloadInfo: {
/**
* 下载次数
*/
downloadTimes: number
/**
* 上传者QQ
*/
uploaderId: number
/**
* 上传时间
*/
uploadTime: number
/**
* 最后修改时间
*/
lastModifyTime: number
/**
* 文件 sha1 值
*/
sha1: string
/**
* 文件 md5 值
*/
md5: string
/**
* 文件下载 url
*/
url: string
}
}
export interface FileListOptions extends BaseFileOptions {
/**
* 是否携带下载信息,额外请求,无必要不要携带
*/
withDownloadInfo?: number
/**
* 分页偏移
*/
offset?: number
/**
* 分页大小
*/
size?: number
}
export type FileListResponse = AxiosResponse<
Api.Response.ResponseType<FileInfo[]>
>
export interface FileInfoOptions extends BaseFileOptions {
/**
* 是否携带下载信息,额外请求,无必要不要携带
*/
withDownloadInfo?: number
}
export type FileInfoParams = Api.Params.RequestParams<FileInfoOptions>
export interface FileMkdirOptions extends BaseFileOptions {
/**
* 新建文件夹名
*/
directoryName: string
}
export type FileMkdirParams = Api.Params.RequestParams<FileMkdirOptions>
export type FileDeleteOptions = BaseFileOptions
export type FileDeleteParams = Api.Params.RequestParams<BaseFileOptions>
export interface FileRenameOptions extends BaseFileOptions {
/**
* 新文件名
*/
renameTo?: string
}
export type FileRenameParams = Api.Params.RequestParams<FileRenameOptions>
export interface FileMoveOptions extends BaseFileOptions {
/**
* 移动目标文件夹 id
*/
moveTo?: string
/**
* 移动目标文件路径, 文件夹允许重名, 不保证准确, 准确定位使用 moveTo
*/
moveToPath?: string
}
export type FileMoveParams = Api.Params.RequestParams<FileMoveOptions>
/**
* [文件操作 | mirai-api-http](https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/API.md#%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C)
* [文件操作 Http Adapter](https://github.com/project-mirai/mirai-api-http/blob/master/docs/adapter/HttpAdapter.md#%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C)
*/
export class File {
constructor(public api: MiraiApiHttp) {}
// 群文件管理
/**
* 获取群文件列表
* @param target 指定群的群号
* @param dir 指定查询目录,不填为根目录
*/
/**
* 目前仅支持群文件的操作, 所有好友文件的字段为保留字段
* @param options
*/
async list(options: FileListOptions) {
const { data } = await this.api.axios.get<FileInfoParams, FileListResponse>(
'/file/list',
{
params: {
sessionKey: this.api.sessionKey,
...options,
},
},
)
return data
}
/**
* 获取文件信息
* @param options
*/
async info(options: FileInfoOptions) {
const { data } = await this.api.axios.get<FileInfoParams, FileInfoResponse>(
'/file/info',
{
params: {
sessionKey: this.api.sessionKey,
...options,
},
},
)
return data
}
/**
* 创建文件夹
* @param options
*/
async mkdir(options: FileMkdirOptions) {
const { data } = await this.api.axios.post<
FileMkdirParams,
FileInfoResponse
>('/file/mkdir', {
sessionKey: this.api.sessionKey,
...options,
})
return data
}
/**
* 删除文件
*/
async delete(options: FileDeleteOptions) {
const { data } = await this.api.axios.post<
FileDeleteParams,
AxiosResponse<Api.Response.BaseResponse>
>('/file/delete', {
sessionKey: this.api.sessionKey,
...options,
})
return data
}
/**
* 移动文件
* @param options
*/
async move(options: FileMoveOptions) {
const { data } = await this.api.axios.post<
FileMoveParams,
AxiosResponse<Api.Response.BaseResponse>
>('/groupFileMove', {
sessionKey: this.api.sessionKey,
...options,
})
return data
}
/**
* 重命名文件
*/
async rename(options: FileRenameOptions) {
const { data } = await this.api.axios.post<
FileRenameParams,
AxiosResponse<Api.Response.BaseResponse>
>('/groupFileRename', {
sessionKey: this.api.sessionKey,
...options,
})
return data
}
}