文件白名单
This commit is contained in:
parent
255dc9285d
commit
69fc47d13a
|
|
@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
||||
|
|
@ -145,6 +147,11 @@ public class Constants
|
|||
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
||||
"org.springframework", "org.apache", "com.bonus.sgzb.common.core.utils.file" };
|
||||
|
||||
// 常见图片格式
|
||||
public static final List<String> IMAGE_EXTENSIONS = Arrays.asList("jpg", "jpeg", "png", "gif");
|
||||
|
||||
public static final String UPLOAD_FILE_URL_PART = "myqcloud.com";
|
||||
|
||||
/**
|
||||
* 系统初始密码
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
package com.bonus.sgzb.common.core.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import com.bonus.sgzb.common.core.constant.Constants;
|
||||
import com.bonus.sgzb.common.core.text.StrFormatter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import static com.bonus.sgzb.common.core.constant.Constants.IMAGE_EXTENSIONS;
|
||||
import static com.bonus.sgzb.common.core.constant.Constants.UPLOAD_FILE_URL_PART;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Slf4j
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
{
|
||||
/** 空字符串 */
|
||||
|
|
@ -21,6 +24,59 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
/** 下划线 */
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
private static final Map<String, String> CAT_MAP;
|
||||
|
||||
static {
|
||||
CAT_MAP = new HashMap<>();
|
||||
CAT_MAP.put("线路施工类", "A");
|
||||
CAT_MAP.put("变电施工类", "B");
|
||||
CAT_MAP.put("特种及其他设备", "C");
|
||||
CAT_MAP.put("检修试验", "D");
|
||||
CAT_MAP.put("创新装备", "E");
|
||||
}
|
||||
|
||||
/**
|
||||
1 抱杆 01人字抱杆、02平臂抱杆、03悬浮抱杆、04....
|
||||
2 放线及滑车 01牵张设备、02滑车、03....
|
||||
3 收紧设备 01电动紧线机、02液压紧线机、03...
|
||||
4 线路动力设备 01机动绞磨、02压接机、03飞车及间隔棒运输机、04....
|
||||
5 配件及仪器仪表 01锚固、02绳索、03连接器、04全站仪RPK、05附件、06....
|
||||
|
||||
1 一次安装设备 01滤油机、02 SF6回收装置、03排油泵、04真空泵、05....
|
||||
2 变电运输设备 01二次屏柜搬运设备、02液压移动小车、03轨道小车、04 GIS运输小坦克、05..
|
||||
|
||||
1 直升机及无人机 01、多旋翼无人机、02固定翼无人机、03巡线直升机、04...
|
||||
2 带电清洗设备 01线路水冲洗、02变电水冲洗、03...
|
||||
3 起重设备 01汽车起重机、02履带式起重机、03随车起重机、04...
|
||||
4 土建设备 01履带式推土机、02液压式挖掘机、03混凝土泵车、05旋挖钻机、06...
|
||||
5 运输设备 01厢式货车、02平板货车、03灌式运输车、04履带运输车、05...
|
||||
6 高空作业设备 01曲臂升降车、02高处作业平台车、03剪叉式升降平台、04...
|
||||
|
||||
1 一次试验设备 01试验变压器、02高压直流发生器、03绕组直流电阻、04变比测试仪、05...
|
||||
2 二次试验设备 01万用表、02电流表、03微安表、04...
|
||||
3 油化试验设备 01微水测试仪、02介损测试仪、03...
|
||||
|
||||
1 线路创新装备 01索道自动上下料装置、02遥控索道牵引机、03塔材组片专用装备、04...
|
||||
2 变电创新装备 01自动安装机械、02新型模具和加固装置、03 GIS/HGIS设备整体就位装备、04..
|
||||
3 其他新装备 01砌筑作业机器人、02高处作业平台车、03电缆敷设智能化控制装备、04...
|
||||
|
||||
map.put("抱杆_人字抱杆","101");
|
||||
map.put("抱杆_平臂抱杆","102");
|
||||
map.put("抱杆_悬浮抱杆","103");
|
||||
map.put("放线及滑车_牵张设备","201");
|
||||
map.put("放线及滑车_滑车","202");
|
||||
map.put("收紧设备_电动紧线机","301");
|
||||
map.put("收紧设备_液压紧线机","302");
|
||||
map.put("线路动力设备_机动绞磨","401");
|
||||
map.put("线路动力设备_压接机","402");
|
||||
map.put("线路动力设备_飞车及间隔棒运输机","403");
|
||||
map.put("配件及仪器仪表_锚固","501");
|
||||
map.put("配件及仪器仪表_绳索","502");
|
||||
map.put("配件及仪器仪表_连接器","503");
|
||||
map.put("配件及仪器仪表_全站仪RPK","504");
|
||||
map.put("配件及仪器仪表_附件","505");
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
|
|
@ -551,4 +607,51 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// System.out.println(getDeviceCode("CSG", "线路施工类", "102", new Date(), "500322"));
|
||||
// }
|
||||
|
||||
public static boolean checkIfFileUrlsValid(String fileUrls) {
|
||||
boolean url_valid = true;
|
||||
if (StringUtils.isEmpty(fileUrls)) {
|
||||
return true;
|
||||
} else {
|
||||
String[] fileUrlArray = fileUrls.split(",");
|
||||
for (String fileUrl : fileUrlArray) {
|
||||
if (!fileUrl.toLowerCase().contains(UPLOAD_FILE_URL_PART)) {
|
||||
url_valid = false;
|
||||
}
|
||||
}
|
||||
return url_valid;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkFileUrlsEndWithExtensions(String fileUrls) {
|
||||
if (StringUtils.isEmpty(fileUrls)) {
|
||||
return true;
|
||||
} else {
|
||||
String[] fileUrlArray = fileUrls.split(",");
|
||||
List<String> fileUrlList = Arrays.asList(fileUrlArray);
|
||||
for (String fileUrl : fileUrlList) {
|
||||
boolean endsWithExtension = false;
|
||||
for (String extension : IMAGE_EXTENSIONS) {
|
||||
if (fileUrl.toLowerCase().endsWith(extension)) {
|
||||
endsWithExtension = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!endsWithExtension) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String fileUrls = "https://example.com/file1.png,https://example.com/file2.gif";
|
||||
boolean allEndWithExtensions = checkFileUrlsEndWithExtensions(fileUrls);
|
||||
System.out.println("所有文件URL都以给定的扩展名结尾: " + allEndWithExtensions);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue