yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.qianwen.core.boot.file;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.qianwen.core.boot.props.BladeFileProperties;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.ImageUtil;
import com.qianwen.core.tool.utils.SpringUtil;
 
/* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/file/LocalFileProxyFactory.class */
public class LocalFileProxyFactory implements IFileProxy {
    private static BladeFileProperties fileProperties;
 
    private static BladeFileProperties getBladeFileProperties() {
        if (fileProperties == null) {
            fileProperties = (BladeFileProperties) SpringUtil.getBean(BladeFileProperties.class);
        }
        return fileProperties;
    }
 
    @Override // com.qianwen.core.boot.file.IFileProxy
    public File rename(File f, String path) {
        File dest = new File(path);
        f.renameTo(dest);
        return dest;
    }
 
    @Override // com.qianwen.core.boot.file.IFileProxy
    public String[] path(File f, String dir) {
        long time = System.nanoTime();
        StringBuilder uploadPath = new StringBuilder().append(getFileDir(dir, getBladeFileProperties().getUploadRealPath())).append(time).append(getFileExt(f.getName()));
        StringBuilder virtualPath = new StringBuilder().append(getFileDir(dir, getBladeFileProperties().getUploadCtxPath())).append(time).append(getFileExt(f.getName()));
        return new String[]{BladeFileUtil.formatUrl(uploadPath.toString()), BladeFileUtil.formatUrl(virtualPath.toString())};
    }
 
    public static String getFileExt(String fileName) {
        if (!fileName.contains(".")) {
            return ".jpg";
        }
        return fileName.substring(fileName.lastIndexOf("."));
    }
 
    public static String getFileDir(String dir, String saveDir) {
        StringBuilder newFileDir = new StringBuilder();
        newFileDir.append(saveDir).append(File.separator).append(dir).append(File.separator).append(DateUtil.format(DateUtil.now(), "yyyyMMdd")).append(File.separator);
        return newFileDir.toString();
    }
 
    @Override // com.qianwen.core.boot.file.IFileProxy
    public void compress(String path) {
        try {
            ImageUtil.zoomScale(ImageUtil.readImage(path), new FileOutputStream(new File(path)), (String) null, getBladeFileProperties().getCompressScale().doubleValue(), getBladeFileProperties().getCompressFlag().booleanValue());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}