mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 19:03:56 +08:00
refactor: 优化部分代码格式
This commit is contained in:
@@ -21,6 +21,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.core.exception.BusinessException;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
@@ -33,14 +34,12 @@ import top.continew.starter.storage.model.req.StorageProperties;
|
||||
import top.continew.starter.storage.model.resp.ThumbnailResp;
|
||||
import top.continew.starter.storage.model.resp.UploadResp;
|
||||
import top.continew.starter.storage.util.ImageThumbnailUtils;
|
||||
import top.continew.starter.storage.util.LocalUtils;
|
||||
import top.continew.starter.storage.util.StorageUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Base64;
|
||||
|
||||
@@ -147,12 +146,12 @@ public class LocalStorageStrategy implements StorageStrategy<LocalClient> {
|
||||
}
|
||||
|
||||
// 构建文件 md5
|
||||
String eTag = LocalUtils.calculateMD5(inputStream);
|
||||
String eTag = DigestUtil.md5Hex(IoUtil.readBytes(inputStream));
|
||||
// 构建 上传后的文件路径地址 格式 xxx/xxx/xxx.jpg
|
||||
String filePath = Paths.get(path, formatFileName).toString();
|
||||
// 构建 文件上传记录 并返回
|
||||
return buildStorageRecord(bucketName, fileName, filePath, eTag, originalBytes.length, thumbnailResp);
|
||||
} catch (NoSuchAlgorithmException | IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("文件上传异常", e);
|
||||
}
|
||||
|
||||
|
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.storage.util;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import net.dreamlu.mica.core.utils.DigestUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* 本地存储工具
|
||||
*
|
||||
* @author echo
|
||||
* @since 2.9.0
|
||||
*/
|
||||
public class LocalUtils {
|
||||
public LocalUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算MD5
|
||||
*
|
||||
* @param inputStream 输入流
|
||||
* @return {@link String }
|
||||
* @throws NoSuchAlgorithmException 没有这样算法例外
|
||||
*/
|
||||
public static String calculateMD5(InputStream inputStream) throws NoSuchAlgorithmException {
|
||||
byte[] fileBytes = IoUtil.readBytes(inputStream);
|
||||
return DigestUtil.md5Hex(fileBytes);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user