|
|
@ -6,9 +6,10 @@ import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import top.naccl.dwz.annotation.AccessLimit; |
|
|
|
import top.naccl.dwz.annotation.AccessLimit; |
|
|
|
|
|
|
|
import top.naccl.dwz.entity.GenerateCmd; |
|
|
|
import top.naccl.dwz.entity.R; |
|
|
|
import top.naccl.dwz.entity.R; |
|
|
|
import top.naccl.dwz.service.UrlService; |
|
|
|
import top.naccl.dwz.service.UrlService; |
|
|
|
import top.naccl.dwz.util.HashUtils; |
|
|
|
import top.naccl.dwz.util.HashUtils; |
|
|
@ -27,7 +28,7 @@ public class IndexController { |
|
|
|
|
|
|
|
|
|
|
|
@Value("${server.host}") |
|
|
|
@Value("${server.host}") |
|
|
|
public void setHost(String host) { |
|
|
|
public void setHost(String host) { |
|
|
|
this.host = host; |
|
|
|
IndexController.host = host; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/") |
|
|
|
@GetMapping("/") |
|
|
@ -38,7 +39,8 @@ public class IndexController { |
|
|
|
@AccessLimit(seconds = 10, maxCount = 1, msg = "10秒内只能生成一次短链接") |
|
|
|
@AccessLimit(seconds = 10, maxCount = 1, msg = "10秒内只能生成一次短链接") |
|
|
|
@PostMapping("/generate") |
|
|
|
@PostMapping("/generate") |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public R generateShortURL(@RequestParam String longURL) { |
|
|
|
public R generateShortURL(@RequestBody GenerateCmd cmd) { |
|
|
|
|
|
|
|
String longURL = cmd.getLongURL(); |
|
|
|
if (UrlUtils.checkURL(longURL)) { |
|
|
|
if (UrlUtils.checkURL(longURL)) { |
|
|
|
if (!longURL.startsWith("http")) { |
|
|
|
if (!longURL.startsWith("http")) { |
|
|
|
longURL = "http://" + longURL; |
|
|
|
longURL = "http://" + longURL; |
|
|
|