|
|
@@ -1,11 +1,13 @@
|
|
|
package com.mokasz.pool.image.restful.controller;
|
|
|
|
|
|
+import com.mokasz.pool.image.algorithm.HashTool;
|
|
|
import com.mokasz.pool.image.algorithm.OpenCvService;
|
|
|
import com.mokasz.pool.image.restful.entity.ImageQueryResponse;
|
|
|
import com.mokasz.pool.image.restful.entity.ImageSaveResponse;
|
|
|
import com.mokasz.pool.image.restful.service.DownloadBytes;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -34,6 +36,25 @@ public class ImageController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/store/url")
|
|
|
+ @ResponseStatus(HttpStatus.CREATED)
|
|
|
+ public void storeUrl (@RequestParam(value = "url") String url) throws IOException {
|
|
|
+ byte[] fileData = DownloadBytes.downloadAsBytesArray(url);
|
|
|
+ String md5 = HashTool.calculateMd5(fileData);
|
|
|
+ float[] floats = new float[8];
|
|
|
+ service.calculatePHash(fileData, floats);
|
|
|
+ float[] binaries = new float[64];
|
|
|
+ service.transformBinaryArray(floats, binaries);
|
|
|
+ String hash = service.getReadableHash(floats);
|
|
|
+ log.info("URL: {}, MD5: {} PHash: {}", url, md5, hash);
|
|
|
+ jdbcTemplate.update(
|
|
|
+ "INSERT INTO image_pool.url_hash VALUES (?, ?, ?, ?, NOW()) ON CONFLICT (url) DO NOTHING",
|
|
|
+ url,
|
|
|
+ md5,
|
|
|
+ hash,
|
|
|
+ binaries);
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/store")
|
|
|
public ImageSaveResponse store(
|
|
|
@RequestParam(value = "file", required = false) MultipartFile file,
|