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
8675f5bd
Unverified
Commit
8675f5bd
authored
Jan 29, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
#12514
parent
147746a2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
17 deletions
+47
-17
src/main/java/org/b3log/solo/model/Option.java
src/main/java/org/b3log/solo/model/Option.java
+16
-6
src/main/java/org/b3log/solo/service/CronMgmtService.java
src/main/java/org/b3log/solo/service/CronMgmtService.java
+1
-1
src/main/java/org/b3log/solo/service/PageMgmtService.java
src/main/java/org/b3log/solo/service/PageMgmtService.java
+20
-3
src/main/java/org/b3log/solo/util/Solos.java
src/main/java/org/b3log/solo/util/Solos.java
+10
-7
No files found.
src/main/java/org/b3log/solo/model/Option.java
View file @
8675f5bd
...
@@ -319,37 +319,47 @@ public final class Option {
...
@@ -319,37 +319,47 @@ public final class Option {
*/
*/
public
static
final
String
ID_C_OAUTH_GITHUB
=
"oauthGitHub"
;
public
static
final
String
ID_C_OAUTH_GITHUB
=
"oauthGitHub"
;
/**
* Key of GitHub repos.
*/
public
static
final
String
ID_C_GITHUB_REPOS
=
"githubRepos"
;
// Category constants
// Category constants
/**
/**
* Qiniu.
*
Category -
Qiniu.
*/
*/
public
static
final
String
CATEGORY_C_QINIU
=
"qiniu"
;
public
static
final
String
CATEGORY_C_QINIU
=
"qiniu"
;
/**
/**
* Aliyun
*
Category -
Aliyun
*/
*/
public
static
final
String
CATEGORY_C_ALIYUN
=
"aliyun"
;
public
static
final
String
CATEGORY_C_ALIYUN
=
"aliyun"
;
/**
/**
* Cloud object storage
* C
ategory - C
loud object storage
*/
*/
public
static
final
String
CATEGORY_C_CLOU_STORAGE
=
"cloudStorage"
;
public
static
final
String
CATEGORY_C_CLOU_STORAGE
=
"cloudStorage"
;
/**
/**
* Preference.
*
Category -
Preference.
*/
*/
public
static
final
String
CATEGORY_C_PREFERENCE
=
"preference"
;
public
static
final
String
CATEGORY_C_PREFERENCE
=
"preference"
;
/**
/**
* Statistic.
*
Category -
Statistic.
*/
*/
public
static
final
String
CATEGORY_C_STATISTIC
=
"statistic"
;
public
static
final
String
CATEGORY_C_STATISTIC
=
"statistic"
;
/**
/**
* OAuth.
*
Category -
OAuth.
*/
*/
public
static
final
String
CATEGORY_C_OAUTH
=
"oauth"
;
public
static
final
String
CATEGORY_C_OAUTH
=
"oauth"
;
/**
* Category - GitHub.
*/
public
static
final
String
CATEGORY_C_GITHUB
=
"github"
;
//// Transient ////
//// Transient ////
/**
/**
* Key of statistic blog published article count.
* Key of statistic blog published article count.
...
...
src/main/java/org/b3log/solo/service/CronMgmtService.java
View file @
8675f5bd
...
@@ -96,7 +96,7 @@ public class CronMgmtService {
...
@@ -96,7 +96,7 @@ public class CronMgmtService {
}
finally
{
}
finally
{
Stopwatchs
.
release
();
Stopwatchs
.
release
();
}
}
},
delay
,
1000
*
60
*
10
,
TimeUnit
.
MILLISECONDS
);
},
delay
,
1000
*
60
*
60
*
24
,
TimeUnit
.
MILLISECONDS
);
delay
+=
2000
;
delay
+=
2000
;
}
}
...
...
src/main/java/org/b3log/solo/service/PageMgmtService.java
View file @
8675f5bd
...
@@ -104,6 +104,12 @@ public class PageMgmtService {
...
@@ -104,6 +104,12 @@ public class PageMgmtService {
@Inject
@Inject
private
OptionQueryService
optionQueryService
;
private
OptionQueryService
optionQueryService
;
/**
* Option management service.
*/
@Inject
private
OptionMgmtService
optionMgmtService
;
/**
/**
* Refreshes GitHub repos.
* Refreshes GitHub repos.
* 同步 GitHub 仓库 https://github.com/b3log/solo/issues/12514
* 同步 GitHub 仓库 https://github.com/b3log/solo/issues/12514
...
@@ -122,13 +128,24 @@ public class PageMgmtService {
...
@@ -122,13 +128,24 @@ public class PageMgmtService {
final
JSONArray
github
=
new
JSONArray
(
value
);
final
JSONArray
github
=
new
JSONArray
(
value
);
final
String
githubPair
=
github
.
optString
(
0
);
// Just refresh the first account
final
String
githubPair
=
github
.
optString
(
0
);
// Just refresh the first account
final
String
githubUserId
=
githubPair
.
split
(
OAuthGitHubProcessor
.
GITHUB_SPLIT
)[
0
];
final
String
githubUserId
=
githubPair
.
split
(
OAuthGitHubProcessor
.
GITHUB_SPLIT
)[
0
];
final
List
<
JSONObject
>
gitHubRepos
=
Solos
.
getGitHubRepos
(
githubUserId
);
final
JSONArray
gitHubRepos
=
Solos
.
getGitHubRepos
(
githubUserId
);
if
(
null
==
gitHubRepos
||
gitHubRepos
.
isEmpty
())
{
if
(
null
==
gitHubRepos
||
gitHubRepos
.
isEmpty
())
{
return
;
return
;
}
}
final
String
userId
=
githubPair
.
split
(
OAuthGitHubProcessor
.
GITHUB_SPLIT
)[
1
];
System
.
out
.
println
(
userId
+
": "
+
gitHubRepos
);
JSONObject
githubReposOpt
=
optionQueryService
.
getOptionById
(
Option
.
ID_C_GITHUB_REPOS
);
if
(
null
==
githubReposOpt
)
{
githubReposOpt
=
new
JSONObject
();
githubReposOpt
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_GITHUB_REPOS
);
githubReposOpt
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_GITHUB
);
}
githubReposOpt
.
put
(
Option
.
OPTION_VALUE
,
gitHubRepos
.
toString
());
try
{
optionMgmtService
.
addOrUpdateOption
(
githubReposOpt
);
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Updates github repos option failed"
,
e
);
}
}
}
/**
/**
...
...
src/main/java/org/b3log/solo/util/Solos.java
View file @
8675f5bd
...
@@ -47,7 +47,10 @@ import javax.servlet.http.Cookie;
...
@@ -47,7 +47,10 @@ import javax.servlet.http.Cookie;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.MissingResourceException
;
import
java.util.ResourceBundle
;
/**
/**
* Solo utilities.
* Solo utilities.
...
@@ -170,9 +173,9 @@ public final class Solos {
...
@@ -170,9 +173,9 @@ public final class Solos {
* Gets GitHub repos.
* Gets GitHub repos.
*
*
* @param githubUserId the specified GitHub user id
* @param githubUserId the specified GitHub user id
* @return GitHub repos, returns
an empty list
if not found
* @return GitHub repos, returns
{@code null}
if not found
*/
*/
public
static
List
<
JSONObject
>
getGitHubRepos
(
final
String
githubUserId
)
{
public
static
JSONArray
getGitHubRepos
(
final
String
githubUserId
)
{
try
{
try
{
final
HttpResponse
res
=
HttpRequest
.
get
(
"https://hacpai.com/github/repos?id="
+
githubUserId
).
final
HttpResponse
res
=
HttpRequest
.
get
(
"https://hacpai.com/github/repos?id="
+
githubUserId
).
connectionTimeout
(
3000
).
timeout
(
7000
).
header
(
"User-Agent"
,
Solos
.
USER_AGENT
).
send
();
connectionTimeout
(
3000
).
timeout
(
7000
).
header
(
"User-Agent"
,
Solos
.
USER_AGENT
).
send
();
...
@@ -182,16 +185,16 @@ public final class Solos {
...
@@ -182,16 +185,16 @@ public final class Solos {
res
.
charset
(
"UTF-8"
);
res
.
charset
(
"UTF-8"
);
final
JSONObject
result
=
new
JSONObject
(
res
.
bodyText
());
final
JSONObject
result
=
new
JSONObject
(
res
.
bodyText
());
if
(
0
!=
result
.
optInt
(
Keys
.
STATUS_CODE
))
{
if
(
0
!=
result
.
optInt
(
Keys
.
STATUS_CODE
))
{
return
Collections
.
emptyList
()
;
return
null
;
}
}
final
JSONObject
data
=
result
.
optJSONObject
(
Common
.
DATA
);
final
JSONObject
data
=
result
.
optJSONObject
(
Common
.
DATA
);
final
JSONArray
re
pos
=
data
.
optJSONArray
(
"githubrepos"
);
final
JSONArray
re
t
=
data
.
optJSONArray
(
"githubrepos"
);
return
CollectionUtils
.
jsonArrayToList
(
repos
)
;
return
ret
;
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Gets GitHub repos failed"
,
e
);
LOGGER
.
log
(
Level
.
ERROR
,
"Gets GitHub repos failed"
,
e
);
return
Collections
.
emptyList
()
;
return
null
;
}
}
}
}
...
...
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