Compare commits

...

5 Commits

Author SHA1 Message Date
Boom 16d456130d 🔥 init 2 months ago
Naccl 755fa6ae52 fix 2 years ago
Naccl 237b379a08 Merge branch 'remote' 2 years ago
Naccl Lu 20612d0945
Update README.md 2 years ago
Naccl 3b71b59f38 refactor: cdn.jsdelivr.net -> local 3 years ago
  1. 6
      README.md
  2. 10
      src/main/java/top/naccl/dwz/controller/IndexController.java
  3. 18
      src/main/java/top/naccl/dwz/entity/GenerateCmd.java
  4. 12
      src/main/resources/application-dev.properties
  5. 7
      src/main/resources/static/js/clipboard.min.js
  6. 2
      src/main/resources/static/js/jquery.min.js
  7. 36
      src/main/resources/templates/index.html

6
README.md

@ -34,9 +34,3 @@ Redis:生成短链接后,通常在后续一段时间内此短链接的使用
本在线网站只用于项目展示,随时可能关闭,并不保证绝对的可用性,切勿用于商业用途或非法传播,因此产生的任何纠纷与本人无关。
被刷数据也快习惯了,几千条也就算了,这次的 80 万条是在帮我做压测吗😅
如果是的话,请把结果在 Issues 里分享一下,否则可能会变得不幸,甚至会变成猫猫🐱

10
src/main/java/top/naccl/dwz/controller/IndexController.java

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

18
src/main/java/top/naccl/dwz/entity/GenerateCmd.java

@ -0,0 +1,18 @@
package top.naccl.dwz.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Naccl
* @date 2023-07-16
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GenerateCmd {
private String longURL;
}

12
src/main/resources/application-dev.properties

@ -1,15 +1,15 @@
server.port=8060
server.host=http://localhost:8060/
server.host=http://localhost1:8060/
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/dwz?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.url=jdbc:mysql://192.168.10.200:3306/dwz?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
spring.redis.host=192.168.17.132
spring.redis.password=123456
spring.redis.host=192.168.10.200
spring.redis.password=
spring.redis.port=6379
spring.redis.database=1
spring.redis.database=15
spring.redis.timeout=10000ms
mybatis.mapper-locations=classpath:mapper/*.xml
@ -17,4 +17,4 @@ mybatis.configuration.map-underscore-to-camel-case=true
logging.level.root=info
logging.level.top.naccl.dwz=debug
logging.file.name=./log/dwz
logging.file.name=./log/dwz

7
src/main/resources/static/js/clipboard.min.js vendored

File diff suppressed because one or more lines are too long

2
src/main/resources/static/js/jquery.min.js vendored

File diff suppressed because one or more lines are too long

36
src/main/resources/templates/index.html

@ -23,23 +23,31 @@
<button type="button" id="copy" style="width:100px;" data-clipboard-action="copy" data-clipboard-target="#short">Copy</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/clipboard.min.js"></script>
<script>
$('#generate').click(() => {
let longURL = $('#long').val();
if (longURL) {
$.post("/generate", {
longURL
}, function (res) {
if (res.code === 200) {
$('#short').val(res.data);
} else {
alert(res.msg);
}
}, "json").fail(() => {
alert('异常错误');
});
$.ajax({
url: "/generate",
type: "POST",
contentType: "application/json",
data: JSON.stringify({
longURL: longURL
}),
dataType: "json",
success: function (res) {
if (res.code === 200) {
$('#short').val(res.data);
} else {
alert(res.msg);
}
},
error: function () {
alert('异常错误');
}
});
} else {
alert('请输入原始链接');
}
@ -54,4 +62,4 @@
});
</script>
</body>
</html>
</html>

Loading…
Cancel
Save