|
|
@@ -41,102 +41,6 @@ public class ConsistentCheckTest {
|
|
|
FileUploadService fileUploadService;
|
|
|
@Autowired
|
|
|
ImageFileService imageFileService;
|
|
|
-
|
|
|
- HttpClient client = HttpClient.newBuilder()
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .build();
|
|
|
- @Test
|
|
|
- public void test() {
|
|
|
- List<String> urls = new ArrayList<>();
|
|
|
- for (String url : urls) {
|
|
|
- try {
|
|
|
- HttpRequest.Builder builder = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(url))
|
|
|
- .timeout(Duration.ofSeconds(30))
|
|
|
- .GET();
|
|
|
- HttpResponse<InputStream> streamBody = client.send(builder.build(), HttpResponse.BodyHandlers.ofInputStream());
|
|
|
- if (streamBody.statusCode() != 200) {
|
|
|
- log.error("{} 获取失败", url);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- byte[] imageBytes = getBytes(streamBody.body());
|
|
|
- String filename = UrlFormatter.getFilename(url);
|
|
|
- long size = imageBytes.length;
|
|
|
- String contentType = "image/jpeg";
|
|
|
-
|
|
|
- ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
|
|
|
- UploadingFile uploadingFile = new UploadingFile(filename, size, contentType, inputStream);
|
|
|
- UploadedFile uploadedFile = fileUploadService.put(uploadingFile);
|
|
|
-
|
|
|
- /*ImageFileRet imageFileRet = imageFileService.process(uploadedFile);
|
|
|
- String imageFileId = imageFileRet.getImageFileId();
|
|
|
- String url1 = imageFileRet.getThumbnailUrl();*/
|
|
|
- //saveFile(inputStream, new File(String.format("/home/reghao/Downloads/0/%s", filename)));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void saveFile(InputStream in, File file) throws IOException {
|
|
|
- File parentDir = file.getParentFile();
|
|
|
- if (!parentDir.exists()) {
|
|
|
- FileUtils.forceMkdir(parentDir);
|
|
|
- }
|
|
|
-
|
|
|
- FileOutputStream fos = new FileOutputStream(file);
|
|
|
- // 1MiB
|
|
|
- int len = 1024*1024;
|
|
|
- byte[] buf = new byte[len];
|
|
|
- int readLen;
|
|
|
- while ((readLen = in.read(buf, 0, len)) != -1) {
|
|
|
- fos.write(buf, 0, readLen);
|
|
|
- }
|
|
|
- fos.close();
|
|
|
- }
|
|
|
-
|
|
|
- private byte[] getBytes(InputStream in) throws IOException {
|
|
|
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
- // 1MiB
|
|
|
- int len = 1024*1024;
|
|
|
- byte[] buf = new byte[len];
|
|
|
- int readLen;
|
|
|
- while ((readLen = in.read(buf, 0, len)) != -1) {
|
|
|
- baos.write(buf, 0, readLen);
|
|
|
- }
|
|
|
- baos.close();
|
|
|
- in.close();
|
|
|
- return baos.toByteArray();
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void saveLocalVideoFile() throws Exception {
|
|
|
- String videoFileId = "wOdK71938E";
|
|
|
- String filePath = "/home/reghao/Downloads/mp4/0/video_720.mp4";
|
|
|
- saveVideoFile(videoFileId, filePath);
|
|
|
- }
|
|
|
-
|
|
|
- private void saveVideoFile(String videoFileId, String filePath) throws Exception {
|
|
|
- File file = new File(filePath);
|
|
|
-
|
|
|
- String filename = file.getName();
|
|
|
- long size = file.length();
|
|
|
- String contentType = "video/mp4";
|
|
|
- InputStream inputStream = new FileInputStream(file);
|
|
|
-
|
|
|
- UploadingFile uploadingFile = new UploadingFile(filename, size, contentType, inputStream);
|
|
|
- UploadedFile fileRet = fileUploadService.put(uploadingFile);
|
|
|
-
|
|
|
- String fileId = fileRet.getFileId();
|
|
|
- int width = 1280;
|
|
|
- int height = 720;
|
|
|
- MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
|
|
|
- VideoUrl videoUrl = new VideoUrl(videoFileId, fileId, VideoUrlType.mp4.getName(),
|
|
|
- width, height, mediaResolution.getQuality());
|
|
|
- videoUrlMapper.save(videoUrl);
|
|
|
- }
|
|
|
-
|
|
|
@Autowired
|
|
|
FileInfoMapper fileInfoMapper;
|
|
|
@Autowired
|
|
|
@@ -146,76 +50,7 @@ public class ConsistentCheckTest {
|
|
|
@Autowired
|
|
|
VideoUrlMapper videoUrlMapper;
|
|
|
|
|
|
- /**
|
|
|
- * 检查 FileInfo 和 FileUrl 的一致性
|
|
|
- * FileInfo 和 FileUrl 是 one-to-many 关系
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @date 2022-08-14 下午2:30
|
|
|
- */
|
|
|
- @Test
|
|
|
- public void fileTest() {
|
|
|
- int i = 0;
|
|
|
- List<FileInfo> list = fileInfoMapper.findAll();
|
|
|
- for (FileInfo fileInfo : list) {
|
|
|
- String fileId = fileInfo.getFileId();
|
|
|
- List<FileUrl> fileUrls = fileUrlMapper.findByFileId(fileId);
|
|
|
- if (fileUrls.size() == 0) {
|
|
|
- log.error("{} 没有 FileUrl", fileId);
|
|
|
- } else if (fileUrls.size() > 1) {
|
|
|
- log.error("{} 有 {} 个 FileUrl", fileId, fileUrls.size());
|
|
|
- }
|
|
|
-
|
|
|
- log.info("{}", i++);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void videoFileTest() {
|
|
|
- int i = 0;
|
|
|
- List<FileUrl> list = fileUrlMapper.findAllVideoUrl();
|
|
|
- for (FileUrl fileUrl : list) {
|
|
|
- String fileId = fileUrl.getFileId();
|
|
|
-
|
|
|
- VideoUrl videoUrl = videoUrlMapper.findByFileId(fileId);
|
|
|
- if (videoUrl != null) {
|
|
|
- String videoFileId = videoUrl.getVideoFileId();
|
|
|
- videoUrlMapper.updateSetUrl(fileId, fileUrl.getUrl());
|
|
|
-
|
|
|
- VideoFile videoFile = videoFileMapper.findByVideoFileId(videoFileId);
|
|
|
- if (videoFile == null) {
|
|
|
- log.error("{} 没有 VideoFile", fileId);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.error("{} 没有 VideoUrl", fileId);
|
|
|
- }
|
|
|
-
|
|
|
- log.info("{}", i++);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- IdGenerator idGenerator = new IdGenerator("image-file-id");
|
|
|
@Test
|
|
|
- public void imageFileTest() {
|
|
|
- int i = 0;
|
|
|
- List<FileUrl> list = fileUrlMapper.findAllImageUrl();
|
|
|
- for (FileUrl fileUrl : list) {
|
|
|
- String fileId = fileUrl.getFileId();
|
|
|
- log.error("{} 没有 ImageUrl", fileId);
|
|
|
- log.info("{}", i++);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void videoFileTest1() {
|
|
|
- int i = 0;
|
|
|
-
|
|
|
- List<VideoFile> videoFiles = videoFileMapper.findAll();
|
|
|
- for (VideoFile videoFile : videoFiles) {
|
|
|
- String coverUrl = videoFile.getCoverUrl();
|
|
|
- log.error("{} 没有 ImageUrl", videoFile.getVideoFileId());
|
|
|
- //log.info("{}", i++);
|
|
|
- }
|
|
|
+ public void test() {
|
|
|
}
|
|
|
}
|