commit
d54a690b4a
63
.workflow/pipeline-20220517-1.yml
Normal file
63
.workflow/pipeline-20220517-1.yml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
version: '1.0'
|
||||||
|
name: pipeline-20220517-1
|
||||||
|
displayName: pipeline-20220517-1
|
||||||
|
triggers:
|
||||||
|
trigger: manual
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
prefix:
|
||||||
|
- ''
|
||||||
|
stages:
|
||||||
|
- name: stage-c0fe9b78
|
||||||
|
displayName: 编译
|
||||||
|
strategy: naturally
|
||||||
|
trigger: auto
|
||||||
|
executor:
|
||||||
|
- mac520
|
||||||
|
steps:
|
||||||
|
- step: build@maven
|
||||||
|
name: build_maven
|
||||||
|
displayName: Maven 构建
|
||||||
|
jdkVersion: '8'
|
||||||
|
mavenVersion: 3.3.9
|
||||||
|
commands:
|
||||||
|
- mvn -B clean package -Dmaven.test.skip=true
|
||||||
|
artifacts:
|
||||||
|
- name: BUILD_ARTIFACT
|
||||||
|
path:
|
||||||
|
- ./release
|
||||||
|
settings: []
|
||||||
|
- name: stage-4d60b905
|
||||||
|
displayName: 部署
|
||||||
|
strategy: naturally
|
||||||
|
trigger: auto
|
||||||
|
executor:
|
||||||
|
- mac520
|
||||||
|
steps:
|
||||||
|
- step: deploy@agent
|
||||||
|
name: deploy_agent
|
||||||
|
displayName: 主机部署
|
||||||
|
hostGroupID: qiwen
|
||||||
|
deployArtifact:
|
||||||
|
- source: build
|
||||||
|
name: qiwen-file
|
||||||
|
target: ~/gitee_go/deploy/qiwen-file
|
||||||
|
dependArtifact: BUILD_ARTIFACT
|
||||||
|
script: |-
|
||||||
|
# 请在此输入部署脚本,如启动Java应用如下
|
||||||
|
# nohup java -jar test.jar > nohup.out &
|
||||||
|
cd ~/gitee_go/deploy/qiwen-file
|
||||||
|
rm -r bin/ conf/ lib/ log/
|
||||||
|
tar -zxvf qiwen-file.tar.gz
|
||||||
|
rm qiwen-file.tar.gz
|
||||||
|
cp -r ~/gitee_go/deploy/qiwen-file/release/* ~/gitee_go/deploy/qiwen-file
|
||||||
|
rm -r release
|
||||||
|
cp /home/qiwen-script/qiwen-file/application.properties conf/config/
|
||||||
|
cp /home/qiwen-script/qiwen-file/settings.properties conf/config/
|
||||||
|
cd bin
|
||||||
|
chmod -R 777 ./*
|
||||||
|
sh restart.sh
|
||||||
|
echo 'Hello Gitee!'
|
||||||
|
permissions:
|
||||||
|
- role: admin
|
||||||
|
members: []
|
47
.workflow/pipeline-20220517.yml
Normal file
47
.workflow/pipeline-20220517.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
version: '1.0'
|
||||||
|
name: pipeline-20220517
|
||||||
|
displayName: pipeline-20220517
|
||||||
|
triggers:
|
||||||
|
trigger: manual
|
||||||
|
stages:
|
||||||
|
- name: stage-8109fa22
|
||||||
|
displayName: 编译
|
||||||
|
strategy: naturally
|
||||||
|
trigger: manual
|
||||||
|
executor: []
|
||||||
|
steps:
|
||||||
|
- step: build@maven
|
||||||
|
name: build_maven
|
||||||
|
displayName: Maven 构建
|
||||||
|
jdkVersion: '8'
|
||||||
|
mavenVersion: 3.3.9
|
||||||
|
commands:
|
||||||
|
- mvn -B clean package -Dmaven.test.skip=true
|
||||||
|
artifacts:
|
||||||
|
- name: BUILD_ARTIFACT
|
||||||
|
path:
|
||||||
|
- ./target
|
||||||
|
settings: []
|
||||||
|
- name: stage-285eb1b9
|
||||||
|
displayName: 发布
|
||||||
|
strategy: naturally
|
||||||
|
trigger: manual
|
||||||
|
executor: []
|
||||||
|
steps:
|
||||||
|
- step: deploy@agent
|
||||||
|
name: deploy_agent
|
||||||
|
displayName: 主机部署
|
||||||
|
hostGroupID: qiwen
|
||||||
|
deployArtifact:
|
||||||
|
- source: build
|
||||||
|
name: output
|
||||||
|
target: ~/gitee_go/deploy
|
||||||
|
dependArtifact: BUILD_ARTIFACT
|
||||||
|
script: |-
|
||||||
|
# 请在此输入部署脚本,如启动Java应用如下
|
||||||
|
# nohup java -jar test.jar > nohup.out &
|
||||||
|
echo 'Hello Gitee!'
|
||||||
|
permissions:
|
||||||
|
- role: admin
|
||||||
|
members:
|
||||||
|
- mac520
|
28
pom.xml
28
pom.xml
@ -6,11 +6,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.qiwenshare</groupId>
|
<groupId>com.qiwenshare</groupId>
|
||||||
<artifactId>qiwenshare</artifactId>
|
<artifactId>qiwenshare</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>qiwen-file</artifactId>
|
<artifactId>qiwen-file</artifactId>
|
||||||
<version>1.2.0-SNAPSHOT</version>
|
<version>1.2.1-SNAPSHOT</version>
|
||||||
<name>qiwen-file</name>
|
<name>qiwen-file</name>
|
||||||
<description>pan.qiwenshare.com</description>
|
<description>pan.qiwenshare.com</description>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@ -45,8 +45,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!-- fastjson -->
|
<!-- fastjson -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 导入Mysql数据库链接jar包-->
|
<!-- 导入Mysql数据库链接jar包-->
|
||||||
@ -86,12 +86,6 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!--mybatis end-->
|
<!--mybatis end-->
|
||||||
|
|
||||||
<!--登陆认证和权限管理-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.shiro</groupId>
|
|
||||||
<artifactId>shiro-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.qiwenshare</groupId>
|
<groupId>com.qiwenshare</groupId>
|
||||||
<artifactId>ufop-spring-boot-starter</artifactId>
|
<artifactId>ufop-spring-boot-starter</artifactId>
|
||||||
@ -112,38 +106,25 @@
|
|||||||
<version>2.0.1</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.inversoft</groupId>
|
|
||||||
<artifactId>prime-jwt</artifactId>
|
|
||||||
<version>1.3.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.11.0</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.mpatric</groupId>-->
|
|
||||||
<!-- <artifactId>mp3agic</artifactId>-->
|
|
||||||
<!-- <version>0.9.1</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org</groupId>
|
<groupId>org</groupId>
|
||||||
<artifactId>jaudiotagger</artifactId>
|
<artifactId>jaudiotagger</artifactId>
|
||||||
<version>2.0.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.stuxuhai</groupId>
|
<groupId>com.github.stuxuhai</groupId>
|
||||||
<artifactId>jpinyin</artifactId>
|
<artifactId>jpinyin</artifactId>
|
||||||
<version>1.1.8</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- <plugin>-->
|
<!-- <plugin>-->
|
||||||
@ -175,6 +156,7 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- not append assembly id in release file name -->
|
<!-- not append assembly id in release file name -->
|
||||||
|
@ -13,8 +13,8 @@ public interface IUserFileService extends IService<UserFile> {
|
|||||||
List<UserFile> selectSameUserFile(String fileName, String filePath, String extendName, Long userId);
|
List<UserFile> selectSameUserFile(String fileName, String filePath, String extendName, Long userId);
|
||||||
|
|
||||||
IPage<FileListVo> userFileList(Long userId, String filePath, Long beginCount, Long pageCount);
|
IPage<FileListVo> userFileList(Long userId, String filePath, Long beginCount, Long pageCount);
|
||||||
void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
void updateFilepathByUserFileId(String userFileId, String newfilePath, long userId);
|
||||||
void userFileCopy(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
void userFileCopy(String userFileId, String newfilePath, long userId);
|
||||||
|
|
||||||
IPage<FileListVo> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, long userId);
|
IPage<FileListVo> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, long userId);
|
||||||
List<UserFile> selectUserFileListByPath(String filePath, Long userId);
|
List<UserFile> selectUserFileListByPath(String filePath, Long userId);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.qiwenshare.file.component;
|
package com.qiwenshare.file.component;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.qiwenshare.file.api.IFiletransferService;
|
import com.qiwenshare.file.api.IFiletransferService;
|
||||||
import com.qiwenshare.file.api.IRecoveryFileService;
|
import com.qiwenshare.file.api.IRecoveryFileService;
|
||||||
|
@ -3,12 +3,13 @@ package com.qiwenshare.file.component;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.github.stuxuhai.jpinyin.PinyinException;
|
import com.github.stuxuhai.jpinyin.PinyinException;
|
||||||
import com.github.stuxuhai.jpinyin.PinyinFormat;
|
import com.github.stuxuhai.jpinyin.PinyinFormat;
|
||||||
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
|
import com.qiwenshare.common.util.HttpsUtils;
|
||||||
import com.qiwenshare.file.api.IShareFileService;
|
import com.qiwenshare.file.api.IShareFileService;
|
||||||
import com.qiwenshare.file.api.IShareService;
|
import com.qiwenshare.file.api.IShareService;
|
||||||
import com.qiwenshare.file.api.IUserService;
|
import com.qiwenshare.file.api.IUserService;
|
||||||
@ -18,17 +19,13 @@ import com.qiwenshare.file.io.QiwenFile;
|
|||||||
import com.qiwenshare.file.mapper.FileMapper;
|
import com.qiwenshare.file.mapper.FileMapper;
|
||||||
import com.qiwenshare.file.mapper.MusicMapper;
|
import com.qiwenshare.file.mapper.MusicMapper;
|
||||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||||
import com.qiwenshare.file.util.HttpsUtils;
|
|
||||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
import com.qiwenshare.file.util.QiwenFileUtil;
|
||||||
import com.qiwenshare.file.util.TreeNode;
|
import com.qiwenshare.file.util.TreeNode;
|
||||||
import com.qiwenshare.ufop.constant.StorageTypeEnum;
|
|
||||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||||
import com.qiwenshare.ufop.operation.copy.Copier;
|
import com.qiwenshare.ufop.operation.copy.Copier;
|
||||||
import com.qiwenshare.ufop.operation.copy.domain.CopyFile;
|
import com.qiwenshare.ufop.operation.copy.domain.CopyFile;
|
||||||
import com.qiwenshare.ufop.operation.download.Downloader;
|
import com.qiwenshare.ufop.operation.download.Downloader;
|
||||||
import com.qiwenshare.ufop.operation.download.domain.DownloadFile;
|
import com.qiwenshare.ufop.operation.download.domain.DownloadFile;
|
||||||
import com.qiwenshare.ufop.operation.read.Reader;
|
|
||||||
import com.qiwenshare.ufop.operation.read.domain.ReadFile;
|
|
||||||
import com.qiwenshare.ufop.operation.write.Writer;
|
import com.qiwenshare.ufop.operation.write.Writer;
|
||||||
import com.qiwenshare.ufop.operation.write.domain.WriteFile;
|
import com.qiwenshare.ufop.operation.write.domain.WriteFile;
|
||||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||||
@ -144,9 +141,8 @@ public class FileDealComp {
|
|||||||
*
|
*
|
||||||
* @param sessionUserId
|
* @param sessionUserId
|
||||||
*/
|
*/
|
||||||
public void restoreParentFilePath(QiwenFile ufopFile1, Long sessionUserId) {
|
public void restoreParentFilePath(QiwenFile qiwenFile, Long sessionUserId) {
|
||||||
|
|
||||||
QiwenFile qiwenFile = new QiwenFile(ufopFile1.getPath(), ufopFile1.isDirectory());
|
|
||||||
if (qiwenFile.isFile()) {
|
if (qiwenFile.isFile()) {
|
||||||
qiwenFile = qiwenFile.getParentFile();
|
qiwenFile = qiwenFile.getParentFile();
|
||||||
}
|
}
|
||||||
@ -166,7 +162,11 @@ public class FileDealComp {
|
|||||||
try {
|
try {
|
||||||
userFileMapper.insert(userFile);
|
userFileMapper.insert(userFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//ignore
|
if (e.getMessage().contains("Duplicate entry")) {
|
||||||
|
//ignore
|
||||||
|
} else {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qiwenFile = new QiwenFile(parentFilePath, true);
|
qiwenFile = new QiwenFile(parentFilePath, true);
|
||||||
@ -549,8 +549,9 @@ public class FileDealComp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getLyc(String singerName, String mp3Name) {
|
public String getLyc(String singerName, String mp3Name) {
|
||||||
|
Map<String, Object> headMap = new HashMap<>();
|
||||||
String s = HttpsUtils.doGetString("https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?_=1651992748984&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&hostUin=0&is_xml=0&key=" + mp3Name.replaceAll(" ", ""));
|
headMap.put("Referer", "https://y.qq.com/");
|
||||||
|
String s = HttpsUtils.doGetString("https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?_=1651992748984&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&hostUin=0&is_xml=0&key=" + mp3Name.replaceAll(" ", ""), headMap);
|
||||||
Map map = JSON.parseObject(s, Map.class);
|
Map map = JSON.parseObject(s, Map.class);
|
||||||
Map data = (Map) map.get("data");
|
Map data = (Map) map.get("data");
|
||||||
Map song = (Map) data.get("song");
|
Map song = (Map) data.get("song");
|
||||||
@ -603,7 +604,7 @@ public class FileDealComp {
|
|||||||
id = (String) item.get("id");
|
id = (String) item.get("id");
|
||||||
mid = (String) item.get("mid");
|
mid = (String) item.get("mid");
|
||||||
if (singer.equals(singerName) && mp3Name.equals(mp3name)) {
|
if (singer.equals(singerName) && mp3Name.equals(mp3name)) {
|
||||||
String res = HttpsUtils.doGetString("https://c.y.qq.com/v8/fcg-bin/musicmall.fcg?_=1652026128283&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&cmd=get_album_buy_page&albummid=" + mid + "&albumid=0");
|
String res = HttpsUtils.doGetString("https://c.y.qq.com/v8/fcg-bin/musicmall.fcg?_=1652026128283&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&cmd=get_album_buy_page&albummid=" + mid + "&albumid=0", headMap);
|
||||||
Map map1 = JSON.parseObject(res, Map.class);
|
Map map1 = JSON.parseObject(res, Map.class);
|
||||||
Map data1 = (Map) map1.get("data");
|
Map data1 = (Map) map1.get("data");
|
||||||
List<Map> list1 = (List<Map>) data1.get("songlist");
|
List<Map> list1 = (List<Map>) data1.get("songlist");
|
||||||
@ -625,7 +626,7 @@ public class FileDealComp {
|
|||||||
|
|
||||||
String s1 = HttpsUtils.doGetString("https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?_=1651993218842&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&loginUin=0&" +
|
String s1 = HttpsUtils.doGetString("https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?_=1651993218842&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&loginUin=0&" +
|
||||||
"songmid="+mid+"&" +
|
"songmid="+mid+"&" +
|
||||||
"musicid=" + id);
|
"musicid=" + id, headMap);
|
||||||
Map map1 = JSON.parseObject(s1, Map.class);
|
Map map1 = JSON.parseObject(s1, Map.class);
|
||||||
return (String) map1.get("lyric");
|
return (String) map1.get("lyric");
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.qiwenshare.file.component;
|
package com.qiwenshare.file.component;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.qiwenshare.common.util.math.CalculatorUtils;
|
import com.qiwenshare.common.util.math.CalculatorUtils;
|
||||||
import com.qiwenshare.file.config.jwt.JwtProperties;
|
import com.qiwenshare.file.config.jwt.JwtProperties;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
@ -7,13 +8,14 @@ import io.jsonwebtoken.JwtBuilder;
|
|||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
import io.jsonwebtoken.impl.DefaultClaims;
|
import io.jsonwebtoken.impl.DefaultClaims;
|
||||||
import org.apache.commons.net.util.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class JwtComp {
|
public class JwtComp {
|
||||||
@ -32,8 +34,8 @@ public class JwtComp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建jwt
|
// 创建jwt
|
||||||
public String createJWT(String subject) throws Exception {
|
public String createJWT(Map<String, Object> param) {
|
||||||
|
String subject = JSON.toJSONString(param);
|
||||||
// 生成JWT的时间
|
// 生成JWT的时间
|
||||||
long nowTime = System.currentTimeMillis();
|
long nowTime = System.currentTimeMillis();
|
||||||
Date nowDate = new Date(nowTime);
|
Date nowDate = new Date(nowTime);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.qiwenshare.file.controller;
|
package com.qiwenshare.file.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.qiwenshare.common.anno.MyLog;
|
import com.qiwenshare.common.anno.MyLog;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
@ -10,7 +10,6 @@ import com.qiwenshare.common.util.security.SessionUtil;
|
|||||||
import com.qiwenshare.file.api.ICommonFileService;
|
import com.qiwenshare.file.api.ICommonFileService;
|
||||||
import com.qiwenshare.file.api.IFilePermissionService;
|
import com.qiwenshare.file.api.IFilePermissionService;
|
||||||
import com.qiwenshare.file.api.IUserFileService;
|
import com.qiwenshare.file.api.IUserFileService;
|
||||||
import com.qiwenshare.file.constant.CommonFileTypeEnum;
|
|
||||||
import com.qiwenshare.file.domain.CommonFile;
|
import com.qiwenshare.file.domain.CommonFile;
|
||||||
import com.qiwenshare.file.domain.FilePermission;
|
import com.qiwenshare.file.domain.FilePermission;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
|
@ -5,7 +5,7 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|||||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||||
import co.elastic.clients.elasticsearch.core.search.HighlighterEncoder;
|
import co.elastic.clients.elasticsearch.core.search.HighlighterEncoder;
|
||||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.qiwenshare.common.anno.MyLog;
|
import com.qiwenshare.common.anno.MyLog;
|
||||||
@ -235,7 +235,7 @@ public class FileController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "解压文件", description = "解压缩功能为体验功能,可以解压zip和rar格式的压缩文件,目前只支持本地存储文件解压,部分高版本rar格式不支持。", tags = {"file"})
|
@Operation(summary = "解压文件", description = "解压文件。", tags = {"file"})
|
||||||
@RequestMapping(value = "/unzipfile", method = RequestMethod.POST)
|
@RequestMapping(value = "/unzipfile", method = RequestMethod.POST)
|
||||||
@MyLog(operation = "解压文件", module = CURRENT_MODULE)
|
@MyLog(operation = "解压文件", module = CURRENT_MODULE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -264,7 +264,6 @@ public class FileController {
|
|||||||
String oldfilePath = userFile.getFilePath();
|
String oldfilePath = userFile.getFilePath();
|
||||||
String newfilePath = copyFileDTO.getFilePath();
|
String newfilePath = copyFileDTO.getFilePath();
|
||||||
String fileName = userFile.getFileName();
|
String fileName = userFile.getFileName();
|
||||||
String extendName = userFile.getExtendName();
|
|
||||||
if (userFile.getIsDir() == 1) {
|
if (userFile.getIsDir() == 1) {
|
||||||
QiwenFile qiwenFile = new QiwenFile(oldfilePath, fileName, true);
|
QiwenFile qiwenFile = new QiwenFile(oldfilePath, fileName, true);
|
||||||
if (newfilePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || newfilePath.equals(qiwenFile.getPath())) {
|
if (newfilePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || newfilePath.equals(qiwenFile.getPath())) {
|
||||||
@ -272,7 +271,7 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userFileService.userFileCopy(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId());
|
userFileService.userFileCopy(userFileId, newfilePath,sessionUserBean.getUserId());
|
||||||
fileDealComp.deleteRepeatSubDirFile(newfilePath, sessionUserBean.getUserId());
|
fileDealComp.deleteRepeatSubDirFile(newfilePath, sessionUserBean.getUserId());
|
||||||
return RestResult.success();
|
return RestResult.success();
|
||||||
|
|
||||||
@ -285,11 +284,11 @@ public class FileController {
|
|||||||
public RestResult<String> moveFile(@RequestBody MoveFileDTO moveFileDto) {
|
public RestResult<String> moveFile(@RequestBody MoveFileDTO moveFileDto) {
|
||||||
|
|
||||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||||
|
UserFile userFile = userFileService.getById(moveFileDto.getUserFileId());
|
||||||
String oldfilePath = moveFileDto.getOldFilePath();
|
String oldfilePath = userFile.getFilePath();
|
||||||
String newfilePath = moveFileDto.getFilePath();
|
String newfilePath = moveFileDto.getFilePath();
|
||||||
String fileName = moveFileDto.getFileName();
|
String fileName = userFile.getFileName();
|
||||||
String extendName = moveFileDto.getExtendName();
|
String extendName = userFile.getExtendName();
|
||||||
if (StringUtil.isEmpty(extendName)) {
|
if (StringUtil.isEmpty(extendName)) {
|
||||||
QiwenFile qiwenFile = new QiwenFile(oldfilePath, fileName, true);
|
QiwenFile qiwenFile = new QiwenFile(oldfilePath, fileName, true);
|
||||||
if (newfilePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || newfilePath.equals(qiwenFile.getPath())) {
|
if (newfilePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || newfilePath.equals(qiwenFile.getPath())) {
|
||||||
@ -297,7 +296,7 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userFileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId());
|
userFileService.updateFilepathByUserFileId(moveFileDto.getUserFileId(), newfilePath, sessionUserBean.getUserId());
|
||||||
|
|
||||||
fileDealComp.deleteRepeatSubDirFile(newfilePath, sessionUserBean.getUserId());
|
fileDealComp.deleteRepeatSubDirFile(newfilePath, sessionUserBean.getUserId());
|
||||||
return RestResult.success();
|
return RestResult.success();
|
||||||
@ -325,8 +324,7 @@ public class FileController {
|
|||||||
return RestResult.fail().message("原路径与目标路径冲突,不能移动");
|
return RestResult.fail().message("原路径与目标路径冲突,不能移动");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userFileService.updateFilepathByUserFileId(userFile.getUserFileId(), newfilePath, sessionUserBean.getUserId());
|
||||||
userFileService.updateFilepathByFilepath(userFile.getFilePath(), newfilePath, userFile.getFileName(), userFile.getExtendName(), sessionUserBean.getUserId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RestResult.success().data("批量移动文件成功");
|
return RestResult.success().data("批量移动文件成功");
|
||||||
|
@ -23,6 +23,7 @@ import com.qiwenshare.file.vo.file.UploadFileVo;
|
|||||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||||
import com.qiwenshare.ufop.operation.download.Downloader;
|
import com.qiwenshare.ufop.operation.download.Downloader;
|
||||||
import com.qiwenshare.ufop.operation.download.domain.DownloadFile;
|
import com.qiwenshare.ufop.operation.download.domain.DownloadFile;
|
||||||
|
import com.qiwenshare.ufop.operation.download.domain.Range;
|
||||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -213,40 +214,49 @@ public class FiletransferController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
||||||
|
String mime = MimeUtils.getMime(userFile.getExtendName());
|
||||||
|
httpServletResponse.setHeader("Content-Type", mime);
|
||||||
|
|
||||||
FileBean fileBean = fileService.getById(userFile.getFileId());
|
FileBean fileBean = fileService.getById(userFile.getFileId());
|
||||||
if ((UFOPUtils.isVideoFile(userFile.getExtendName()) || "mp3".equalsIgnoreCase(userFile.getExtendName()) || "flac".equalsIgnoreCase(userFile.getExtendName()))
|
if ((UFOPUtils.isVideoFile(userFile.getExtendName()) || "mp3".equalsIgnoreCase(userFile.getExtendName()) || "flac".equalsIgnoreCase(userFile.getExtendName()))
|
||||||
&& !"true".equals(previewDTO.getIsMin())) {
|
&& !"true".equals(previewDTO.getIsMin())) {
|
||||||
|
//获取从那个字节开始读取文件
|
||||||
|
String rangeString = httpServletRequest.getHeader("Range");
|
||||||
|
int start = 0;
|
||||||
|
if (StringUtils.isNotBlank(rangeString)) {
|
||||||
|
start = Integer.valueOf(rangeString.substring(rangeString.indexOf("=") + 1, rangeString.indexOf("-")));
|
||||||
|
}
|
||||||
|
|
||||||
Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
|
Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
|
||||||
DownloadFile downloadFile = new DownloadFile();
|
DownloadFile downloadFile = new DownloadFile();
|
||||||
downloadFile.setFileUrl(fileBean.getFileUrl());
|
downloadFile.setFileUrl(fileBean.getFileUrl());
|
||||||
|
Range range = new Range();
|
||||||
|
range.setStart(start);
|
||||||
|
range.setLength(1024 * 1024 * 1);
|
||||||
|
downloadFile.setRange(range);
|
||||||
InputStream inputStream = downloader.getInputStream(downloadFile);
|
InputStream inputStream = downloader.getInputStream(downloadFile);
|
||||||
|
|
||||||
String mime = MimeUtils.getMime(userFile.getExtendName());
|
|
||||||
httpServletResponse.setHeader("Content-Type", mime);
|
|
||||||
|
|
||||||
//获取从那个字节开始读取文件
|
|
||||||
String rangeString = httpServletRequest.getHeader("Range");
|
|
||||||
int range = 0;
|
|
||||||
if (StringUtils.isNotBlank(rangeString)) {
|
|
||||||
range = Integer.valueOf(rangeString.substring(rangeString.indexOf("=") + 1, rangeString.indexOf("-")));
|
|
||||||
}
|
|
||||||
//获取响应的输出流
|
|
||||||
OutputStream outputStream = httpServletResponse.getOutputStream();
|
OutputStream outputStream = httpServletResponse.getOutputStream();
|
||||||
//返回码需要为206,代表只处理了部分请求,响应了部分数据
|
try {
|
||||||
httpServletResponse.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
|
||||||
// 每次请求只返回1MB的视频流
|
//返回码需要为206,代表只处理了部分请求,响应了部分数据
|
||||||
byte[] bytes = new byte[1024 * 1024 * 5];
|
httpServletResponse.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||||
inputStream.skip(range);
|
// 每次请求只返回1MB的视频流
|
||||||
int len = IOUtils.read(inputStream, bytes);
|
|
||||||
//设置此次相应返回的数据长度
|
httpServletResponse.setHeader("Accept-Ranges", "bytes");
|
||||||
httpServletResponse.setContentLength(len);
|
//设置此次相应返回的数据范围
|
||||||
httpServletResponse.setHeader("Accept-Ranges", "bytes");
|
httpServletResponse.setHeader("Content-Range", "bytes " + start + "-" + (fileBean.getFileSize() - 1) + "/" + fileBean.getFileSize());
|
||||||
//设置此次相应返回的数据范围
|
IOUtils.copy(inputStream, outputStream);
|
||||||
httpServletResponse.setHeader("Content-Range", "bytes " + range + "-" + (fileBean.getFileSize() - 1) + "/" + fileBean.getFileSize());
|
|
||||||
// 将这1MB的视频流响应给客户端
|
|
||||||
outputStream.write(bytes, 0, len);
|
} finally {
|
||||||
outputStream.close();
|
IOUtils.closeQuietly(inputStream);
|
||||||
|
IOUtils.closeQuietly(outputStream);
|
||||||
|
if (downloadFile.getOssClient() != null) {
|
||||||
|
downloadFile.getOssClient().shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
filetransferService.previewFile(httpServletResponse, previewDTO);
|
filetransferService.previewFile(httpServletResponse, previewDTO);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.qiwenshare.file.controller;
|
package com.qiwenshare.file.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||||
import com.qiwenshare.common.exception.NotLoginException;
|
import com.qiwenshare.common.exception.NotLoginException;
|
||||||
@ -147,16 +147,17 @@ public class OfficeController {
|
|||||||
UserFile userFile = userFileService.getById(previewOfficeFileDTO.getUserFileId());
|
UserFile userFile = userFileService.getById(previewOfficeFileDTO.getUserFileId());
|
||||||
|
|
||||||
String baseUrl = request.getScheme()+"://"+ deploymentHost + ":" + port + request.getContextPath();
|
String baseUrl = request.getScheme()+"://"+ deploymentHost + ":" + port + request.getContextPath();
|
||||||
|
String query = "?type=show&token="+token;
|
||||||
FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(),
|
String callbackUrl = baseUrl + "/office/IndexServlet" + query;
|
||||||
|
FileModel file = new FileModel(userFile.getUserFileId(),
|
||||||
|
userFile.getFileName() + "." + userFile.getExtendName(),
|
||||||
previewOfficeFileDTO.getPreviewUrl(),
|
previewOfficeFileDTO.getPreviewUrl(),
|
||||||
userFile.getUploadTime(),
|
userFile.getUploadTime(),
|
||||||
String.valueOf(loginUser.getUserId()),
|
String.valueOf(loginUser.getUserId()),
|
||||||
loginUser.getUsername(),
|
loginUser.getUsername(),
|
||||||
|
callbackUrl,
|
||||||
"view");
|
"view");
|
||||||
|
|
||||||
String query = "?type=show&token="+token;
|
|
||||||
file.editorConfig.callbackUrl= baseUrl + "/office/IndexServlet" + query;
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("file",file);
|
jsonObject.put("file",file);
|
||||||
jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api"));
|
jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api"));
|
||||||
@ -185,17 +186,17 @@ public class OfficeController {
|
|||||||
String baseUrl = request.getScheme()+"://"+ deploymentHost + ":" + port + request.getContextPath();
|
String baseUrl = request.getScheme()+"://"+ deploymentHost + ":" + port + request.getContextPath();
|
||||||
|
|
||||||
log.info("回调地址baseUrl:" + baseUrl);
|
log.info("回调地址baseUrl:" + baseUrl);
|
||||||
|
String query = "?type=edit&userFileId="+userFile.getUserFileId()+"&token="+token;
|
||||||
|
String callbackUrl = baseUrl + "/office/IndexServlet" + query;
|
||||||
|
|
||||||
FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(),
|
FileModel file = new FileModel(userFile.getUserFileId(),
|
||||||
|
userFile.getFileName() + "." + userFile.getExtendName(),
|
||||||
editOfficeFileDTO.getPreviewUrl(),
|
editOfficeFileDTO.getPreviewUrl(),
|
||||||
userFile.getUploadTime(),
|
userFile.getUploadTime(),
|
||||||
String.valueOf(loginUser.getUserId()),
|
String.valueOf(loginUser.getUserId()),
|
||||||
loginUser.getUsername(),
|
loginUser.getUsername(),
|
||||||
|
callbackUrl,
|
||||||
"edit");
|
"edit");
|
||||||
file.changeType(request.getParameter("mode"), "edit");
|
|
||||||
|
|
||||||
String query = "?type=edit&userFileId="+userFile.getUserFileId()+"&token="+token;
|
|
||||||
file.editorConfig.callbackUrl= baseUrl + "/office/IndexServlet" + query;
|
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("file",file);
|
jsonObject.put("file",file);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.qiwenshare.file.controller;
|
package com.qiwenshare.file.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.qiwenshare.common.anno.MyLog;
|
import com.qiwenshare.common.anno.MyLog;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.util.security.JwtUser;
|
import com.qiwenshare.common.util.security.JwtUser;
|
||||||
|
@ -3,7 +3,7 @@ package com.qiwenshare.file.controller;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.qiwenshare.common.anno.MyLog;
|
import com.qiwenshare.common.anno.MyLog;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
|
@ -7,7 +7,6 @@ import com.qiwenshare.file.component.FileDealComp;
|
|||||||
import com.qiwenshare.file.domain.ShareFile;
|
import com.qiwenshare.file.domain.ShareFile;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
import com.qiwenshare.file.io.QiwenFile;
|
import com.qiwenshare.file.io.QiwenFile;
|
||||||
import com.qiwenshare.file.service.ShareFileService;
|
|
||||||
import com.qiwenshare.file.service.UserFileService;
|
import com.qiwenshare.file.service.UserFileService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.qiwenshare.file.controller;
|
package com.qiwenshare.file.controller;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.qiwenshare.common.anno.MyLog;
|
import com.qiwenshare.common.anno.MyLog;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
|
import com.qiwenshare.common.util.HashUtils;
|
||||||
import com.qiwenshare.common.util.security.JwtUser;
|
import com.qiwenshare.common.util.security.JwtUser;
|
||||||
import com.qiwenshare.common.util.security.SessionUtil;
|
import com.qiwenshare.common.util.security.SessionUtil;
|
||||||
import com.qiwenshare.file.api.IUserLoginInfoService;
|
import com.qiwenshare.file.api.IUserLoginInfoService;
|
||||||
@ -19,7 +19,6 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.shiro.crypto.hash.SimpleHash;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -68,8 +67,7 @@ public class UserController {
|
|||||||
@Parameter(description = "登录密码") String password){
|
@Parameter(description = "登录密码") String password){
|
||||||
RestResult<UserLoginVo> restResult = new RestResult<UserLoginVo>();
|
RestResult<UserLoginVo> restResult = new RestResult<UserLoginVo>();
|
||||||
String salt = userService.getSaltByTelephone(telephone);
|
String salt = userService.getSaltByTelephone(telephone);
|
||||||
String hashPassword = new SimpleHash("MD5", password, salt, 1024).toHex();
|
String hashPassword = HashUtils.hashHex("MD5", password, salt, 1024);
|
||||||
|
|
||||||
UserBean result = userService.selectUserByTelephoneAndPassword(telephone, hashPassword);
|
UserBean result = userService.selectUserByTelephoneAndPassword(telephone, hashPassword);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return RestResult.fail().message("手机号或密码错误!");
|
return RestResult.fail().message("手机号或密码错误!");
|
||||||
@ -79,7 +77,7 @@ public class UserController {
|
|||||||
param.put("userId", result.getUserId());
|
param.put("userId", result.getUserId());
|
||||||
String token = "";
|
String token = "";
|
||||||
try {
|
try {
|
||||||
token = jwtComp.createJWT(JSON.toJSONString(param));
|
token = jwtComp.createJWT(param);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("登录失败:{}", e);
|
log.info("登录失败:{}", e);
|
||||||
return RestResult.fail().message("创建token失败!");
|
return RestResult.fail().message("创建token失败!");
|
||||||
@ -98,7 +96,6 @@ public class UserController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "检查用户登录信息", description = "验证token的有效性", tags = {"user"})
|
@Operation(summary = "检查用户登录信息", description = "验证token的有效性", tags = {"user"})
|
||||||
@GetMapping("/checkuserlogininfo")
|
@GetMapping("/checkuserlogininfo")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -12,7 +12,7 @@ import javax.persistence.*;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "userfile", uniqueConstraints = {
|
@Table(name = "userfile", uniqueConstraints = {
|
||||||
@UniqueConstraint(name = "fileindex", columnNames = { "userId", "filePath", "fileName", "extendName", "deleteFlag"})}
|
@UniqueConstraint(name = "fileindex", columnNames = { "userId", "filePath", "fileName", "extendName", "deleteFlag", "isDir"})}
|
||||||
)
|
)
|
||||||
@Entity
|
@Entity
|
||||||
@TableName("userfile")
|
@TableName("userfile")
|
||||||
@ -35,7 +35,7 @@ public class UserFile {
|
|||||||
@Column(columnDefinition="varchar(500) comment '文件路径'")
|
@Column(columnDefinition="varchar(500) comment '文件路径'")
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(100) comment '扩展名'")
|
@Column(columnDefinition="varchar(100) NULL DEFAULT '' comment '扩展名'")
|
||||||
private String extendName;
|
private String extendName;
|
||||||
|
|
||||||
@Column(columnDefinition="int(1) comment '是否是目录(0-否,1-是)'")
|
@Column(columnDefinition="int(1) comment '是否是目录(0-否,1-是)'")
|
||||||
@ -66,4 +66,12 @@ public class UserFile {
|
|||||||
this.deleteFlag = 0;
|
this.deleteFlag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDirectory() {
|
||||||
|
return this.isDir == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFile() {
|
||||||
|
return this.isDir == 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,17 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
@Schema(name = "移动文件DTO",required = true)
|
@Schema(name = "移动文件DTO",required = true)
|
||||||
public class MoveFileDTO {
|
public class MoveFileDTO {
|
||||||
|
@Schema(description = "用户文件id", required = true)
|
||||||
|
private String userFileId;
|
||||||
@Schema(description = "文件路径", required = true)
|
@Schema(description = "文件路径", required = true)
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
//
|
||||||
@Schema(description = "文件名", required = true)
|
// @Schema(description = "文件名", required = true)
|
||||||
private String fileName;
|
// private String fileName;
|
||||||
|
//
|
||||||
@Schema(description = "旧文件名", required = true)
|
// @Schema(description = "旧文件名", required = true)
|
||||||
private String oldFilePath;
|
// private String oldFilePath;
|
||||||
@Schema(description = "扩展名", required = true)
|
// @Schema(description = "扩展名", required = true)
|
||||||
private String extendName;
|
// private String extendName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,12 @@
|
|||||||
package com.qiwenshare.file.helper;
|
package com.qiwenshare.file.helper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.qiwenshare.file.component.JwtComp;
|
||||||
|
import com.qiwenshare.file.service.OfficeConverterService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import javax.annotation.Resource;
|
||||||
import com.qiwenshare.file.constant.FileType;
|
|
||||||
import org.primeframework.jwt.Signer;
|
|
||||||
import org.primeframework.jwt.Verifier;
|
|
||||||
import org.primeframework.jwt.domain.JWT;
|
|
||||||
import org.primeframework.jwt.hmac.HMACSigner;
|
|
||||||
import org.primeframework.jwt.hmac.HMACVerifier;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -38,8 +35,13 @@ import java.net.URLEncoder;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class DocumentManager
|
public class DocumentManager
|
||||||
{
|
{
|
||||||
|
@Resource
|
||||||
|
private JwtComp jwtComp;
|
||||||
|
@Resource
|
||||||
|
private OfficeConverterService officeConverterService;
|
||||||
private static HttpServletRequest request;
|
private static HttpServletRequest request;
|
||||||
|
|
||||||
public static void Init(HttpServletRequest req, HttpServletResponse resp)
|
public static void Init(HttpServletRequest req, HttpServletResponse resp)
|
||||||
@ -229,7 +231,7 @@ public class DocumentManager
|
|||||||
|
|
||||||
File meta = new File(histDir + File.separator + "createdInfo.json");
|
File meta = new File(histDir + File.separator + "createdInfo.json");
|
||||||
try (FileWriter writer = new FileWriter(meta)) {
|
try (FileWriter writer = new FileWriter(meta)) {
|
||||||
json.writeJSONString(writer);
|
// json.writeJSONString(writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,13 +292,13 @@ public class DocumentManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Map<String, Object>> GetFilesInfo(){
|
public ArrayList<Map<String, Object>> GetFilesInfo(){
|
||||||
ArrayList<Map<String, Object>> files = new ArrayList<>();
|
ArrayList<Map<String, Object>> files = new ArrayList<>();
|
||||||
|
|
||||||
for(File file : GetStoredFiles(null)){
|
for(File file : GetStoredFiles(null)){
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("version", GetFileVersion(file.getName(), null));
|
map.put("version", GetFileVersion(file.getName(), null));
|
||||||
map.put("id", ServiceConverter.GenerateRevisionId(CurUserHostAddress(null) + "/" + file.getName() + "/" + Long.toString(new File(StoragePath(file.getName(), null)).lastModified())));
|
map.put("id", officeConverterService.GenerateRevisionId(CurUserHostAddress(null) + "/" + file.getName() + "/" + Long.toString(new File(StoragePath(file.getName(), null)).lastModified())));
|
||||||
map.put("contentLength", new BigDecimal(String.valueOf((file.length()/1024.0))).setScale(2, RoundingMode.HALF_UP) + " KB");
|
map.put("contentLength", new BigDecimal(String.valueOf((file.length()/1024.0))).setScale(2, RoundingMode.HALF_UP) + " KB");
|
||||||
map.put("pureContentLength", file.length());
|
map.put("pureContentLength", file.length());
|
||||||
map.put("title", file.getName());
|
map.put("title", file.getName());
|
||||||
@ -307,7 +309,7 @@ public class DocumentManager
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Map<String, Object>> GetFilesInfo(String fileId){
|
public ArrayList<Map<String, Object>> GetFilesInfo(String fileId){
|
||||||
ArrayList<Map<String, Object>> file = new ArrayList<>();
|
ArrayList<Map<String, Object>> file = new ArrayList<>();
|
||||||
|
|
||||||
for (Map<String, Object> map : GetFilesInfo()){
|
for (Map<String, Object> map : GetFilesInfo()){
|
||||||
@ -356,50 +358,52 @@ public class DocumentManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GetInternalExtension(FileType fileType)
|
// public static String GetInternalExtension(FileType fileType)
|
||||||
{
|
// {
|
||||||
if (fileType.equals(FileType.Word))
|
// if (fileType.equals(FileType.Word))
|
||||||
return ".docx";
|
// return ".docx";
|
||||||
|
//
|
||||||
|
// if (fileType.equals(FileType.Cell))
|
||||||
|
// return ".xlsx";
|
||||||
|
//
|
||||||
|
// if (fileType.equals(FileType.Slide))
|
||||||
|
// return ".pptx";
|
||||||
|
//
|
||||||
|
// return ".docx";
|
||||||
|
// }
|
||||||
|
|
||||||
if (fileType.equals(FileType.Cell))
|
// public static String CreateToken(Map<String, Object> payloadClaims)
|
||||||
return ".xlsx";
|
// {
|
||||||
|
// jwtComp.createJWT(payloadClaims);
|
||||||
if (fileType.equals(FileType.Slide))
|
//
|
||||||
return ".pptx";
|
// try
|
||||||
|
// {
|
||||||
return ".docx";
|
// Signer signer = HMACSigner.newSHA256Signer(GetTokenSecret());
|
||||||
}
|
// JWT jwt = new JWT();
|
||||||
|
// for (String key : payloadClaims.keySet())
|
||||||
public static String CreateToken(Map<String, Object> payloadClaims)
|
// {
|
||||||
{
|
// jwt.addClaim(key, payloadClaims.get(key));
|
||||||
try
|
// }
|
||||||
{
|
// return JWT.getEncoder().encode(jwt, signer);
|
||||||
Signer signer = HMACSigner.newSHA256Signer(GetTokenSecret());
|
// }
|
||||||
JWT jwt = new JWT();
|
// catch (Exception e)
|
||||||
for (String key : payloadClaims.keySet())
|
// {
|
||||||
{
|
// return "";
|
||||||
jwt.addClaim(key, payloadClaims.get(key));
|
// }
|
||||||
}
|
// }
|
||||||
return JWT.getEncoder().encode(jwt, signer);
|
//
|
||||||
}
|
// public static JWT ReadToken(String token)
|
||||||
catch (Exception e)
|
// {
|
||||||
{
|
// try
|
||||||
return "";
|
// {
|
||||||
}
|
// Verifier verifier = HMACVerifier.newVerifier(GetTokenSecret());
|
||||||
}
|
// return JWT.getDecoder().decode(token, verifier);
|
||||||
|
// }
|
||||||
public static JWT ReadToken(String token)
|
// catch (Exception exception)
|
||||||
{
|
// {
|
||||||
try
|
// return null;
|
||||||
{
|
// }
|
||||||
Verifier verifier = HMACVerifier.newVerifier(GetTokenSecret());
|
// }
|
||||||
return JWT.getDecoder().decode(token, verifier);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Boolean TokenEnabled()
|
public static Boolean TokenEnabled()
|
||||||
{
|
{
|
||||||
|
@ -18,24 +18,33 @@
|
|||||||
|
|
||||||
package com.qiwenshare.file.helper;
|
package com.qiwenshare.file.helper;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.primeframework.jwt.domain.JWT;
|
import com.qiwenshare.file.component.JwtComp;
|
||||||
|
import com.qiwenshare.file.service.OfficeConverterService;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class TrackManager {
|
public class TrackManager {
|
||||||
|
@Resource
|
||||||
|
private JwtComp jwtComp;
|
||||||
|
@Resource
|
||||||
|
private OfficeConverterService officeConverterService;
|
||||||
private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
|
private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
|
||||||
|
|
||||||
public static JSONObject readBody(HttpServletRequest request, PrintWriter writer) throws Exception {
|
public JSONObject readBody(HttpServletRequest request, PrintWriter writer) throws Exception {
|
||||||
String bodyString = "";
|
String bodyString = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -78,37 +87,45 @@ public class TrackManager {
|
|||||||
throw new Exception("{\"error\":1,\"message\":\"JWT expected\"}");
|
throw new Exception("{\"error\":1,\"message\":\"JWT expected\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
JWT jwt = DocumentManager.ReadToken(token);
|
Claims claims = jwtComp.parseJWT(token);
|
||||||
if (jwt == null) {
|
|
||||||
writer.write("{\"error\":1,\"message\":\"JWT validation failed\"}");
|
|
||||||
throw new Exception("{\"error\":1,\"message\":\"JWT validation failed\"}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jwt.getObject("payload") != null) {
|
|
||||||
try {
|
|
||||||
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> payload =
|
|
||||||
(LinkedHashMap<String, Object>)jwt.getObject("payload");
|
|
||||||
|
|
||||||
jwt.claims = payload;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
writer.write("{\"error\":1,\"message\":\"Wrong payload\"}");
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Gson gson = new Gson();
|
body = JSONObject.parseObject(JSON.toJSONString(claims));
|
||||||
body = JSONObject.parseObject(gson.toJson(jwt.claims));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
writer.write("JSONParser.parse error:" + ex.getMessage());
|
writer.write("JSONParser.parse error:" + ex.getMessage());
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (body == null) {
|
||||||
|
writer.write("{\"error\":1,\"message\":\"JWT validation failed\"}");
|
||||||
|
throw new Exception("{\"error\":1,\"message\":\"JWT validation failed\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (jwt.getObject("payload") != null) {
|
||||||
|
// try {
|
||||||
|
// @SuppressWarnings("unchecked") LinkedHashMap<String, Object> payload =
|
||||||
|
// (LinkedHashMap<String, Object>)jwt.getObject("payload");
|
||||||
|
//
|
||||||
|
// jwt.claims = payload;
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// writer.write("{\"error\":1,\"message\":\"Wrong payload\"}");
|
||||||
|
// throw ex;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// Gson gson = new Gson();
|
||||||
|
// body = JSONObject.parseObject(gson.toJson(jwt.claims));
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// writer.write("JSONParser.parse error:" + ex.getMessage());
|
||||||
|
// throw ex;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void processSave(JSONObject body, String fileName, String userAddress) throws Exception {
|
public void processSave(JSONObject body, String fileName, String userAddress) throws Exception {
|
||||||
String downloadUri = (String) body.get("url");
|
String downloadUri = (String) body.get("url");
|
||||||
String changesUri = (String) body.get("changesurl");
|
String changesUri = (String) body.get("changesurl");
|
||||||
String key = (String) body.get("key");
|
String key = (String) body.get("key");
|
||||||
@ -119,7 +136,7 @@ public class TrackManager {
|
|||||||
|
|
||||||
if (!curExt.equals(downloadExt)) {
|
if (!curExt.equals(downloadExt)) {
|
||||||
try {
|
try {
|
||||||
String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false);
|
String newFileUri = officeConverterService.GetConvertedUri(downloadUri, downloadExt, curExt, officeConverterService.GenerateRevisionId(downloadUri), null, false);
|
||||||
if (newFileUri.isEmpty()) {
|
if (newFileUri.isEmpty()) {
|
||||||
newFileName = DocumentManager.GetCorrectName(FileUtility.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress);
|
newFileName = DocumentManager.GetCorrectName(FileUtility.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress);
|
||||||
} else {
|
} else {
|
||||||
@ -167,7 +184,7 @@ public class TrackManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void processForceSave(JSONObject body, String fileName, String userAddress) throws Exception {
|
public void processForceSave(JSONObject body, String fileName, String userAddress) throws Exception {
|
||||||
|
|
||||||
String downloadUri = (String) body.get("url");
|
String downloadUri = (String) body.get("url");
|
||||||
|
|
||||||
@ -177,7 +194,7 @@ public class TrackManager {
|
|||||||
|
|
||||||
if (!curExt.equals(downloadExt)) {
|
if (!curExt.equals(downloadExt)) {
|
||||||
try {
|
try {
|
||||||
String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false);
|
String newFileUri = officeConverterService.GetConvertedUri(downloadUri, downloadExt, curExt, officeConverterService.GenerateRevisionId(downloadUri), null, false);
|
||||||
if (newFileUri.isEmpty()) {
|
if (newFileUri.isEmpty()) {
|
||||||
newFileName = true;
|
newFileName = true;
|
||||||
} else {
|
} else {
|
||||||
@ -249,7 +266,7 @@ public class TrackManager {
|
|||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void commandRequest(String method, String key) throws Exception {
|
public void commandRequest(String method, String key) throws Exception {
|
||||||
String DocumentCommandUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.command");
|
String DocumentCommandUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.command");
|
||||||
|
|
||||||
URL url = new URL(DocumentCommandUrl);
|
URL url = new URL(DocumentCommandUrl);
|
||||||
@ -264,11 +281,11 @@ public class TrackManager {
|
|||||||
{
|
{
|
||||||
Map<String, Object> payloadMap = new HashMap<String, Object>();
|
Map<String, Object> payloadMap = new HashMap<String, Object>();
|
||||||
payloadMap.put("payload", params);
|
payloadMap.put("payload", params);
|
||||||
headerToken = DocumentManager.CreateToken(payloadMap);
|
headerToken = jwtComp.createJWT(payloadMap);
|
||||||
|
|
||||||
connection.setRequestProperty(DocumentJwtHeader.equals("") ? "Authorization" : DocumentJwtHeader, "Bearer " + headerToken);
|
connection.setRequestProperty(DocumentJwtHeader.equals("") ? "Authorization" : DocumentJwtHeader, "Bearer " + headerToken);
|
||||||
|
|
||||||
String token = DocumentManager.CreateToken(params);
|
String token = jwtComp.createJWT(params);
|
||||||
params.put("token", token);
|
params.put("token", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,10 +307,10 @@ public class TrackManager {
|
|||||||
if (stream == null)
|
if (stream == null)
|
||||||
throw new Exception("Could not get an answer");
|
throw new Exception("Could not get an answer");
|
||||||
|
|
||||||
String jsonString = ServiceConverter.ConvertStreamToString(stream);
|
String jsonString = officeConverterService.ConvertStreamToString(stream);
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
|
|
||||||
JSONObject response = ServiceConverter.ConvertStringToJSON(jsonString);
|
JSONObject response = officeConverterService.ConvertStringToJSON(jsonString);
|
||||||
if (!response.get("error").toString().equals("0")){
|
if (!response.get("error").toString().equals("0")){
|
||||||
throw new Exception(response.toJSONString());
|
throw new Exception(response.toJSONString());
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.qiwenshare.file.service;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package com.qiwenshare.file.service;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.github.stuxuhai.jpinyin.PinyinException;
|
|
||||||
import com.github.stuxuhai.jpinyin.PinyinFormat;
|
|
||||||
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
import com.qiwenshare.common.util.MimeUtils;
|
import com.qiwenshare.common.util.MimeUtils;
|
||||||
import com.qiwenshare.common.util.security.JwtUser;
|
import com.qiwenshare.common.util.security.JwtUser;
|
||||||
@ -20,7 +15,6 @@ import com.qiwenshare.file.dto.file.PreviewDTO;
|
|||||||
import com.qiwenshare.file.dto.file.UploadFileDTO;
|
import com.qiwenshare.file.dto.file.UploadFileDTO;
|
||||||
import com.qiwenshare.file.io.QiwenFile;
|
import com.qiwenshare.file.io.QiwenFile;
|
||||||
import com.qiwenshare.file.mapper.*;
|
import com.qiwenshare.file.mapper.*;
|
||||||
import com.qiwenshare.file.util.HttpsUtils;
|
|
||||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
import com.qiwenshare.file.util.QiwenFileUtil;
|
||||||
import com.qiwenshare.file.vo.file.UploadFileVo;
|
import com.qiwenshare.file.vo.file.UploadFileVo;
|
||||||
import com.qiwenshare.ufop.constant.StorageTypeEnum;
|
import com.qiwenshare.ufop.constant.StorageTypeEnum;
|
||||||
@ -28,8 +22,6 @@ import com.qiwenshare.ufop.constant.UploadFileStatusEnum;
|
|||||||
import com.qiwenshare.ufop.exception.operation.DownloadException;
|
import com.qiwenshare.ufop.exception.operation.DownloadException;
|
||||||
import com.qiwenshare.ufop.exception.operation.UploadException;
|
import com.qiwenshare.ufop.exception.operation.UploadException;
|
||||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||||
import com.qiwenshare.ufop.operation.copy.Copier;
|
|
||||||
import com.qiwenshare.ufop.operation.copy.domain.CopyFile;
|
|
||||||
import com.qiwenshare.ufop.operation.delete.Deleter;
|
import com.qiwenshare.ufop.operation.delete.Deleter;
|
||||||
import com.qiwenshare.ufop.operation.delete.domain.DeleteFile;
|
import com.qiwenshare.ufop.operation.delete.domain.DeleteFile;
|
||||||
import com.qiwenshare.ufop.operation.download.Downloader;
|
import com.qiwenshare.ufop.operation.download.Downloader;
|
||||||
@ -42,26 +34,8 @@ import com.qiwenshare.ufop.operation.upload.domain.UploadFileResult;
|
|||||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.jaudiotagger.audio.AudioFile;
|
|
||||||
import org.jaudiotagger.audio.AudioFileIO;
|
|
||||||
import org.jaudiotagger.audio.AudioHeader;
|
|
||||||
import org.jaudiotagger.audio.exceptions.CannotReadException;
|
|
||||||
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
|
|
||||||
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
|
|
||||||
import org.jaudiotagger.audio.flac.FlacFileReader;
|
|
||||||
import org.jaudiotagger.audio.mp3.MP3AudioHeader;
|
|
||||||
import org.jaudiotagger.audio.mp3.MP3File;
|
|
||||||
import org.jaudiotagger.tag.FieldKey;
|
|
||||||
import org.jaudiotagger.tag.Tag;
|
|
||||||
import org.jaudiotagger.tag.TagException;
|
|
||||||
import org.jaudiotagger.tag.TagField;
|
|
||||||
import org.jaudiotagger.tag.id3.AbstractID3v2Frame;
|
|
||||||
import org.jaudiotagger.tag.id3.AbstractID3v2Tag;
|
|
||||||
import org.jaudiotagger.tag.id3.framebody.FrameBodyAPIC;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import sun.nio.cs.ext.GBK;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -70,7 +44,10 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.Base64;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.Adler32;
|
import java.util.zip.Adler32;
|
||||||
import java.util.zip.CheckedOutputStream;
|
import java.util.zip.CheckedOutputStream;
|
||||||
@ -98,8 +75,6 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
UploadTaskMapper uploadTaskMapper;
|
UploadTaskMapper uploadTaskMapper;
|
||||||
@Resource
|
@Resource
|
||||||
ImageMapper imageMapper;
|
ImageMapper imageMapper;
|
||||||
@Resource
|
|
||||||
MusicMapper musicMapper;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
PictureFileMapper pictureFileMapper;
|
PictureFileMapper pictureFileMapper;
|
||||||
@ -125,11 +100,6 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
if (list != null && !list.isEmpty()) {
|
if (list != null && !list.isEmpty()) {
|
||||||
FileBean file = list.get(0);
|
FileBean file = list.get(0);
|
||||||
|
|
||||||
if (relativePath.contains("/")) {
|
|
||||||
fileDealComp.restoreParentFilePath(qiwenFile, sessionUserBean.getUserId());
|
|
||||||
fileDealComp.deleteRepeatSubDirFile(uploadFileDTO.getFilePath(), sessionUserBean.getUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
UserFile userFile = new UserFile(qiwenFile, sessionUserBean.getUserId(), file.getFileId());
|
UserFile userFile = new UserFile(qiwenFile, sessionUserBean.getUserId(), file.getFileId());
|
||||||
UserFile param1 = QiwenFileUtil.searchQiwenFileParam(userFile);
|
UserFile param1 = QiwenFileUtil.searchQiwenFileParam(userFile);
|
||||||
List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(param1));
|
List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(param1));
|
||||||
@ -137,6 +107,9 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
userFileMapper.insert(userFile);
|
userFileMapper.insert(userFile);
|
||||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||||
}
|
}
|
||||||
|
if (relativePath.contains("/")) {
|
||||||
|
fileDealComp.restoreParentFilePath(qiwenFile, sessionUserBean.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
uploadFileVo.setSkipUpload(true);
|
uploadFileVo.setSkipUpload(true);
|
||||||
} else {
|
} else {
|
||||||
@ -188,7 +161,7 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
uploadFileResultList = uploader.upload(request, uploadFile);
|
uploadFileResultList = uploader.upload(request, uploadFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("上传失败,请检查UFOP连接配置是否正确");
|
log.error("上传失败,请检查UFOP连接配置是否正确");
|
||||||
throw new UploadException("上传失败");
|
throw new UploadException("上传失败", e);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < uploadFileResultList.size(); i++){
|
for (int i = 0; i < uploadFileResultList.size(); i++){
|
||||||
UploadFileResult uploadFileResult = uploadFileResultList.get(i);
|
UploadFileResult uploadFileResult = uploadFileResultList.get(i);
|
||||||
@ -208,10 +181,7 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
|
|
||||||
UserFile userFile = new UserFile(qiwenFile, userId, fileBean.getFileId());
|
UserFile userFile = new UserFile(qiwenFile, userId, fileBean.getFileId());
|
||||||
|
|
||||||
if (relativePath.contains("/")) {
|
|
||||||
fileDealComp.restoreParentFilePath(qiwenFile, userId);
|
|
||||||
fileDealComp.deleteRepeatSubDirFile(uploadFileDto.getFilePath(), userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserFile param = QiwenFileUtil.searchQiwenFileParam(userFile);
|
UserFile param = QiwenFileUtil.searchQiwenFileParam(userFile);
|
||||||
List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(param));
|
List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(param));
|
||||||
@ -221,6 +191,10 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
}
|
}
|
||||||
userFileMapper.insert(userFile);
|
userFileMapper.insert(userFile);
|
||||||
|
|
||||||
|
if (relativePath.contains("/")) {
|
||||||
|
fileDealComp.restoreParentFilePath(qiwenFile, userId);
|
||||||
|
}
|
||||||
|
|
||||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||||
|
|
||||||
|
|
||||||
@ -306,8 +280,8 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
downloader.download(httpServletResponse, downloadFile);
|
downloader.download(httpServletResponse, downloadFile);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
List<UserFile> userFileList = userFileMapper.selectUserFileByLikeRightFilePath(userFile.getFilePath() + "/" + userFile.getFileName()
|
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
||||||
, userFile.getUserId());
|
List<UserFile> userFileList = userFileMapper.selectUserFileByLikeRightFilePath(qiwenFile.getPath() , userFile.getUserId());
|
||||||
List<String> userFileIds = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
|
List<String> userFileIds = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
|
||||||
|
|
||||||
downloadUserFileList(httpServletResponse, userFile.getFilePath(), userFile.getFileName(), userFileIds);
|
downloadUserFileList(httpServletResponse, userFile.getFilePath(), userFile.getFileName(), userFileIds);
|
||||||
|
@ -16,10 +16,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.qiwenshare.file.helper;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.qiwenshare.file.component.JwtComp;
|
||||||
|
import com.qiwenshare.file.helper.ConfigManager;
|
||||||
|
import com.qiwenshare.file.helper.DocumentManager;
|
||||||
|
import com.qiwenshare.file.helper.FileUtility;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -28,8 +35,11 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class ServiceConverter
|
@Component
|
||||||
|
public class OfficeConverterService
|
||||||
{
|
{
|
||||||
|
@Resource
|
||||||
|
private JwtComp jwtComp;
|
||||||
private static int ConvertTimeout = 120000;
|
private static int ConvertTimeout = 120000;
|
||||||
private static final String DocumentConverterUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.converter");
|
private static final String DocumentConverterUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.converter");
|
||||||
private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
|
private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
|
||||||
@ -61,7 +71,7 @@ public class ServiceConverter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GetConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, String filePass, Boolean isAsync) throws Exception
|
public String GetConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, String filePass, Boolean isAsync) throws Exception
|
||||||
{
|
{
|
||||||
fromExtension = fromExtension == null || fromExtension.isEmpty() ? FileUtility.GetFileExtension(documentUri) : fromExtension;
|
fromExtension = fromExtension == null || fromExtension.isEmpty() ? FileUtility.GetFileExtension(documentUri) : fromExtension;
|
||||||
|
|
||||||
@ -95,12 +105,12 @@ public class ServiceConverter
|
|||||||
if (isAsync)
|
if (isAsync)
|
||||||
map.put("async", body.async);
|
map.put("async", body.async);
|
||||||
|
|
||||||
String token = DocumentManager.CreateToken(map);
|
String token = jwtComp.createJWT(map);
|
||||||
body.token = token;
|
body.token = token;
|
||||||
|
|
||||||
Map<String, Object> payloadMap = new HashMap<String, Object>();
|
Map<String, Object> payloadMap = new HashMap<String, Object>();
|
||||||
payloadMap.put("payload", map);
|
payloadMap.put("payload", map);
|
||||||
headerToken = DocumentManager.CreateToken(payloadMap);
|
headerToken = jwtComp.createJWT(payloadMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
@ -1,6 +1,6 @@
|
|||||||
package com.qiwenshare.file.service;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qiwenshare.file.api.IShareFileService;
|
import com.qiwenshare.file.api.IShareFileService;
|
||||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.net.URLDecoder;
|
|||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@ -18,20 +17,15 @@ import com.qiwenshare.file.component.FileDealComp;
|
|||||||
import com.qiwenshare.file.domain.RecoveryFile;
|
import com.qiwenshare.file.domain.RecoveryFile;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
import com.qiwenshare.file.io.QiwenFile;
|
import com.qiwenshare.file.io.QiwenFile;
|
||||||
import com.qiwenshare.file.mapper.FileMapper;
|
|
||||||
import com.qiwenshare.file.mapper.FileTypeMapper;
|
|
||||||
import com.qiwenshare.file.mapper.RecoveryFileMapper;
|
import com.qiwenshare.file.mapper.RecoveryFileMapper;
|
||||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
|
||||||
import com.qiwenshare.file.vo.file.FileListVo;
|
import com.qiwenshare.file.vo.file.FileListVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@ -39,17 +33,13 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor=Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
||||||
@Resource
|
@Resource
|
||||||
UserFileMapper userFileMapper;
|
UserFileMapper userFileMapper;
|
||||||
@Resource
|
@Resource
|
||||||
FileMapper fileMapper;
|
|
||||||
@Resource
|
|
||||||
RecoveryFileMapper recoveryFileMapper;
|
RecoveryFileMapper recoveryFileMapper;
|
||||||
@Resource
|
@Resource
|
||||||
FileTypeMapper fileTypeMapper;
|
|
||||||
@Resource
|
|
||||||
FileDealComp fileDealComp;
|
FileDealComp fileDealComp;
|
||||||
|
|
||||||
public static Executor executor = Executors.newFixedThreadPool(20);
|
public static Executor executor = Executors.newFixedThreadPool(20);
|
||||||
@ -94,32 +84,23 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId) {
|
public void updateFilepathByUserFileId(String userFileId, String newfilePath, long userId) {
|
||||||
|
UserFile userFile = userFileMapper.selectById(userFileId);
|
||||||
|
String oldfilePath = userFile.getFilePath();
|
||||||
|
String fileName = userFile.getFileName();
|
||||||
|
|
||||||
QueryWrapper<UserFile> queryWrapper = new QueryWrapper<UserFile>()
|
userFile.setFilePath(newfilePath);
|
||||||
.eq("userId", userId)
|
if (userFile.getIsDir() == 0) {
|
||||||
.eq("filePath", oldfilePath).eq("fileName", fileName);
|
String repeatFileName = fileDealComp.getRepeatFileName(userFile, userFile.getFilePath());
|
||||||
if (extendName == null) {
|
userFile.setFileName(repeatFileName);
|
||||||
queryWrapper.eq("isDir", 1);
|
|
||||||
} else {
|
|
||||||
queryWrapper.eq("extendName", extendName);
|
|
||||||
}
|
|
||||||
queryWrapper.eq("deleteFlag", 0);
|
|
||||||
List<UserFile> userFileList = userFileMapper.selectList(queryWrapper);
|
|
||||||
for (UserFile userFile : userFileList) {
|
|
||||||
userFile.setFilePath(newfilePath);
|
|
||||||
if (userFile.getIsDir() == 0) {
|
|
||||||
String repeatFileName = fileDealComp.getRepeatFileName(userFile, userFile.getFilePath());
|
|
||||||
userFile.setFileName(repeatFileName);
|
|
||||||
}
|
|
||||||
userFileMapper.updateById(userFile);
|
|
||||||
}
|
}
|
||||||
|
userFileMapper.updateById(userFile);
|
||||||
|
|
||||||
//移动子目录
|
//移动子目录
|
||||||
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
||||||
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
||||||
|
|
||||||
if (StringUtils.isEmpty(extendName)) { //为空说明是目录,则需要移动子目录
|
if (userFile.isDirectory()) { //为空说明是目录,则需要移动子目录
|
||||||
List<UserFile> list = selectUserFileByLikeRightFilePath(oldfilePath, userId);
|
List<UserFile> list = selectUserFileByLikeRightFilePath(oldfilePath, userId);
|
||||||
|
|
||||||
for (UserFile newUserFile : list) {
|
for (UserFile newUserFile : list) {
|
||||||
@ -135,43 +116,34 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userFileCopy(String oldfilePath, String newfilePath, String fileName, String extendName, long userId) {
|
public void userFileCopy(String userFileId, String newfilePath, long userId) {
|
||||||
|
UserFile userFile = userFileMapper.selectById(userFileId);
|
||||||
|
String oldfilePath = userFile.getFilePath();
|
||||||
|
String fileName = userFile.getFileName();
|
||||||
|
|
||||||
QueryWrapper<UserFile> queryWrapper = new QueryWrapper<UserFile>()
|
userFile.setFilePath(newfilePath);
|
||||||
.eq("userId", userId)
|
userFile.setUserFileId(IdUtil.getSnowflakeNextIdStr());
|
||||||
.eq("filePath", oldfilePath).eq("fileName", fileName);
|
if (userFile.getIsDir() == 0) {
|
||||||
if (extendName == null) {
|
String repeatFileName = fileDealComp.getRepeatFileName(userFile, userFile.getFilePath());
|
||||||
queryWrapper.eq("isDir", 1);
|
userFile.setFileName(repeatFileName);
|
||||||
} else {
|
|
||||||
queryWrapper.eq("extendName", extendName);
|
|
||||||
}
|
|
||||||
queryWrapper.eq("deleteFlag", 0);
|
|
||||||
List<UserFile> userFileList = userFileMapper.selectList(queryWrapper);
|
|
||||||
for (UserFile userFile : userFileList) {
|
|
||||||
userFile.setFilePath(newfilePath);
|
|
||||||
userFile.setUserFileId(IdUtil.getSnowflakeNextIdStr());
|
|
||||||
if (userFile.getIsDir() == 0) {
|
|
||||||
String repeatFileName = fileDealComp.getRepeatFileName(userFile, userFile.getFilePath());
|
|
||||||
userFile.setFileName(repeatFileName);
|
|
||||||
}
|
|
||||||
userFileMapper.insert(userFile);
|
|
||||||
}
|
}
|
||||||
|
userFileMapper.insert(userFile);
|
||||||
|
|
||||||
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
||||||
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
||||||
|
|
||||||
|
|
||||||
if (extendName == null) { //为null说明是目录,则需要移动子目录
|
if (userFile.isDirectory()) { //为null说明是目录,则需要移动子目录
|
||||||
List<UserFile> subUserFileList = userFileMapper.selectUserFileByLikeRightFilePath(oldfilePath, userId);
|
List<UserFile> subUserFileList = userFileMapper.selectUserFileByLikeRightFilePath(oldfilePath, userId);
|
||||||
|
|
||||||
for (UserFile userFile : subUserFileList) {
|
for (UserFile newUserFile : subUserFileList) {
|
||||||
userFile.setFilePath(userFile.getFilePath().replaceFirst(oldfilePath, newfilePath));
|
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(oldfilePath, newfilePath));
|
||||||
userFile.setUserFileId(IdUtil.getSnowflakeNextIdStr());
|
newUserFile.setUserFileId(IdUtil.getSnowflakeNextIdStr());
|
||||||
if (userFile.getIsDir() == 0) {
|
if (!newUserFile.isFile()) {
|
||||||
String repeatFileName = fileDealComp.getRepeatFileName(userFile, userFile.getFilePath());
|
String repeatFileName = fileDealComp.getRepeatFileName(newUserFile, newUserFile.getFilePath());
|
||||||
userFile.setFileName(repeatFileName);
|
newUserFile.setFileName(repeatFileName);
|
||||||
}
|
}
|
||||||
userFileMapper.insert(userFile);
|
userFileMapper.insert(newUserFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +193,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
String filePath = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath();
|
String filePath = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath();
|
||||||
updateFileDeleteStateByFilePath(filePath, uuid, sessionUserId);
|
updateFileDeleteStateByFilePath(filePath, uuid, sessionUserId);
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
UserFile userFileTemp = userFileMapper.selectById(userFileId);
|
UserFile userFileTemp = userFileMapper.selectById(userFileId);
|
||||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(1, FileConstant.deleteFileRandomSize))
|
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(1, FileConstant.deleteFileRandomSize))
|
||||||
@ -248,16 +220,16 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) {
|
private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
List<UserFile> fileList = selectUserFileByLikeRightFilePath(filePath, userId);
|
List<UserFile> fileList = selectUserFileByLikeRightFilePath(filePath, userId);
|
||||||
for (int i = 0; i < fileList.size(); i++){
|
for (int i = 0; i < fileList.size(); i++) {
|
||||||
UserFile userFileTemp = fileList.get(i);
|
UserFile userFileTemp = fileList.get(i);
|
||||||
//标记删除标志
|
//标记删除标志
|
||||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
|
||||||
userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize))
|
userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize))
|
||||||
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||||
.set(UserFile::getDeleteBatchNum, deleteBatchNum)
|
.set(UserFile::getDeleteBatchNum, deleteBatchNum)
|
||||||
.eq(UserFile::getUserFileId, userFileTemp.getUserFileId())
|
.eq(UserFile::getUserFileId, userFileTemp.getUserFileId())
|
||||||
.eq(UserFile::getDeleteFlag, 0);
|
.eq(UserFile::getDeleteFlag, 0);
|
||||||
userFileMapper.update(null, userFileLambdaUpdateWrapper1);
|
userFileMapper.update(null, userFileLambdaUpdateWrapper1);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package com.qiwenshare.file.service;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
|
import com.qiwenshare.common.util.HashUtils;
|
||||||
import com.qiwenshare.common.util.PasswordUtil;
|
import com.qiwenshare.common.util.PasswordUtil;
|
||||||
import com.qiwenshare.common.util.security.JwtUser;
|
import com.qiwenshare.common.util.security.JwtUser;
|
||||||
import com.qiwenshare.file.api.IUserService;
|
import com.qiwenshare.file.api.IUserService;
|
||||||
@ -17,7 +18,6 @@ import com.qiwenshare.file.mapper.UserMapper;
|
|||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.shiro.crypto.hash.SimpleHash;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
@ -91,7 +91,7 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
|||||||
|
|
||||||
|
|
||||||
String salt = PasswordUtil.getSaltValue();
|
String salt = PasswordUtil.getSaltValue();
|
||||||
String newPassword = new SimpleHash("MD5", userBean.getPassword(), salt, 1024).toHex();
|
String newPassword = HashUtils.hashHex("MD5", userBean.getPassword(), salt, 1024);
|
||||||
|
|
||||||
userBean.setSalt(salt);
|
userBean.setSalt(salt);
|
||||||
|
|
||||||
|
@ -18,17 +18,15 @@
|
|||||||
|
|
||||||
package com.qiwenshare.file.util;
|
package com.qiwenshare.file.util;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.qiwenshare.file.helper.DocumentManager;
|
import com.qiwenshare.file.helper.DocumentManager;
|
||||||
import com.qiwenshare.file.helper.FileUtility;
|
import com.qiwenshare.file.helper.FileUtility;
|
||||||
import com.qiwenshare.file.helper.ServiceConverter;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -41,7 +39,7 @@ public class FileModel
|
|||||||
public EditorConfig editorConfig;
|
public EditorConfig editorConfig;
|
||||||
public String token;
|
public String token;
|
||||||
|
|
||||||
public FileModel(String fileName, String fileUrl, String fileModifyTime, String uid, String uname, String mode)
|
public FileModel(String userFileId, String fileName, String fileUrl, String fileModifyTime, String uid, String uname, String callbackUrl, String mode)
|
||||||
{
|
{
|
||||||
if (fileName == null) fileName = "";
|
if (fileName == null) fileName = "";
|
||||||
fileName = fileName.trim();
|
fileName = fileName.trim();
|
||||||
@ -53,12 +51,12 @@ public class FileModel
|
|||||||
document.url = fileUrl;
|
document.url = fileUrl;
|
||||||
// document.urlUser = DocumentManager.GetFileUri(fileName, false);
|
// document.urlUser = DocumentManager.GetFileUri(fileName, false);
|
||||||
document.fileType = FileUtility.GetFileExtension(fileName).replace(".", "");
|
document.fileType = FileUtility.GetFileExtension(fileName).replace(".", "");
|
||||||
document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName + "/" + fileModifyTime);
|
document.key = Base64.getEncoder().encodeToString((userFileId + "_" + fileModifyTime).getBytes(StandardCharsets.UTF_8));
|
||||||
document.info = new Info();
|
document.info = new Info();
|
||||||
document.info.favorite = uid != null && !uid.isEmpty() ? uid.equals("uid-2") : null;
|
document.info.favorite = uid != null && !uid.isEmpty() ? uid.equals("uid-2") : null;
|
||||||
|
|
||||||
editorConfig = new EditorConfig(null);
|
editorConfig = new EditorConfig(null);
|
||||||
// editorConfig.callbackUrl = DocumentManager.GetCallback(fileName);
|
editorConfig.callbackUrl = callbackUrl;
|
||||||
// editorConfig.lang = null;
|
// editorConfig.lang = null;
|
||||||
|
|
||||||
if (uid != null) editorConfig.user.id = uid;
|
if (uid != null) editorConfig.user.id = uid;
|
||||||
@ -90,90 +88,90 @@ public class FileModel
|
|||||||
editorConfig.InitDesktop(document.urlUser);
|
editorConfig.InitDesktop(document.urlUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BuildToken()
|
// public void BuildToken()
|
||||||
{
|
// {
|
||||||
Map<String, Object> map = new HashMap<>();
|
// Map<String, Object> map = new HashMap<>();
|
||||||
map.put("type", type);
|
// map.put("type", type);
|
||||||
map.put("documentType", documentType);
|
// map.put("documentType", documentType);
|
||||||
map.put("document", document);
|
// map.put("document", document);
|
||||||
map.put("editorConfig", editorConfig);
|
// map.put("editorConfig", editorConfig);
|
||||||
|
//
|
||||||
|
// token = jwtComp.createJWT(map);
|
||||||
|
// }
|
||||||
|
|
||||||
token = DocumentManager.CreateToken(map);
|
// public String[] GetHistory()
|
||||||
}
|
// {
|
||||||
|
// String histDir = DocumentManager.HistoryDir(DocumentManager.StoragePath(document.title, null));
|
||||||
public String[] GetHistory()
|
// if (DocumentManager.GetFileVersion(histDir) > 0) {
|
||||||
{
|
// Integer curVer = DocumentManager.GetFileVersion(histDir);
|
||||||
String histDir = DocumentManager.HistoryDir(DocumentManager.StoragePath(document.title, null));
|
//
|
||||||
if (DocumentManager.GetFileVersion(histDir) > 0) {
|
// List<Object> hist = new ArrayList<>();
|
||||||
Integer curVer = DocumentManager.GetFileVersion(histDir);
|
// Map<String, Object> histData = new HashMap<String, Object>();
|
||||||
|
//
|
||||||
List<Object> hist = new ArrayList<>();
|
// for (Integer i = 1; i <= curVer; i++) {
|
||||||
Map<String, Object> histData = new HashMap<String, Object>();
|
// Map<String, Object> obj = new HashMap<String, Object>();
|
||||||
|
// Map<String, Object> dataObj = new HashMap<String, Object>();
|
||||||
for (Integer i = 1; i <= curVer; i++) {
|
// String verDir = DocumentManager.VersionDir(histDir, i);
|
||||||
Map<String, Object> obj = new HashMap<String, Object>();
|
//
|
||||||
Map<String, Object> dataObj = new HashMap<String, Object>();
|
// try {
|
||||||
String verDir = DocumentManager.VersionDir(histDir, i);
|
// String key = null;
|
||||||
|
//
|
||||||
try {
|
// key = i == curVer ? document.key : readFileToEnd(new File(verDir + File.separator + "key.txt"));
|
||||||
String key = null;
|
//
|
||||||
|
// obj.put("key", key);
|
||||||
key = i == curVer ? document.key : readFileToEnd(new File(verDir + File.separator + "key.txt"));
|
// obj.put("version", i);
|
||||||
|
//
|
||||||
obj.put("key", key);
|
// if (i == 1) {
|
||||||
obj.put("version", i);
|
// String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json"));
|
||||||
|
// JSONObject json = JSONObject.parseObject(createdInfo);
|
||||||
if (i == 1) {
|
// obj.put("created", json.get("created"));
|
||||||
String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json"));
|
// Map<String, Object> user = new HashMap<String, Object>();
|
||||||
JSONObject json = JSONObject.parseObject(createdInfo);
|
// user.put("id", json.get("id"));
|
||||||
obj.put("created", json.get("created"));
|
// user.put("name", json.get("name"));
|
||||||
Map<String, Object> user = new HashMap<String, Object>();
|
// obj.put("user", user);
|
||||||
user.put("id", json.get("id"));
|
// }
|
||||||
user.put("name", json.get("name"));
|
//
|
||||||
obj.put("user", user);
|
// dataObj.put("key", key);
|
||||||
}
|
// dataObj.put("url", i == curVer ? document.url : DocumentManager.GetPathUri(verDir + File.separator + "prev" + FileUtility.GetFileExtension(document.title)));
|
||||||
|
// dataObj.put("version", i);
|
||||||
dataObj.put("key", key);
|
//
|
||||||
dataObj.put("url", i == curVer ? document.url : DocumentManager.GetPathUri(verDir + File.separator + "prev" + FileUtility.GetFileExtension(document.title)));
|
// if (i > 1) {
|
||||||
dataObj.put("version", i);
|
// JSONObject changes = JSONObject.parseObject(readFileToEnd(new File(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "changes.json")));
|
||||||
|
// JSONObject change = (JSONObject) ((JSONArray) changes.get("changes")).get(0);
|
||||||
if (i > 1) {
|
//
|
||||||
JSONObject changes = JSONObject.parseObject(readFileToEnd(new File(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "changes.json")));
|
// obj.put("changes", changes.get("changes"));
|
||||||
JSONObject change = (JSONObject) ((JSONArray) changes.get("changes")).get(0);
|
// obj.put("serverVersion", changes.get("serverVersion"));
|
||||||
|
// obj.put("created", change.get("created"));
|
||||||
obj.put("changes", changes.get("changes"));
|
// obj.put("user", change.get("user"));
|
||||||
obj.put("serverVersion", changes.get("serverVersion"));
|
//
|
||||||
obj.put("created", change.get("created"));
|
// Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 2));
|
||||||
obj.put("user", change.get("user"));
|
// Map<String, Object> prevInfo = new HashMap<String, Object>();
|
||||||
|
// prevInfo.put("key", prev.get("key"));
|
||||||
Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 2));
|
// prevInfo.put("url", prev.get("url"));
|
||||||
Map<String, Object> prevInfo = new HashMap<String, Object>();
|
// dataObj.put("previous", prevInfo);
|
||||||
prevInfo.put("key", prev.get("key"));
|
// dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip"));
|
||||||
prevInfo.put("url", prev.get("url"));
|
// }
|
||||||
dataObj.put("previous", prevInfo);
|
//
|
||||||
dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip"));
|
// if (DocumentManager.TokenEnabled())
|
||||||
}
|
// {
|
||||||
|
// dataObj.put("token", jwtComp.createJWT(dataObj));
|
||||||
if (DocumentManager.TokenEnabled())
|
// }
|
||||||
{
|
//
|
||||||
dataObj.put("token", DocumentManager.CreateToken(dataObj));
|
// hist.add(obj);
|
||||||
}
|
// histData.put(Integer.toString(i - 1), dataObj);
|
||||||
|
//
|
||||||
hist.add(obj);
|
// } catch (Exception ex) { }
|
||||||
histData.put(Integer.toString(i - 1), dataObj);
|
// }
|
||||||
|
//
|
||||||
} catch (Exception ex) { }
|
// Map<String, Object> histObj = new HashMap<String, Object>();
|
||||||
}
|
// histObj.put("currentVersion", curVer);
|
||||||
|
// histObj.put("history", hist);
|
||||||
Map<String, Object> histObj = new HashMap<String, Object>();
|
//
|
||||||
histObj.put("currentVersion", curVer);
|
// Gson gson = new Gson();
|
||||||
histObj.put("history", hist);
|
// return new String[] { gson.toJson(histObj), gson.toJson(histData) };
|
||||||
|
// }
|
||||||
Gson gson = new Gson();
|
// return new String[] { "", "" };
|
||||||
return new String[] { gson.toJson(histObj), gson.toJson(histData) };
|
// }
|
||||||
}
|
|
||||||
return new String[] { "", "" };
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readFileToEnd(File file) {
|
private String readFileToEnd(File file) {
|
||||||
String output = "";
|
String output = "";
|
||||||
|
@ -1,268 +0,0 @@
|
|||||||
package com.qiwenshare.file.util;
|
|
||||||
|
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.config.RequestConfig;
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
|
||||||
import org.apache.http.conn.ssl.TrustStrategy;
|
|
||||||
import org.apache.http.entity.StringEntity;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.SSLSession;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
public class HttpsUtils {
|
|
||||||
private static final int MAX_TIMEOUT = 7000;
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(HttpsUtils.class);
|
|
||||||
private static PoolingHttpClientConnectionManager connMgr;
|
|
||||||
private static RequestConfig requestConfig;
|
|
||||||
|
|
||||||
static {
|
|
||||||
// 设置连接池
|
|
||||||
connMgr = new PoolingHttpClientConnectionManager();
|
|
||||||
// 设置连接池大小
|
|
||||||
connMgr.setMaxTotal(100);
|
|
||||||
connMgr.setDefaultMaxPerRoute(connMgr.getMaxTotal());
|
|
||||||
// Validate connections after 1 sec of inactivity
|
|
||||||
connMgr.setValidateAfterInactivity(1000);
|
|
||||||
RequestConfig.Builder configBuilder = RequestConfig.custom();
|
|
||||||
// 设置连接超时
|
|
||||||
configBuilder.setConnectTimeout(MAX_TIMEOUT);
|
|
||||||
// 设置读取超时
|
|
||||||
configBuilder.setSocketTimeout(MAX_TIMEOUT);
|
|
||||||
// 设置从连接池获取连接实例的超时
|
|
||||||
configBuilder.setConnectionRequestTimeout(MAX_TIMEOUT);
|
|
||||||
|
|
||||||
requestConfig = configBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 GET 请求(HTTP),不带输入数据
|
|
||||||
*
|
|
||||||
* @param url url
|
|
||||||
* @return 返回
|
|
||||||
*/
|
|
||||||
public static InputStream doGet(String url) {
|
|
||||||
HttpEntity httpEntity = doGetHttpEntity(url, new HashMap<String, Object>());
|
|
||||||
InputStream inputStream = null;
|
|
||||||
try {
|
|
||||||
inputStream = httpEntity.getContent();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return inputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String doGetString(String url, Map<String, Object> params) {
|
|
||||||
HttpEntity httpEntity = doGetHttpEntity(url, params);
|
|
||||||
String result = null;
|
|
||||||
try {
|
|
||||||
result = EntityUtils.toString(httpEntity, "UTF-8");
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String doGetString(String url) {
|
|
||||||
HttpEntity httpEntity = doGetHttpEntity(url, new HashMap<String, Object>());
|
|
||||||
String result = null;
|
|
||||||
try {
|
|
||||||
result = EntityUtils.toString(httpEntity, "UTF-8");
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 GET 请求(HTTP),K-V形式
|
|
||||||
*
|
|
||||||
* @param url url
|
|
||||||
* @param params 参数
|
|
||||||
* @return 返回
|
|
||||||
*/
|
|
||||||
public static HttpEntity doGetHttpEntity(String url, Map<String, Object> params) {
|
|
||||||
String apiUrl = url;
|
|
||||||
StringBuffer param = new StringBuffer();
|
|
||||||
int i = 0;
|
|
||||||
for (String key : params.keySet()) {
|
|
||||||
if (i == 0)
|
|
||||||
param.append("?");
|
|
||||||
else
|
|
||||||
param.append("&");
|
|
||||||
param.append(key).append("=").append(params.get(key));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
apiUrl += param;
|
|
||||||
String result = null;
|
|
||||||
HttpClient httpClient = null;
|
|
||||||
if (apiUrl.startsWith("https")) {
|
|
||||||
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
|
|
||||||
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
|
|
||||||
} else {
|
|
||||||
httpClient = HttpClients.createDefault();
|
|
||||||
}
|
|
||||||
InputStream instream = null;
|
|
||||||
HttpEntity httpEntity = null;
|
|
||||||
try {
|
|
||||||
HttpGet httpGet = new HttpGet(apiUrl);
|
|
||||||
httpGet.setHeader("Referer", "https://y.qq.com/");
|
|
||||||
HttpResponse response = httpClient.execute(httpGet);
|
|
||||||
httpEntity = response.getEntity();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
return httpEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 POST 请求(HTTP),不带输入数据
|
|
||||||
*
|
|
||||||
* @param apiUrl url
|
|
||||||
* @return 返回
|
|
||||||
*/
|
|
||||||
public static String doPost(String apiUrl) {
|
|
||||||
return doPost(apiUrl, new HashMap<String, Object>());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 POST 请求,K-V形式
|
|
||||||
*
|
|
||||||
* @param apiUrl API接口URL
|
|
||||||
* @param params 参数map
|
|
||||||
* @return 返回
|
|
||||||
*/
|
|
||||||
public static String doPost(String apiUrl, Map<String, Object> params) {
|
|
||||||
CloseableHttpClient httpClient = null;
|
|
||||||
if (apiUrl.startsWith("https")) {
|
|
||||||
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
|
|
||||||
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
|
|
||||||
} else {
|
|
||||||
httpClient = HttpClients.createDefault();
|
|
||||||
}
|
|
||||||
String httpStr = null;
|
|
||||||
HttpPost httpPost = new HttpPost(apiUrl);
|
|
||||||
CloseableHttpResponse response = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
httpPost.setConfig(requestConfig);
|
|
||||||
List<NameValuePair> pairList = new ArrayList<>(params.size());
|
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
|
||||||
NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
|
|
||||||
pairList.add(pair);
|
|
||||||
}
|
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
|
|
||||||
response = httpClient.execute(httpPost);
|
|
||||||
HttpEntity entity = response.getEntity();
|
|
||||||
httpStr = EntityUtils.toString(entity, "UTF-8");
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (response != null) {
|
|
||||||
try {
|
|
||||||
EntityUtils.consume(response.getEntity());
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return httpStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 POST 请求,JSON形式
|
|
||||||
*
|
|
||||||
* @param apiUrl url
|
|
||||||
* @param json json对象
|
|
||||||
* @return 返回
|
|
||||||
*/
|
|
||||||
public static String doPost(String apiUrl, Object json) {
|
|
||||||
CloseableHttpClient httpClient = null;
|
|
||||||
if (apiUrl.startsWith("https")) {
|
|
||||||
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
|
|
||||||
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
|
|
||||||
} else {
|
|
||||||
httpClient = HttpClients.createDefault();
|
|
||||||
}
|
|
||||||
String httpStr = null;
|
|
||||||
HttpPost httpPost = new HttpPost(apiUrl);
|
|
||||||
CloseableHttpResponse response = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
httpPost.setConfig(requestConfig);
|
|
||||||
StringEntity stringEntity = new StringEntity(json.toString(), "UTF-8");// 解决中文乱码问题
|
|
||||||
stringEntity.setContentEncoding("UTF-8");
|
|
||||||
stringEntity.setContentType("application/json");
|
|
||||||
httpPost.setEntity(stringEntity);
|
|
||||||
response = httpClient.execute(httpPost);
|
|
||||||
HttpEntity entity = response.getEntity();
|
|
||||||
httpStr = EntityUtils.toString(entity, "UTF-8");
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (response != null) {
|
|
||||||
try {
|
|
||||||
EntityUtils.consume(response.getEntity());
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return httpStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建SSL安全连接
|
|
||||||
*
|
|
||||||
* @return 返回
|
|
||||||
*/
|
|
||||||
private static SSLConnectionSocketFactory createSSLConnSocketFactory() {
|
|
||||||
SSLConnectionSocketFactory sslsf = null;
|
|
||||||
try {
|
|
||||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
|
||||||
|
|
||||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}).build();
|
|
||||||
sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean verify(String arg0, SSLSession arg1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (GeneralSecurityException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
return sslsf;
|
|
||||||
}
|
|
||||||
}
|
|
@ -152,9 +152,6 @@ INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExt
|
|||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (53, 2, 'css');
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (53, 2, 'css');
|
||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (54, 2, 'json');
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (54, 2, 'json');
|
||||||
|
|
||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (53, 2, 'md');
|
|
||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (54, 2, 'markdown');
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (55, 3, 'avi');
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (55, 3, 'avi');
|
||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (56, 3, 'mp4');
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (56, 3, 'mp4');
|
||||||
@ -173,4 +170,5 @@ INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExt
|
|||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (68, 4, 'aac');
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (68, 4, 'aac');
|
||||||
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (69, 4, 'flac');
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (69, 4, 'flac');
|
||||||
|
|
||||||
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (70, 2, 'md');
|
||||||
|
INSERT INTO `fileclassification` (`fileClassificationId`, `fileTypeId`, `fileExtendName`) VALUES (71, 2, 'markdown');
|
||||||
|
Loading…
Reference in New Issue
Block a user