feat: 主题切换 + 浅色模式适配,SFTP/批量命令/Webhook/仪表盘全面升级
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.sshmanager.controller;
|
||||
|
||||
import com.sshmanager.entity.User;
|
||||
import com.sshmanager.entity.WebhookConfig;
|
||||
import com.sshmanager.repository.UserRepository;
|
||||
import com.sshmanager.service.WebhookService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/webhooks")
|
||||
public class WebhookController {
|
||||
|
||||
private final WebhookService webhookService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public WebhookController(WebhookService webhookService, UserRepository userRepository) {
|
||||
this.webhookService = webhookService;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
private Long getCurrentUserId(Authentication auth) {
|
||||
User user = userRepository.findByUsername(auth.getName())
|
||||
.orElseThrow(() -> new IllegalStateException("User not found"));
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<WebhookConfig>> list(Authentication auth) {
|
||||
return ResponseEntity.ok(webhookService.listByUser(getCurrentUserId(auth)));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<WebhookConfig> create(@RequestBody Map<String, String> body, Authentication auth) {
|
||||
return ResponseEntity.ok(webhookService.create(
|
||||
getCurrentUserId(auth), body.get("url"), body.get("eventType")));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Map<String, String>> delete(@PathVariable Long id, Authentication auth) {
|
||||
webhookService.delete(id, getCurrentUserId(auth));
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("message", "Deleted");
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
@PostMapping("/test")
|
||||
public ResponseEntity<Map<String, String>> test(@RequestBody Map<String, String> body) {
|
||||
webhookService.fireEvent("test", "测试通知", body.getOrDefault("message", "这是一条测试消息"));
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("message", "Test event fired");
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user