Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IEQEFCR
halo
提交
001d9f88
H
halo
项目概览
IEQEFCR
/
halo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
halo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
001d9f88
编写于
4月 16, 2019
作者:
RYAN0UP
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complates upload theme api.
上级
297b751e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
0 deletion
+59
-0
src/main/java/run/halo/app/service/ThemeService.java
src/main/java/run/halo/app/service/ThemeService.java
+9
-0
src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
...main/java/run/halo/app/service/impl/ThemeServiceImpl.java
+44
-0
src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java
...un/halo/app/web/controller/admin/api/ThemeController.java
+6
-0
未找到文件。
src/main/java/run/halo/app/service/ThemeService.java
浏览文件 @
001d9f88
package
run.halo.app.service
;
import
org.springframework.lang.NonNull
;
import
org.springframework.web.multipart.MultipartFile
;
import
run.halo.app.handler.theme.support.Group
;
import
run.halo.app.handler.theme.support.ThemeProperty
;
import
run.halo.app.model.support.ThemeFile
;
...
...
@@ -200,4 +201,12 @@ public interface ThemeService {
*/
@NonNull
ThemeProperty
activeTheme
(
@NonNull
String
themeId
);
/**
* Upload theme.
* @param file multipart file must not be null
* @return theme info
*/
@NonNull
ThemeProperty
upload
(
@NonNull
MultipartFile
file
);
}
src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
浏览文件 @
001d9f88
package
run.halo.app.service.impl
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.file.FileReader
;
import
cn.hutool.core.io.file.FileWriter
;
import
cn.hutool.core.text.StrBuilder
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.ZipUtil
;
import
freemarker.template.Configuration
;
import
freemarker.template.TemplateModelException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.http.MediaType
;
import
org.springframework.lang.NonNull
;
import
org.springframework.lang.Nullable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
run.halo.app.cache.StringCacheStore
;
import
run.halo.app.config.properties.HaloProperties
;
import
run.halo.app.exception.*
;
import
run.halo.app.handler.file.FileHandler
;
import
run.halo.app.handler.theme.ThemeConfigResolver
;
import
run.halo.app.handler.theme.ThemePropertyResolver
;
import
run.halo.app.handler.theme.support.Group
;
...
...
@@ -23,11 +28,14 @@ import run.halo.app.handler.theme.support.ThemeProperty;
import
run.halo.app.model.properties.PrimaryProperties
;
import
run.halo.app.model.support.HaloConst
;
import
run.halo.app.model.support.ThemeFile
;
import
run.halo.app.model.support.UploadResult
;
import
run.halo.app.service.OptionService
;
import
run.halo.app.service.ThemeService
;
import
run.halo.app.utils.FilenameUtils
;
import
run.halo.app.utils.JsonUtils
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
...
...
@@ -314,6 +322,42 @@ public class ThemeServiceImpl implements ThemeService {
return
themeProperty
;
}
/**
* Upload theme.
*
* @param file multipart file must not be null
* @return theme info
*/
@Override
public
ThemeProperty
upload
(
MultipartFile
file
)
{
Assert
.
notNull
(
file
,
"Multipart file must not be null"
);
// Get upload path
Path
uploadPath
=
Paths
.
get
(
workDir
.
toString
(),
file
.
getOriginalFilename
());
final
String
originalBasename
=
FilenameUtils
.
getBasename
(
file
.
getOriginalFilename
());
log
.
info
(
"Uploading theme to directory: [{}]"
,
uploadPath
.
toString
());
try
{
// Create directory
Files
.
createDirectories
(
uploadPath
.
getParent
());
Files
.
createFile
(
uploadPath
);
file
.
transferTo
(
uploadPath
);
// Unzip theme package
ZipUtil
.
unzip
(
uploadPath
.
toFile
(),
uploadPath
.
getParent
().
toFile
());
// Delete theme package
FileUtil
.
del
(
uploadPath
.
toFile
());
return
getProperty
(
Paths
.
get
(
workDir
.
toString
(),
originalBasename
));
}
catch
(
IOException
e
)
{
log
.
error
(
"Failed to upload theme to local: "
+
uploadPath
,
e
);
throw
new
ServiceException
(
"Failed to upload theme to local"
).
setErrorData
(
uploadPath
);
}
}
/**
* Lists theme files as tree view.
*
...
...
src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java
浏览文件 @
001d9f88
...
...
@@ -2,6 +2,7 @@ package run.halo.app.web.controller.admin.api;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
run.halo.app.handler.theme.support.Group
;
import
run.halo.app.model.support.BaseResponse
;
import
run.halo.app.model.support.ThemeFile
;
...
...
@@ -115,4 +116,9 @@ public class ThemeController {
themeService
.
deleteTheme
(
themeId
);
}
@PostMapping
(
"upload"
)
@ApiOperation
(
"Upload theme"
)
public
ThemeProperty
uploadTheme
(
@RequestPart
(
"file"
)
MultipartFile
file
){
return
themeService
.
upload
(
file
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录