Commit 4f3624a7 authored by Liang Ding's avatar Liang Ding

🎨 #12724

parent bc29399f
...@@ -144,7 +144,7 @@ public class AdminConsole { ...@@ -144,7 +144,7 @@ public class AdminConsole {
dataModel.put(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT, preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT)); dataModel.put(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT, preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT));
dataModel.put(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE, preference.getInt(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE)); dataModel.put(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE, preference.getInt(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE));
final JSONObject skin = optionQueryService.getSkin(); final JSONObject skin = optionQueryService.getSkin();
dataModel.put(Option.CATEGORY_C_SKIN, skin.optString(Option.OPTION_VALUE)); dataModel.put(Option.CATEGORY_C_SKIN, skin.optString(Option.ID_C_SKIN_DIR_NAME));
Keys.fillRuntime(dataModel); Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel); dataModelService.fillMinified(dataModel);
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614 // 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.b3log.solo.processor.console; package org.b3log.solo.processor.console;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.Inject; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
...@@ -30,10 +31,13 @@ import org.b3log.latke.servlet.renderer.JsonRenderer; ...@@ -30,10 +31,13 @@ import org.b3log.latke.servlet.renderer.JsonRenderer;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.service.OptionQueryService; import org.b3log.solo.service.OptionQueryService;
import org.b3log.solo.service.SkinMgmtService; import org.b3log.solo.service.SkinMgmtService;
import org.b3log.solo.util.Skins;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Set;
/** /**
* Skin console request processing. * Skin console request processing.
...@@ -101,6 +105,22 @@ public class SkinConsole { ...@@ -101,6 +105,22 @@ public class SkinConsole {
return; return;
} }
final Set<String> skinDirNames = Skins.getSkinDirNames();
final JSONArray skinArray = new JSONArray();
for (final String dirName : skinDirNames) {
final JSONObject s = new JSONObject();
final String name = Latkes.getSkinName(dirName);
if (null == name) {
LOGGER.log(Level.WARN, "The directory [{0}] does not contain any skin, ignored it", dirName);
continue;
}
s.put(Option.ID_C_SKIN_DIR_NAME, dirName);
skinArray.put(s);
}
skin.put("skins", skinArray.toString());
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
ret.put(Option.CATEGORY_C_SKIN, skin); ret.put(Option.CATEGORY_C_SKIN, skin);
...@@ -121,7 +141,8 @@ public class SkinConsole { ...@@ -121,7 +141,8 @@ public class SkinConsole {
* <pre> * <pre>
* { * {
* "skin": { * "skin": {
* "skinDirName": "" * "skinDirName": "",
* "mobileSkinDirName": "",
* } * }
* } * }
* </pre> * </pre>
...@@ -138,9 +159,6 @@ public class SkinConsole { ...@@ -138,9 +159,6 @@ public class SkinConsole {
final JSONObject skin = requestJSONObject.getJSONObject(Option.CATEGORY_C_SKIN); final JSONObject skin = requestJSONObject.getJSONObject(Option.CATEGORY_C_SKIN);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
if (isInvalid(skin, ret)) {
return;
}
skinMgmtService.updateSkin(skin); skinMgmtService.updateSkin(skin);
...@@ -161,102 +179,6 @@ public class SkinConsole { ...@@ -161,102 +179,6 @@ public class SkinConsole {
} }
} }
/**
* Checks whether the specified preference is invalid and sets the specified response object.
*
* @param preference the specified preference
* @param responseObject the specified response object
* @return {@code true} if the specified preference is invalid, returns {@code false} otherwise
*/
private boolean isInvalid(final JSONObject preference, final JSONObject responseObject) {
responseObject.put(Keys.STATUS_CODE, false);
final StringBuilder errMsgBuilder = new StringBuilder('[' + langPropsService.get("paramSettingsLabel"));
errMsgBuilder.append(" - ");
String input = preference.optString(Option.ID_C_EXTERNAL_RELEVANT_ARTICLES_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("externalRelevantArticlesDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_RELEVANT_ARTICLES_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("relevantArticlesDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_RANDOM_ARTICLES_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("randomArticlesDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_MOST_COMMENT_ARTICLE_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("indexMostCommentArticleDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_MOST_VIEW_ARTICLE_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("indexMostViewArticleDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_RECENT_COMMENT_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("indexRecentCommentDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_MOST_USED_TAG_DISPLAY_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("indexTagDisplayCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("pageSizeLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("windowSizeLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
input = preference.optString(Option.ID_C_FEED_OUTPUT_CNT);
if (!isNonNegativeInteger(input)) {
errMsgBuilder.append(langPropsService.get("feedOutputCntLabel")).append("] ")
.append(langPropsService.get("nonNegativeIntegerOnlyLabel"));
responseObject.put(Keys.MSG, errMsgBuilder.toString());
return true;
}
return false;
}
/** /**
* Checks whether the specified input is a non-negative integer. * Checks whether the specified input is a non-negative integer.
* *
......
...@@ -76,28 +76,13 @@ public class SkinMgmtService { ...@@ -76,28 +76,13 @@ public class SkinMgmtService {
*/ */
public void loadSkins(final JSONObject skin) throws Exception { public void loadSkins(final JSONObject skin) throws Exception {
final Set<String> skinDirNames = Skins.getSkinDirNames(); final Set<String> skinDirNames = Skins.getSkinDirNames();
LOGGER.log(Level.DEBUG, "Loaded skins [dirNames={0}]", skinDirNames);
final JSONArray skinArray = new JSONArray();
for (final String dirName : skinDirNames) {
final JSONObject s = new JSONObject();
final String name = Latkes.getSkinName(dirName);
if (null == name) {
LOGGER.log(Level.WARN, "The directory [{0}] does not contain any skin, ignored it", dirName);
continue;
}
s.put(Option.ID_C_SKIN_DIR_NAME, dirName);
skinArray.put(s);
}
final String currentSkinDirName = skin.optString(Option.ID_C_SKIN_DIR_NAME); final String currentSkinDirName = skin.optString(Option.ID_C_SKIN_DIR_NAME);
if (!skinDirNames.contains(currentSkinDirName)) { if (!skinDirNames.contains(currentSkinDirName)) {
LOGGER.log(Level.WARN, "Configured skin [dirName={0}] can not find, try to use " + "default skin [dirName=" LOGGER.log(Level.WARN, "Not found skin [dirName={0}] configured, try to use default skin [dirName="
+ Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME + "] instead.", currentSkinDirName); + Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME + "] instead", currentSkinDirName);
if (!skinDirNames.contains(Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME)) { if (!skinDirNames.contains(Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME)) {
LOGGER.log(Level.ERROR, "Can not find default skin [dirName=" + Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME LOGGER.log(Level.ERROR, "Not found default skin [dirName=" + Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME
+ "], please redeploy your Solo and make sure contains the default skin. If you are using git, try to re-pull with 'git pull --recurse-submodules'"); + "], please redeploy your Solo and make sure contains the default skin. If you are using git, try to pull with 'git pull --recurse-submodules'");
System.exit(-1); System.exit(-1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment