|
@@ -6,6 +6,7 @@ import org.ssssssss.magicapi.exception.InvalidArgumentException;
|
|
|
import org.ssssssss.magicapi.interceptor.Authorization;
|
|
|
import org.ssssssss.magicapi.model.*;
|
|
|
import org.ssssssss.magicapi.service.MagicDynamicRegistry;
|
|
|
+import org.ssssssss.magicapi.service.MagicResourceService;
|
|
|
import org.ssssssss.magicapi.utils.IoUtils;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -17,14 +18,17 @@ import java.util.function.Function;
|
|
|
|
|
|
public class MagicResourceController extends MagicController implements MagicExceptionHandler {
|
|
|
|
|
|
+ private MagicResourceService service;
|
|
|
+
|
|
|
public MagicResourceController(MagicConfiguration configuration) {
|
|
|
super(configuration);
|
|
|
+ this.service = MagicConfiguration.getMagicResourceService();
|
|
|
}
|
|
|
|
|
|
@PostMapping("/resource/folder/save")
|
|
|
@ResponseBody
|
|
|
public JsonBean<String> saveFolder(@RequestBody Group group) {
|
|
|
- if (configuration.getMagicResourceService().saveGroup(group)) {
|
|
|
+ if (service.saveGroup(group)) {
|
|
|
return new JsonBean<>(group.getId());
|
|
|
}
|
|
|
return new JsonBean<>((String) null);
|
|
@@ -33,7 +37,7 @@ public class MagicResourceController extends MagicController implements MagicExc
|
|
|
@PostMapping("/resource/delete")
|
|
|
@ResponseBody
|
|
|
public JsonBean<Boolean> delete(String id, HttpServletRequest request) {
|
|
|
- return new JsonBean<>(configuration.getMagicResourceService().delete(id));
|
|
|
+ return new JsonBean<>(service.delete(id));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/resource/file/{folder}/save")
|
|
@@ -47,7 +51,7 @@ public class MagicResourceController extends MagicController implements MagicExc
|
|
|
.orElseThrow(() -> new InvalidArgumentException(GROUP_NOT_FOUND))
|
|
|
.read(bytes);
|
|
|
isTrue(allowVisit(request, Authorization.SAVE, entity), PERMISSION_INVALID);
|
|
|
- if (configuration.getMagicResourceService().saveFile(entity)) {
|
|
|
+ if (MagicConfiguration.getMagicResourceService().saveFile(entity)) {
|
|
|
return new JsonBean<>(entity.getId());
|
|
|
}
|
|
|
return new JsonBean<>(null);
|
|
@@ -56,37 +60,37 @@ public class MagicResourceController extends MagicController implements MagicExc
|
|
|
@GetMapping("/resource/file/{id}")
|
|
|
@ResponseBody
|
|
|
public JsonBean<MagicEntity> detail(@PathVariable("id") String id, HttpServletRequest request) {
|
|
|
- MagicEntity entity = configuration.getMagicResourceService().file(id);
|
|
|
+ MagicEntity entity = MagicConfiguration.getMagicResourceService().file(id);
|
|
|
isTrue(allowVisit(request, Authorization.VIEW, entity), PERMISSION_INVALID);
|
|
|
- return new JsonBean<>(configuration.getMagicResourceService().file(id));
|
|
|
+ return new JsonBean<>(MagicConfiguration.getMagicResourceService().file(id));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/resource/move")
|
|
|
@ResponseBody
|
|
|
public JsonBean<Boolean> move(String src, String groupId) {
|
|
|
- return new JsonBean<>(configuration.getMagicResourceService().move(src, groupId));
|
|
|
+ return new JsonBean<>(service.move(src, groupId));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/resource/lock")
|
|
|
@ResponseBody
|
|
|
public JsonBean<Boolean> lock(String id, HttpServletRequest request) {
|
|
|
- MagicEntity entity = configuration.getMagicResourceService().file(id);
|
|
|
+ MagicEntity entity = service.file(id);
|
|
|
isTrue(allowVisit(request, Authorization.LOCK, entity), PERMISSION_INVALID);
|
|
|
- return new JsonBean<>(configuration.getMagicResourceService().lock(id));
|
|
|
+ return new JsonBean<>(service.lock(id));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/resource/unlock")
|
|
|
@ResponseBody
|
|
|
public JsonBean<Boolean> unlock(String id, HttpServletRequest request) {
|
|
|
- MagicEntity entity = configuration.getMagicResourceService().file(id);
|
|
|
+ MagicEntity entity = service.file(id);
|
|
|
isTrue(allowVisit(request, Authorization.UNLOCK, entity), PERMISSION_INVALID);
|
|
|
- return new JsonBean<>(configuration.getMagicResourceService().unlock(id));
|
|
|
+ return new JsonBean<>(service.unlock(id));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/resource")
|
|
|
@ResponseBody
|
|
|
public JsonBean<Map<String, TreeNode<Attributes<Object>>>> resources() {
|
|
|
- Map<String, TreeNode<Group>> tree = configuration.getMagicResourceService().tree();
|
|
|
+ Map<String, TreeNode<Group>> tree = service.tree();
|
|
|
Map<String, TreeNode<Attributes<Object>>> result = new HashMap<>();
|
|
|
tree.forEach((key, value) -> result.put(key, process(value)));
|
|
|
return new JsonBean<>(result);
|
|
@@ -97,7 +101,7 @@ public class MagicResourceController extends MagicController implements MagicExc
|
|
|
value.setNode(groupNode.getNode());
|
|
|
groupNode.getChildren().stream().map(this::process).forEach(value::addChild);
|
|
|
if (!Constants.ROOT_ID.equals(groupNode.getNode().getId())) {
|
|
|
- configuration.getMagicResourceService()
|
|
|
+ service
|
|
|
.listFiles(groupNode.getNode().getId())
|
|
|
.stream()
|
|
|
.map(MagicEntity::simple)
|
|
@@ -106,6 +110,4 @@ public class MagicResourceController extends MagicController implements MagicExc
|
|
|
}
|
|
|
return value;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|