-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
23 deletions.
There are no files selected for viewing
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); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.