14
14
import com .zhazhapan .util .Checker ;
15
15
import com .zhazhapan .util .FileExecutor ;
16
16
import com .zhazhapan .util .Formatter ;
17
+ import io .swagger .annotations .Api ;
18
+ import io .swagger .annotations .ApiImplicitParam ;
19
+ import io .swagger .annotations .ApiImplicitParams ;
20
+ import io .swagger .annotations .ApiOperation ;
17
21
import org .springframework .beans .factory .annotation .Autowired ;
18
22
import org .springframework .web .bind .annotation .*;
19
23
import org .springframework .web .multipart .MultipartFile ;
29
33
*/
30
34
@ RestController
31
35
@ RequestMapping ("/file" )
36
+ @ Api (value = "/file" , description = "文件相关操作" )
32
37
public class FileController {
33
38
34
39
private final IFileService fileService ;
@@ -44,20 +49,30 @@ public FileController(IFileService fileService, HttpServletRequest request, JSON
44
49
this .jsonObject = jsonObject ;
45
50
}
46
51
52
+ @ ApiOperation (value = "获取我的下载记录" )
53
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "offset" , value = "偏移量" , required = true ), @ ApiImplicitParam (name =
54
+ "search" , value = "记录匹配(允许为空)" )})
47
55
@ AuthInterceptor (InterceptorLevel .USER )
48
56
@ RequestMapping (value = "/user/downloaded" , method = RequestMethod .GET )
49
57
public String getUserDownloaded (int offset , String search ) {
50
58
User user = (User ) request .getSession ().getAttribute (ValueConsts .USER_STRING );
51
59
return Formatter .listToJson (fileService .getUserDownloaded (user .getId (), offset , search ));
52
60
}
53
61
62
+ @ ApiOperation (value = "获取我的上传记录" )
63
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "offset" , value = "偏移量" , required = true ), @ ApiImplicitParam (name =
64
+ "search" , value = "记录匹配(允许为空)" )})
54
65
@ AuthInterceptor (InterceptorLevel .USER )
55
66
@ RequestMapping (value = "/user/uploaded" , method = RequestMethod .GET )
56
67
public String getUserUploaded (int offset , String search ) {
57
68
User user = (User ) request .getSession ().getAttribute (ValueConsts .USER_STRING );
58
69
return Formatter .listToJson (fileService .getUserUploaded (user .getId (), offset , search ));
59
70
}
60
71
72
+ @ ApiOperation (value = "文件上传" )
73
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "categoryId" , value = "分类ID" , required = true ), @ ApiImplicitParam
74
+ (name = "tag" , value = "文件标签" ), @ ApiImplicitParam (name = "description" , value = "文件描述" ),
75
+ @ ApiImplicitParam (name = "prefix" , value = "文件前缀(仅适用于管理员上传文件,普通用户无效)" )})
61
76
@ AuthInterceptor (InterceptorLevel .USER )
62
77
@ RequestMapping (value = "" , method = RequestMethod .POST )
63
78
public String upload (int categoryId , String tag , String description , String prefix , @ RequestParam ("file" )
@@ -67,6 +82,10 @@ public String upload(int categoryId, String tag, String description, String pref
67
82
user ));
68
83
}
69
84
85
+ @ ApiOperation (value = "获取文件记录" )
86
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "offset" , value = "偏移量" , required = true ), @ ApiImplicitParam (name =
87
+ "categoryId" , value = "分类ID" , required = true ), @ ApiImplicitParam (name = "orderBy" , value = "排序方式" ,
88
+ required = true , example = "id desc" ), @ ApiImplicitParam (name = "search" , value = "记录匹配(允许为空)" )})
70
89
@ AuthInterceptor (InterceptorLevel .NONE )
71
90
@ RequestMapping (value = "/all" , method = RequestMethod .GET )
72
91
public String getAll (int offset , int categoryId , String orderBy , String search ) {
@@ -82,6 +101,7 @@ public String getAll(int offset, int categoryId, String orderBy, String search)
82
101
}
83
102
}
84
103
104
+ @ ApiOperation (value = "删除指定文件" )
85
105
@ AuthInterceptor (InterceptorLevel .USER )
86
106
@ RequestMapping (value = "/{id}" , method = RequestMethod .DELETE )
87
107
public String removeFile (@ PathVariable ("id" ) long id ) {
@@ -99,6 +119,10 @@ public String removeFile(@PathVariable("id") long id) {
99
119
return jsonObject .toString ();
100
120
}
101
121
122
+ @ ApiOperation (value = "更新文件属性" )
123
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "name" , value = "文件名" , required = true ), @ ApiImplicitParam (name =
124
+ "category" , value = "分类名称" , required = true ), @ ApiImplicitParam (name = "tag" , value = "文件标签" , required =
125
+ true ), @ ApiImplicitParam (name = "description" , value = "文件描述" , required = true )})
102
126
@ AuthInterceptor (InterceptorLevel .USER )
103
127
@ RequestMapping (value = "/{id}" , method = RequestMethod .PUT )
104
128
public String updateFileInfo (@ PathVariable ("id" ) long id , String name , String category , String tag , String
@@ -113,12 +137,18 @@ public String updateFileInfo(@PathVariable("id") long id, String name, String ca
113
137
return jsonObject .toString ();
114
138
}
115
139
140
+ @ ApiOperation (value = "获取所有文件的基本信息" )
141
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "user" , value = "指定用户(默认所有用户)" ), @ ApiImplicitParam (name = "file" ,
142
+ value = "指定文件(默认所有文件)" ), @ ApiImplicitParam (name = "category" , value = "指定分类(默认所有分类)" ), @ ApiImplicitParam
143
+ (name = "offset" , value = "偏移量" , required = true )})
116
144
@ AuthInterceptor (InterceptorLevel .ADMIN )
117
145
@ RequestMapping (value = "/basic/all" , method = RequestMethod .GET )
118
146
public String getBasicAll (String user , String file , String category , int offset ) {
119
147
return Formatter .listToJson (fileService .getBasicAll (user , file , category , offset ));
120
148
}
121
149
150
+ @ ApiOperation (value = "通过文件路径获取服务器端的文件" )
151
+ @ ApiImplicitParam (name = "path" , value = "文件路径(默认根目录)" )
122
152
@ AuthInterceptor (InterceptorLevel .ADMIN )
123
153
@ RequestMapping (value = "/server" , method = RequestMethod .GET )
124
154
public String getServerFilesByPath (String path ) {
@@ -132,13 +162,19 @@ public String getServerFilesByPath(String path) {
132
162
return array .toJSONString ();
133
163
}
134
164
165
+ @ ApiOperation ("分享服务器端文件" )
166
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "prefix" , value = "自定义前缀(可空)" ), @ ApiImplicitParam (name = "files" ,
167
+ value = "文件" , required = true , example = "file1,file2,file3" )})
135
168
@ AuthInterceptor (InterceptorLevel .ADMIN )
136
169
@ RequestMapping (value = "/server/share" , method = RequestMethod .POST )
137
170
public String shareFile (String prefix , String files ) {
138
171
User user = (User ) request .getSession ().getAttribute (ValueConsts .USER_STRING );
139
172
return ControllerUtils .getResponse (fileService .shareFiles (Checker .checkNull (prefix ), files , user ));
140
173
}
141
174
175
+ @ ApiOperation (value = "更新文件路径(包括本地路径,访问路径,如果新的本地路径和访问路径均为空,这什么也不会做)" )
176
+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "oldLocalUrl" , value = "文件本地路径" , required = true ), @ ApiImplicitParam
177
+ (name = "localUrl" , value = "新的本地路径(可空)" ), @ ApiImplicitParam (name = "visitUrl" , value = "新的访问路径(可空)" )})
142
178
@ AuthInterceptor (InterceptorLevel .ADMIN )
143
179
@ RequestMapping (value = "/{id}/url" , method = RequestMethod .PUT )
144
180
public String uploadFileUrl (@ PathVariable ("id" ) int id , String oldLocalUrl , String localUrl , String visitUrl ) {
@@ -147,18 +183,22 @@ public String uploadFileUrl(@PathVariable("id") int id, String oldLocalUrl, Stri
147
183
return Formatter .formatJson (responseJson );
148
184
}
149
185
186
+ @ ApiOperation (value = "批量删除文件" )
150
187
@ AuthInterceptor (InterceptorLevel .ADMIN )
151
188
@ RequestMapping (value = "/batch/{ids}" , method = RequestMethod .DELETE )
152
189
public String deleteFiles (@ PathVariable ("ids" ) String ids ) {
153
190
return ControllerUtils .getResponse (fileService .deleteFiles (ids ));
154
191
}
155
192
193
+ @ ApiOperation (value = "获取指定文件的权限记录" )
156
194
@ AuthInterceptor (InterceptorLevel .ADMIN )
157
195
@ RequestMapping (value = "/{id}/auth" , method = RequestMethod .GET )
158
196
public String getAuth (@ PathVariable ("id" ) long id ) {
159
197
return BeanUtils .toPrettyJson (fileService .getAuth (id ));
160
198
}
161
199
200
+ @ ApiOperation (value = "更新指定文件的权限" )
201
+ @ ApiImplicitParam (name = "auth" , value = "权限" , required = true , example = "1,1,1,1" )
162
202
@ AuthInterceptor (InterceptorLevel .ADMIN )
163
203
@ RequestMapping (value = "/{id}/auth" , method = RequestMethod .PUT )
164
204
public String updateAuth (@ PathVariable ("id" ) long id , String auth ) {
@@ -170,6 +210,7 @@ public String updateAuth(@PathVariable("id") long id, String auth) {
170
210
*
171
211
* @param response {@link HttpServletResponse}
172
212
*/
213
+ @ ApiOperation (value = "通过访问路径获取文件资源" )
173
214
@ AuthInterceptor (InterceptorLevel .NONE )
174
215
@ RequestMapping (value = "/**" , method = RequestMethod .GET )
175
216
public void getResource (HttpServletResponse response ) throws IOException {
0 commit comments