Commit a7725d0c authored by Liang Ding's avatar Liang Ding

#19 看板娘处理

parent b657bbd3
...@@ -19,7 +19,6 @@ package org.b3log.solo.processor; ...@@ -19,7 +19,6 @@ package org.b3log.solo.processor;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext; import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing; import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor; import org.b3log.latke.http.annotation.RequestProcessor;
...@@ -30,12 +29,13 @@ import org.json.JSONArray; ...@@ -30,12 +29,13 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/** /**
* KanBanNiang processor. https://github.com/b3log/solo/issues/12472 * KanBanNiang processor. https://github.com/b3log/solo/issues/12472
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Mar 4, 2019 * @version 1.0.0.3, Jan 9, 2020
* @since 2.9.2 * @since 2.9.2
*/ */
@RequestProcessor @RequestProcessor
...@@ -51,7 +51,7 @@ public class KanBanNiangProcessor { ...@@ -51,7 +51,7 @@ public class KanBanNiangProcessor {
* *
* @param context the specified request context * @param context the specified request context
*/ */
@RequestProcessing(value = "/plugins/kanbanniang/assets/model", method = HttpMethod.GET) @RequestProcessing(value = "/plugins/kanbanniang/assets/model.json")
public void randomModel(final RequestContext context) { public void randomModel(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer(); final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
...@@ -59,17 +59,17 @@ public class KanBanNiangProcessor { ...@@ -59,17 +59,17 @@ public class KanBanNiangProcessor {
final String assets = "/plugins/kanbanniang/assets"; final String assets = "/plugins/kanbanniang/assets";
String model; String model;
try (final InputStream inputStream = KanBanNiangProcessor.class.getResourceAsStream(assets + "/model-list.json")) { try (final InputStream inputStream = KanBanNiangProcessor.class.getResourceAsStream(assets + "/model-list.json")) {
final JSONArray models = new JSONArray(IOUtils.toString(inputStream, "UTF-8")); final JSONArray models = new JSONArray(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
final int i = RandomUtils.nextInt(models.length()); final int i = RandomUtils.nextInt(models.length());
model = models.getString(i); model = models.getString(i);
} }
try (final InputStream modelResource = KanBanNiangProcessor.class.getResourceAsStream(assets + "/model/" + model + "/index.json")) { try (final InputStream modelResource = KanBanNiangProcessor.class.getResourceAsStream(assets + "/model/" + model + "/index.json")) {
final JSONObject index = new JSONObject(IOUtils.toString(modelResource, "UTF-8")); final JSONObject index = new JSONObject(IOUtils.toString(modelResource, StandardCharsets.UTF_8));
final JSONArray textures = index.optJSONArray("textures"); final JSONArray textures = index.optJSONArray("textures");
if (textures.isEmpty()) { if (textures.isEmpty()) {
try (final InputStream texturesRes = KanBanNiangProcessor.class.getResourceAsStream(assets + "/model/" + model + "/textures.json")) { try (final InputStream texturesRes = KanBanNiangProcessor.class.getResourceAsStream(assets + "/model/" + model + "/textures.json")) {
final JSONArray texturesArray = new JSONArray(IOUtils.toString(texturesRes, "UTF-8")); final JSONArray texturesArray = new JSONArray(IOUtils.toString(texturesRes, StandardCharsets.UTF_8));
final Object element = texturesArray.opt(RandomUtils.nextInt(texturesArray.length())); final Object element = texturesArray.opt(RandomUtils.nextInt(texturesArray.length()));
if (element instanceof JSONArray) { if (element instanceof JSONArray) {
index.put("textures", element); index.put("textures", element);
......
...@@ -88,8 +88,8 @@ public class StaticSiteProcessor { ...@@ -88,8 +88,8 @@ public class StaticSiteProcessor {
// 切换至静态站点生成模式 // 切换至静态站点生成模式
Latkes.setServerScheme("https"); Latkes.setServerScheme("https");
// TODO: 前端传入生成站点域名 // TODO: 前端传入生成站点域名
// Latkes.setServerHost("88250.github.io"); Latkes.setServerHost("88250.github.io");
Latkes.setServerHost("dl88250.gitee.io"); // Latkes.setServerHost("dl88250.gitee.io");
Latkes.setServerPort(""); Latkes.setServerPort("");
Solos.GEN_STATIC_SITE = true; Solos.GEN_STATIC_SITE = true;
...@@ -109,6 +109,7 @@ public class StaticSiteProcessor { ...@@ -109,6 +109,7 @@ public class StaticSiteProcessor {
genSkins(); genSkins();
genJS(); genJS();
genImages(); genImages();
genPlugins();
genFile("sw.js"); genFile("sw.js");
genFile("robots.txt"); genFile("robots.txt");
genFile("CHANGE_LOGS.md"); genFile("CHANGE_LOGS.md");
...@@ -267,6 +268,15 @@ public class StaticSiteProcessor { ...@@ -267,6 +268,15 @@ public class StaticSiteProcessor {
LOGGER.log(Level.INFO, "Generated images"); LOGGER.log(Level.INFO, "Generated images");
} }
private static void genPlugins() throws Exception {
FileUtils.deleteDirectory(new File(staticSitePath + "/plugins"));
FileUtils.forceMkdir(new File(staticSitePath + "/plugins"));
FileUtils.copyDirectory(new File(StaticSiteProcessor.class.getResource("/plugins").toURI()), new File(staticSitePath + "/plugins"));
genURI("/plugins/kanbanniang/assets/model.json");
LOGGER.log(Level.INFO, "Generated plugins");
}
private static void genFile(final String file) throws Exception { private static void genFile(final String file) throws Exception {
FileUtils.forceMkdirParent(new File(staticSitePath + "/" + file)); FileUtils.forceMkdirParent(new File(staticSitePath + "/" + file));
final String staticSitePath = StaticSiteProcessor.class.getResource("/" + STATIC_SITE).toURI().getPath(); final String staticSitePath = StaticSiteProcessor.class.getResource("/" + STATIC_SITE).toURI().getPath();
......
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