mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
✨ 新增批量删除直链功能,修改直链 Key 功能
This commit is contained in:
@@ -9,8 +9,10 @@ import im.zhaojun.zfile.service.ShortLinkConfigService;
|
||||
import im.zhaojun.zfile.service.SystemConfigService;
|
||||
import im.zhaojun.zfile.util.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -33,10 +35,8 @@ public class ShortLinkController {
|
||||
public ResultBean shortLink(String driveId, String path) {
|
||||
SystemConfigDTO systemConfig = systemConfigService.getSystemConfig();
|
||||
String domain = systemConfig.getDomain();
|
||||
|
||||
// 拼接直链地址.
|
||||
String fullPath = StringUtils.removeDuplicateSeparator("/directlink/" + driveId + path);
|
||||
|
||||
ShortLinkConfig shortLinkConfig = shortLinkConfigService.findByUrl(fullPath);
|
||||
|
||||
if (shortLinkConfig == null) {
|
||||
@@ -71,6 +71,32 @@ public class ShortLinkController {
|
||||
|
||||
String url = URLUtil.encode(StringUtils.removeDuplicateSeparator(domain + shortLinkConfig.getUrl()));
|
||||
return "redirect:" + url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("admin/api/short-link/key")
|
||||
@ResponseBody
|
||||
public ResultBean updateShortKey(Integer id, String newKey) {
|
||||
ShortLinkConfig shortLinkConfig = shortLinkConfigService.findById(id);
|
||||
if (shortLinkConfig == null) {
|
||||
throw new RuntimeException("此直链不存在或已失效.");
|
||||
}
|
||||
|
||||
shortLinkConfig.setKey(newKey);
|
||||
shortLinkConfigService.save(shortLinkConfig);
|
||||
return ResultBean.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除直链
|
||||
*/
|
||||
@DeleteMapping("admin/api/short-link")
|
||||
@ResponseBody
|
||||
public ResultBean batchDelete(@RequestParam("id[]") Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
shortLinkConfigService.deleteById(id);
|
||||
}
|
||||
return ResultBean.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import javax.persistence.criteria.Predicate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class ShortLinkConfigService {
|
||||
@@ -27,6 +28,11 @@ public class ShortLinkConfigService {
|
||||
return shortLinkConfigRepository.findByKey(key);
|
||||
}
|
||||
|
||||
public ShortLinkConfig findById(Integer id) {
|
||||
Optional<ShortLinkConfig> shortLinkConfigOptional = shortLinkConfigRepository.findById(id);
|
||||
return shortLinkConfigOptional.orElse(null);
|
||||
}
|
||||
|
||||
public ShortLinkConfig findByUrl(String url) {
|
||||
return shortLinkConfigRepository.findByUrl(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user