Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
906b219e
Unverified
Commit
906b219e
authored
May 21, 2020
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
新增 Markdown zip 导入方式 #128
parent
7791dba1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
11 deletions
+36
-11
src/main/java/org/b3log/solo/processor/console/AdminConsole.java
...n/java/org/b3log/solo/processor/console/AdminConsole.java
+15
-7
src/main/java/org/b3log/solo/service/ImportService.java
src/main/java/org/b3log/solo/service/ImportService.java
+11
-4
src/main/resources/lang_en_US.properties
src/main/resources/lang_en_US.properties
+5
-0
src/main/resources/lang_zh_CN.properties
src/main/resources/lang_zh_CN.properties
+5
-0
No files found.
src/main/java/org/b3log/solo/processor/console/AdminConsole.java
View file @
906b219e
...
...
@@ -232,16 +232,14 @@ public class AdminConsole {
* @param context the specified context
*/
public
void
importMarkdownZip
(
final
RequestContext
context
)
{
context
.
renderJSON
();
final
Request
request
=
context
.
getRequest
();
final
FileUpload
file
=
request
.
getFileUpload
(
"file"
);
final
String
fileName
=
file
.
getFilename
();
String
suffix
=
StringUtils
.
substringAfterLast
(
fileName
,
"."
);
if
(
StringUtils
.
isBlank
(
suffix
))
{
// TODO
return
;
}
if
(!
StringUtils
.
equalsIgnoreCase
(
suffix
,
"zip"
))
{
// TODO
context
.
renderMsg
(
langPropsService
.
get
(
"allowZipOnlyLabel"
));
return
;
}
...
...
@@ -255,12 +253,22 @@ public class AdminConsole {
final
String
unzipPath
=
tmpDir
+
File
.
separator
+
"solo-import-"
+
date
;
final
File
unzipDir
=
new
File
(
unzipPath
);
ZipUtil
.
unzip
(
zipFile
,
unzipDir
);
importService
.
importMarkdownDir
(
unzipDir
);
final
JSONObject
result
=
importService
.
importMarkdownDir
(
unzipDir
);
final
int
succCount
=
result
.
optInt
(
"succCount"
);
final
int
failCount
=
result
.
optInt
(
"failCount"
);
FileUtils
.
deleteQuietly
(
zipFile
);
FileUtils
.
deleteQuietly
(
unzipDir
);
context
.
renderJSON
(
true
);
String
msg
=
langPropsService
.
get
(
"importSuccLabel"
);
msg
=
msg
.
replace
(
"${succCount}"
,
succCount
+
""
);
if
(
0
<
failCount
)
{
msg
=
langPropsService
.
get
(
"importFailLabel"
);
msg
=
msg
.
replace
(
"${failCount}"
,
failCount
+
""
);
}
context
.
renderMsg
(
msg
);
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Imports markdown file failed"
,
e
);
return
;
context
.
renderMsg
(
langPropsService
.
get
(
"importFailedSeeLogLabel"
))
;
}
}
...
...
src/main/java/org/b3log/solo/service/ImportService.java
View file @
906b219e
...
...
@@ -87,13 +87,19 @@ public class ImportService {
* Imports markdown files under the specified markdown files dir.
*
* @param markdownsDir the specified markdown files dir
* @return <pre>
* {
* "failCount": int,
* "succCnt": int
* }
* </pre>
*/
public
void
importMarkdownDir
(
final
File
markdownsDir
)
{
public
JSONObject
importMarkdownDir
(
final
File
markdownsDir
)
{
LOGGER
.
debug
(
"Import directory ["
+
markdownsDir
.
getPath
()
+
"]"
);
final
JSONObject
admin
=
userQueryService
.
getAdmin
();
if
(
null
==
admin
)
{
// Not init yet
return
;
return
null
;
}
final
String
adminId
=
admin
.
optString
(
Keys
.
OBJECT_ID
);
...
...
@@ -102,7 +108,7 @@ public class ImportService {
final
Set
<
String
>
failSet
=
new
TreeSet
<>();
final
Collection
<
File
>
mds
=
FileUtils
.
listFiles
(
markdownsDir
,
new
String
[]{
"md"
},
true
);
if
(
mds
.
isEmpty
())
{
return
;
return
null
;
}
for
(
final
File
md
:
mds
)
{
...
...
@@ -132,7 +138,7 @@ public class ImportService {
}
if
(
0
==
succCnt
&&
0
==
failCnt
)
{
return
;
return
null
;
}
final
StringBuilder
logBuilder
=
new
StringBuilder
();
...
...
@@ -147,6 +153,7 @@ public class ImportService {
logBuilder
.
append
(
" :p"
);
}
LOGGER
.
info
(
logBuilder
.
toString
());
return
new
JSONObject
().
put
(
"failCount"
,
failCnt
).
put
(
"succCount"
,
succCnt
);
}
private
JSONObject
parseArticle
(
final
String
fileName
,
String
fileContent
)
{
...
...
src/main/resources/lang_en_US.properties
View file @
906b219e
...
...
@@ -18,6 +18,11 @@
# Author: Dongxu Wang
#
importSuccLabel
=
After importing, a total of $ {succCount} articles have been successfully imported
importFailLabel
=
After importing, $ {failCount} articles failed to be imported, please check the log for details
allowZipOnlyLabel
=
Only supports Zip file
importFailedSeeLogLabel
=
Import failed, please check the log for details
uploadMarkdownZipLabel
=
Upload Markdown Zip
editorModeSVLabel
=
Split View
editorModeIRLabel
=
Instant Rendering
editorModeWYSIWYGLabel
=
WYSIWYG
...
...
src/main/resources/lang_zh_CN.properties
View file @
906b219e
...
...
@@ -18,6 +18,11 @@
# Author: Dongxu Wang
#
importSuccLabel
=
\u
5BFC
\u5165\u
5B8C
\u
6BD5
\u
FF0C
\u
4E00
\u5171\u6210\u
529F
\u
5BFC
\u5165
${succCount}
\u
7BC7
\u6587\u
7AE0
importFailLabel
=
\u
5BFC
\u5165\u
5B8C
\u
6BD5
\u
FF0C
\u5176\u
4E2D ${failCount}
\u
7BC7
\u6587\u
7AE0
\u
5BFC
\u5165\u5931\u
8D25
\u
FF0C
\u
8BF7
\u
67E5
\u
770B
\u
65E5
\u
5FD7
\u
4E86
\u
89E3
\u
62A5
\u9519\u
8BE6
\u
60C5
allowZipOnlyLabel
=
\u
4EC5
\u
652F
\u6301
Zip
\u6587\u
4EF6
importFailedSeeLogLabel
=
\u
5BFC
\u5165\u5931\u
8D25
\u
FF0C
\u
8BF7
\u
67E5
\u
770B
\u
65E5
\u
5FD7
\u
4E86
\u
89E3
\u
62A5
\u9519\u
8BE6
\u
60C5
uploadMarkdownZipLabel
=
\u
4E0A
\u
4F20 Markdown Zip
\u5305
editorModeSVLabel
=
\u5206\u
5C4F
\u9884\u
89C8
editorModeIRLabel
=
\u5373\u
65F6
\u
6E32
\u
67D3
editorModeWYSIWYGLabel
=
\u6240\u
89C1
\u5373\u6240\u
5F97
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment