-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from jamebal/ocr
feat: 添加OCR支持
- Loading branch information
Showing
30 changed files
with
580 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/com/jmal/clouddisk/controller/rest/CloudSettingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.jmal.clouddisk.controller.rest; | ||
|
||
import com.jmal.clouddisk.annotation.LogOperatingFun; | ||
import com.jmal.clouddisk.annotation.Permission; | ||
import com.jmal.clouddisk.model.LdapConfigDTO; | ||
import com.jmal.clouddisk.model.LogOperation; | ||
import com.jmal.clouddisk.service.IAuthService; | ||
import com.jmal.clouddisk.service.IUserService; | ||
import com.jmal.clouddisk.service.impl.SettingService; | ||
import com.jmal.clouddisk.util.ResponseResult; | ||
import com.jmal.clouddisk.util.ResultUtil; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@Tag(name = "网盘设置") | ||
@RequiredArgsConstructor | ||
public class CloudSettingController { | ||
|
||
private final SettingService settingService; | ||
|
||
private final IUserService userService; | ||
|
||
private final IAuthService authService; | ||
|
||
@Operation(summary = "重建索引") | ||
@GetMapping("/user/setting/sync") | ||
@Permission(value = "cloud:set:sync") | ||
@LogOperatingFun | ||
public ResponseResult<Object> sync() { | ||
return settingService.sync(null); | ||
} | ||
|
||
@Operation(summary = "上传网盘logo") | ||
@PostMapping("/user/setting/upload_logo") | ||
@Permission(value = "cloud:set:sync") | ||
@LogOperatingFun | ||
public ResponseResult<Object> uploadLogo(MultipartFile file) { | ||
return settingService.uploadLogo(file); | ||
} | ||
|
||
@Operation(summary = "修改网盘名称") | ||
@PutMapping("/user/setting/update_netdisk_name") | ||
@Permission(value = "cloud:set:sync") | ||
@LogOperatingFun | ||
public ResponseResult<Object> updateNetdiskName(@RequestParam String netdiskName) { | ||
return settingService.updateNetdiskName(netdiskName); | ||
} | ||
|
||
@Operation(summary = "是否正在同步") | ||
@GetMapping("/user/setting/isSync") | ||
@LogOperatingFun | ||
public ResponseResult<Object> isSync(@RequestParam String username) { | ||
return settingService.isSync(username); | ||
} | ||
|
||
@Operation(summary = "重置角色菜单") | ||
@PutMapping("/user/setting/resetMenuAndRole") | ||
@Permission(onlyCreator = true) | ||
@LogOperatingFun | ||
public ResponseResult<Object> resetMenuAndRole() { | ||
settingService.resetMenuAndRole(); | ||
return ResultUtil.success(); | ||
} | ||
|
||
@Operation(summary = "获取是否禁用webp状态") | ||
@GetMapping("/user/setting/get/webp") | ||
@Permission("sys:user:list") | ||
@LogOperatingFun(logType = LogOperation.Type.BROWSE) | ||
public ResponseResult<Boolean> getDisabledWebp(@RequestParam String userId) { | ||
return ResultUtil.success(userService.getDisabledWebp(userId)); | ||
} | ||
|
||
@Operation(summary = "是否禁用webp(默认开启)") | ||
@PutMapping("/user/setting/disabled/webp") | ||
@Permission("sys:user:update") | ||
@LogOperatingFun | ||
public ResponseResult<Object> disabledWebp(@RequestParam String userId, @RequestParam Boolean disabled) { | ||
userService.disabledWebp(userId, disabled); | ||
return ResultUtil.success(); | ||
} | ||
|
||
@Operation(summary = "加载ldap配置") | ||
@LogOperatingFun(logType = LogOperation.Type.LOGIN) | ||
@GetMapping("/ldap/config") | ||
public ResponseResult<Object> loadLdapConfig() { | ||
return ResultUtil.success(authService.loadLdapConfig()); | ||
} | ||
|
||
@Operation(summary = "ldap配置") | ||
@LogOperatingFun(logType = LogOperation.Type.LOGIN) | ||
@PutMapping("/ldap/config") | ||
public ResponseResult<Object> updateLdapConfig(@RequestBody LdapConfigDTO ldapConfigDTO) { | ||
return authService.updateLdapConfig(ldapConfigDTO); | ||
} | ||
|
||
@Operation(summary = "测试ldap配置") | ||
@LogOperatingFun(logType = LogOperation.Type.BROWSE) | ||
@PutMapping("/ldap/test-config") | ||
public ResponseResult<Object> testLdapConfig(@RequestBody LdapConfigDTO ldapConfigDTO) { | ||
authService.testLdapConfig(ldapConfigDTO); | ||
return ResultUtil.success(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/jmal/clouddisk/controller/rest/OcrController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.jmal.clouddisk.controller.rest; | ||
|
||
import cn.hutool.core.date.TimeInterval; | ||
import cn.hutool.core.io.FileUtil; | ||
import cn.hutool.http.HttpUtil; | ||
import com.jmal.clouddisk.ocr.OcrService; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Tag(name = "OCR") | ||
@Slf4j | ||
public class OcrController { | ||
|
||
private final OcrService ocrService; | ||
|
||
@GetMapping("/ocr") | ||
public String performOcr(@RequestParam String fileUrl) { | ||
String tempImagePath = ocrService.generateOrcTempImagePath(); | ||
try { | ||
HttpUtil.downloadFile(fileUrl, tempImagePath); | ||
TimeInterval timeInterval = new TimeInterval(); | ||
timeInterval.start(); | ||
String str = ocrService.doOCR(tempImagePath, null); | ||
log.info("OCR time consuming: {}", timeInterval.intervalMs()); | ||
return str; | ||
} finally { | ||
// 删除临时文件 | ||
FileUtil.del(tempImagePath); | ||
} | ||
} | ||
} |
Oops, something went wrong.