1414import com .zhazhapan .util .Checker ;
1515import com .zhazhapan .util .FileExecutor ;
1616import 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 ;
1721import org .springframework .beans .factory .annotation .Autowired ;
1822import org .springframework .web .bind .annotation .*;
1923import org .springframework .web .multipart .MultipartFile ;
2933 */
3034@ RestController
3135@ RequestMapping ("/file" )
36+ @ Api (value = "/file" , description = "文件相关操作" )
3237public class FileController {
3338
3439 private final IFileService fileService ;
@@ -44,20 +49,30 @@ public FileController(IFileService fileService, HttpServletRequest request, JSON
4449 this .jsonObject = jsonObject ;
4550 }
4651
52+ @ ApiOperation (value = "获取我的下载记录" )
53+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "offset" , value = "偏移量" , required = true ), @ ApiImplicitParam (name =
54+ "search" , value = "记录匹配(允许为空)" )})
4755 @ AuthInterceptor (InterceptorLevel .USER )
4856 @ RequestMapping (value = "/user/downloaded" , method = RequestMethod .GET )
4957 public String getUserDownloaded (int offset , String search ) {
5058 User user = (User ) request .getSession ().getAttribute (ValueConsts .USER_STRING );
5159 return Formatter .listToJson (fileService .getUserDownloaded (user .getId (), offset , search ));
5260 }
5361
62+ @ ApiOperation (value = "获取我的上传记录" )
63+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "offset" , value = "偏移量" , required = true ), @ ApiImplicitParam (name =
64+ "search" , value = "记录匹配(允许为空)" )})
5465 @ AuthInterceptor (InterceptorLevel .USER )
5566 @ RequestMapping (value = "/user/uploaded" , method = RequestMethod .GET )
5667 public String getUserUploaded (int offset , String search ) {
5768 User user = (User ) request .getSession ().getAttribute (ValueConsts .USER_STRING );
5869 return Formatter .listToJson (fileService .getUserUploaded (user .getId (), offset , search ));
5970 }
6071
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 = "文件前缀(仅适用于管理员上传文件,普通用户无效)" )})
6176 @ AuthInterceptor (InterceptorLevel .USER )
6277 @ RequestMapping (value = "" , method = RequestMethod .POST )
6378 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
6782 user ));
6883 }
6984
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 = "记录匹配(允许为空)" )})
7089 @ AuthInterceptor (InterceptorLevel .NONE )
7190 @ RequestMapping (value = "/all" , method = RequestMethod .GET )
7291 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)
82101 }
83102 }
84103
104+ @ ApiOperation (value = "删除指定文件" )
85105 @ AuthInterceptor (InterceptorLevel .USER )
86106 @ RequestMapping (value = "/{id}" , method = RequestMethod .DELETE )
87107 public String removeFile (@ PathVariable ("id" ) long id ) {
@@ -99,6 +119,10 @@ public String removeFile(@PathVariable("id") long id) {
99119 return jsonObject .toString ();
100120 }
101121
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 )})
102126 @ AuthInterceptor (InterceptorLevel .USER )
103127 @ RequestMapping (value = "/{id}" , method = RequestMethod .PUT )
104128 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
113137 return jsonObject .toString ();
114138 }
115139
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 )})
116144 @ AuthInterceptor (InterceptorLevel .ADMIN )
117145 @ RequestMapping (value = "/basic/all" , method = RequestMethod .GET )
118146 public String getBasicAll (String user , String file , String category , int offset ) {
119147 return Formatter .listToJson (fileService .getBasicAll (user , file , category , offset ));
120148 }
121149
150+ @ ApiOperation (value = "通过文件路径获取服务器端的文件" )
151+ @ ApiImplicitParam (name = "path" , value = "文件路径(默认根目录)" )
122152 @ AuthInterceptor (InterceptorLevel .ADMIN )
123153 @ RequestMapping (value = "/server" , method = RequestMethod .GET )
124154 public String getServerFilesByPath (String path ) {
@@ -132,13 +162,19 @@ public String getServerFilesByPath(String path) {
132162 return array .toJSONString ();
133163 }
134164
165+ @ ApiOperation ("分享服务器端文件" )
166+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "prefix" , value = "自定义前缀(可空)" ), @ ApiImplicitParam (name = "files" ,
167+ value = "文件" , required = true , example = "file1,file2,file3" )})
135168 @ AuthInterceptor (InterceptorLevel .ADMIN )
136169 @ RequestMapping (value = "/server/share" , method = RequestMethod .POST )
137170 public String shareFile (String prefix , String files ) {
138171 User user = (User ) request .getSession ().getAttribute (ValueConsts .USER_STRING );
139172 return ControllerUtils .getResponse (fileService .shareFiles (Checker .checkNull (prefix ), files , user ));
140173 }
141174
175+ @ ApiOperation (value = "更新文件路径(包括本地路径,访问路径,如果新的本地路径和访问路径均为空,这什么也不会做)" )
176+ @ ApiImplicitParams ({@ ApiImplicitParam (name = "oldLocalUrl" , value = "文件本地路径" , required = true ), @ ApiImplicitParam
177+ (name = "localUrl" , value = "新的本地路径(可空)" ), @ ApiImplicitParam (name = "visitUrl" , value = "新的访问路径(可空)" )})
142178 @ AuthInterceptor (InterceptorLevel .ADMIN )
143179 @ RequestMapping (value = "/{id}/url" , method = RequestMethod .PUT )
144180 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
147183 return Formatter .formatJson (responseJson );
148184 }
149185
186+ @ ApiOperation (value = "批量删除文件" )
150187 @ AuthInterceptor (InterceptorLevel .ADMIN )
151188 @ RequestMapping (value = "/batch/{ids}" , method = RequestMethod .DELETE )
152189 public String deleteFiles (@ PathVariable ("ids" ) String ids ) {
153190 return ControllerUtils .getResponse (fileService .deleteFiles (ids ));
154191 }
155192
193+ @ ApiOperation (value = "获取指定文件的权限记录" )
156194 @ AuthInterceptor (InterceptorLevel .ADMIN )
157195 @ RequestMapping (value = "/{id}/auth" , method = RequestMethod .GET )
158196 public String getAuth (@ PathVariable ("id" ) long id ) {
159197 return BeanUtils .toPrettyJson (fileService .getAuth (id ));
160198 }
161199
200+ @ ApiOperation (value = "更新指定文件的权限" )
201+ @ ApiImplicitParam (name = "auth" , value = "权限" , required = true , example = "1,1,1,1" )
162202 @ AuthInterceptor (InterceptorLevel .ADMIN )
163203 @ RequestMapping (value = "/{id}/auth" , method = RequestMethod .PUT )
164204 public String updateAuth (@ PathVariable ("id" ) long id , String auth ) {
@@ -170,6 +210,7 @@ public String updateAuth(@PathVariable("id") long id, String auth) {
170210 *
171211 * @param response {@link HttpServletResponse}
172212 */
213+ @ ApiOperation (value = "通过访问路径获取文件资源" )
173214 @ AuthInterceptor (InterceptorLevel .NONE )
174215 @ RequestMapping (value = "/**" , method = RequestMethod .GET )
175216 public void getResource (HttpServletResponse response ) throws IOException {
0 commit comments