Skip to content

Commit

Permalink
chore: optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed May 31, 2024
1 parent 1c3e356 commit 917f5c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
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);
}
}
}
23 changes: 0 additions & 23 deletions src/main/java/com/jmal/clouddisk/ocr/OcrController.java

This file was deleted.

0 comments on commit 917f5c0

Please sign in to comment.