Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdisk
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdisk
提交
f3be8846
提交
f3be8846
编写于
7月 19, 2022
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
批量下载文件去除目录,支持文件平铺展示
上级
6ce1236f
变更
4
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
101 行增加
和
8 行删除
+101
-8
DiskCoreService.java
...ibizlab/core/disk/extensions/service/DiskCoreService.java
+45
-4
apiSecurityConfig.java
...rc/main/java/cn/ibizlab/api/config/apiSecurityConfig.java
+1
-0
DiskCoreResource.java
...java/cn/ibizlab/api/rest/extensions/DiskCoreResource.java
+8
-4
ZipUtils.java
...k-util/src/main/java/cn/ibizlab/util/helper/ZipUtils.java
+47
-0
未找到文件。
ibzdisk-core/src/main/java/cn/ibizlab/core/disk/extensions/service/DiskCoreService.java
浏览文件 @
f3be8846
...
...
@@ -28,10 +28,7 @@ import java.security.MessageDigest;
import
java.security.NoSuchAlgorithmException
;
import
java.sql.Wrapper
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.*
;
import
java.util.zip.ZipOutputStream
;
@Primary
...
...
@@ -204,6 +201,50 @@ public class DiskCoreService {
}
/**
* 批量压缩文件,压缩包内所有文件平铺展示,子目录文件重名时,通过序号区分(如:文件名.txt; 件名(1).txt )
* @param strCat
* @param list
* @return
*/
public
File
getFile2
(
String
strCat
,
List
<
JsonNode
>
list
)
{
if
(
ObjectUtils
.
isEmpty
(
list
))
{
throw
new
InternalServerErrorException
(
"未传入文件清单"
);
}
List
<
File
>
fileList
=
new
ArrayList
<>();
for
(
JsonNode
item
:
list
)
{
if
(
item
instanceof
ObjectNode
)
{
ObjectNode
map
=
(
ObjectNode
)
item
;
item
=
map
.
get
(
"id"
);
}
fileList
.
add
(
this
.
getFile
(
strCat
,
item
.
asText
()));
}
try
{
Map
<
String
,
List
<
File
>>
zipFileMap
=
new
HashMap
<>();
//压缩文件集合
File
tempFile
=
File
.
createTempFile
(
"oss"
,
".zip"
);
try
(
ZipOutputStream
zipOutputStream
=
new
ZipOutputStream
(
new
FileOutputStream
(
tempFile
)))
{
for
(
File
file
:
fileList
)
{
if
(
file
.
getParentFile
()
==
null
||
file
.
getParentFile
().
getParentFile
()
==
null
)
{
throw
new
Exception
(
"文件路径不正确"
);
}
long
nTime
=
System
.
currentTimeMillis
();
ZipUtils
.
zip2
(
file
,
zipOutputStream
,
zipFileMap
);
log
.
debug
(
String
.
format
(
"压缩文件[%1$s]耗时[%2$s]ms"
,
file
.
getAbsolutePath
(),
System
.
currentTimeMillis
()
-
nTime
));
}
zipOutputStream
.
flush
();
zipOutputStream
.
close
();
}
return
tempFile
;
}
catch
(
Throwable
ex
)
{
throw
new
InternalServerErrorException
(
String
.
format
(
"生成压缩文件发生异常,%1$s"
,
ex
.
getMessage
()));
}
}
public
File
getFileById
(
String
fileId
)
{
SDFile
sdFile
=
sdFileService
.
getById
(
fileId
);
if
(
sdFile
!=
null
&&(!
StringUtils
.
isEmpty
(
sdFile
.
getFilePath
()))){
...
...
ibzdisk-provider/ibzdisk-provider-api/src/main/java/cn/ibizlab/api/config/apiSecurityConfig.java
浏览文件 @
f3be8846
...
...
@@ -123,6 +123,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/"
+
uploadpath
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
.
antMatchers
(
"/net-disk/download/**"
).
permitAll
()
.
antMatchers
(
"/net-disk/download2/**"
).
permitAll
()
.
antMatchers
(
"/net-disk/**view/**"
).
permitAll
()
.
antMatchers
(
"/net-disk/edit/**"
).
permitAll
();
...
...
ibzdisk-provider/ibzdisk-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/DiskCoreResource.java
浏览文件 @
f3be8846
...
...
@@ -13,7 +13,6 @@ import io.swagger.annotations.ApiOperation;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.StringUtils
;
...
...
@@ -23,9 +22,6 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Base64
;
import
java.util.Hashtable
;
import
java.util.List
;
...
...
@@ -110,6 +106,14 @@ public class DiskCoreResource
this
.
sendRespose
(
response
,
file
);
}
@PostMapping
(
value
=
"net-disk/download2"
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
void
download2
(
@RequestBody
List
<
JsonNode
>
list
,
HttpServletRequest
request
,
HttpServletResponse
response
){
File
file
=
diskCoreService
.
getFile2
(
null
,
list
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
getFileName
(
request
.
getHeader
(
"User-Agent"
),
file
.
getName
()));
this
.
sendRespose
(
response
,
file
);
}
@GetMapping
(
value
=
{
"net-disk/openview/{folder}/{id}/{name}.{ext}"
,
"net-disk/files/{folder}/{id}/{name}.{ext}"
})
@ResponseStatus
(
HttpStatus
.
OK
)
public
void
open
(
@PathVariable
(
"folder"
)
String
folder
,
@PathVariable
(
"id"
)
String
id
,
...
...
ibzdisk-util/src/main/java/cn/ibizlab/util/helper/ZipUtils.java
浏览文件 @
f3be8846
package
cn
.
ibizlab
.
util
.
helper
;
import
org.springframework.util.DigestUtils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
...
...
@@ -82,8 +85,52 @@ public class ZipUtils {
}
}
}
}
public
static
void
zip2
(
File
file
,
ZipOutputStream
zipOutputStream
,
java
.
util
.
Map
<
String
,
List
<
File
>>
zipFileMaps
)
throws
IOException
{
String
zipFileName
=
file
.
getName
();
if
(
file
.
isFile
())
{
String
fileId
=
DigestUtils
.
md5DigestAsHex
(
file
.
getName
().
getBytes
());
if
(
zipFileMaps
.
containsKey
(
fileId
)){
String
prefix
=
zipFileName
.
contains
(
"."
)?
zipFileName
.
substring
(
0
,
zipFileName
.
lastIndexOf
(
"."
)):
null
;
String
suffix
=
zipFileName
.
contains
(
"."
)?
zipFileName
.
substring
(
zipFileName
.
lastIndexOf
(
"."
))
:
null
;
zipFileName
=
String
.
format
(
"%s(%s)%s"
,
prefix
,
zipFileMaps
.
get
(
fileId
).
size
(),
suffix
);
zipFileMaps
.
get
(
fileId
).
add
(
file
);
log
.
debug
(
String
.
format
(
"压缩文件中已存在重复文件名,文件[%s]被重命名为[%s]"
,
file
.
getAbsoluteFile
(),
zipFileName
));
}
else
{
zipFileMaps
.
put
(
fileId
,
new
ArrayList
(){{
add
(
file
);}});
}
ByteBuffer
byteBuffer
=
ByteBuffer
.
allocate
(
1024
);
ZipEntry
zipEntry
=
new
ZipEntry
(
zipFileName
);
zipEntry
.
setTime
(
file
.
lastModified
());
zipOutputStream
.
putNextEntry
(
zipEntry
);
try
(
FileInputStream
fis
=
new
FileInputStream
(
file
);
FileChannel
channel
=
fis
.
getChannel
();)
{
while
(
true
)
{
byteBuffer
.
clear
();
int
read
=
channel
.
read
(
byteBuffer
);
if
(
read
==
-
1
)
break
;
zipOutputStream
.
write
(
byteBuffer
.
array
(),
0
,
read
);
}
}
zipOutputStream
.
closeEntry
();
}
else
{
File
[]
files
=
file
.
listFiles
();
if
(
files
==
null
||
files
.
length
==
0
)
{
ZipEntry
zipEntry
=
new
ZipEntry
(
zipFileName
);
zipEntry
.
setTime
(
file
.
lastModified
());
zipOutputStream
.
putNextEntry
(
zipEntry
);
zipOutputStream
.
closeEntry
();
}
else
{
for
(
File
item
:
files
)
{
zip2
(
item
,
zipOutputStream
,
zipFileMaps
);
}
}
}
}
public
static
void
unzip
(
File
zipFile
,
File
dstFolder
)
throws
IOException
{
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录