Skip to content

Commit

Permalink
JSON 格式化输出
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx committed Jan 19, 2018
1 parent 46a38b4 commit 6d19da1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 161 deletions.
135 changes: 0 additions & 135 deletions src/main/java/com/example/ShadowSocksShare/common/JsonUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.ShadowSocksShare.domain;

import com.example.ShadowSocksShare.common.JsonUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
import org.apache.commons.codec.binary.Base64;

Expand Down Expand Up @@ -75,23 +76,18 @@ public class ShadowSocksDetailsEntity implements Serializable {
@Column
private String title; // 网站名

public String getJsonStr() {
// { "server": "202.91.34.32", "server_ipv6": "::", "server_port": 443, "local_address": "127.0.0.1", "local_port": 1080, "password": "123456", "group": "Charles Xu", "obfs": "tls1.2_ticket_auth", "method": "chacha20", "ssr_protocol": "auth_aes128_sha1", "obfsparam": "", "protoparam": "" }
public String getJsonStr() throws JsonProcessingException {
Map<String, Object> json = new HashMap();
json.put("server", server);
json.put("server_ipv6", "::");
json.put("server_port", server_port);
json.put("local_address", "127.0.0.1");
json.put("local_port", 1080);
json.put("password", password);

json.put("group", group);
json.put("obfs", obfs);
json.put("method", method);
json.put("ssr_protocol", protocol);
json.put("obfsparam", obfs);

return JsonUtils.toJsonString(json);
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(json);
}

public String getLink() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/example/ShadowSocksShare/web/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public String subscribe(boolean valid, @PageableDefault(page = 0, size = 1000, s
return StringUtils.isNotBlank(ssrLink) ? ssrLink : "无有效 SSR 连接,请稍后重试!";
}

/**
* 订阅 Json
*/
/*@RequestMapping("/subscribeJson")
@ResponseBody
public String subscribeJson() {
List<ShadowSocksEntity> ssrList = shadowSocksSerivceImpl.findAll(pageable);
String ssrLink = shadowSocksSerivceImpl.toSSLink(ssrList, valid);
return StringUtils.isNotBlank(ssrLink) ? ssrLink : "无有效 SSR 连接,请稍后重试!";
}*/

/**
* 二维码
*/
Expand Down
26 changes: 8 additions & 18 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ <h2 th:text="${'网站 ' + (iterStat.index + 1)}"></h2>
th:onclick="${'showImg(''' + ssrd.id + ''',''' + ssrd.title + ''',''' + ssrd.link + ''')'}">
<i class="fa fa-qrcode" aria-hidden="true"></i> &nbsp; 二维码 &nbsp; &raquo;
</button>
<button type="button" class="btn btn-sm btn-secondary"
th:onclick="${'showLink(''' + ssrd.id + ''',''' + ssrd.title + ''',''' + ssrd.link + ''')'}">
<button type="button" class="btn btn-sm btn-secondary" th:attr="data-title=${ssrd.title},data-value=${ssrd.link}"
onclick="showLink(this)">
<i class="fa fa-link" aria-hidden="true"></i> &nbsp; 连接 &nbsp; &raquo;
</button>
<button type="button" class="btn btn-sm btn-secondary"
th:onclick="${'showLink(''' + ssrd.id + ''',''' + ssrd.title + ''',''' + ssrd.jsonStr + ''')'}">
<button type="button" class="btn btn-sm btn-secondary" th:attr="data-title=${ssrd.title},data-value=${ssrd.jsonStr}"
onclick="showLink(this)">
<i class="fa fa-code" aria-hidden="true"></i> &nbsp; JSON &nbsp; &raquo;
</button>
</div>
Expand Down Expand Up @@ -211,12 +211,6 @@ <h5 class="modal-title" id="modalTitle"></h5>
</div>
</div>
</div>
<!--<div class="row justify-content-center">
<div class="form-group col-md-9">
<label for="ssrLink" class="col-form-label sr-only">连接:</label>
<input id="ssrLink" readonly="readonly" type="text" class="form-control"/>
</div>
</div>-->
</div>
</div>
<!--<div class="modal-footer">
Expand All @@ -241,10 +235,6 @@ <h5 class="modal-title" id="modalTitle2"></h5>
<div class="modal-body">
<pre id="modalBody"></pre>
</div>
<!--<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary">复制连接</button>
</div>-->
</div>
</div>
</div>
Expand Down Expand Up @@ -275,10 +265,10 @@ <h5 class="modal-title" id="modalTitle2"></h5>
}

// 显示 link、json
function showLink(id, title, text) {
// console.log(link);
$('#modalTitle2').text(title);
$('#modalBody').text(text);
function showLink(obj) {
// console.log($(obj).data('json'));
$('#modalTitle2').text($(obj).data('title'));
$('#modalBody').text($(obj).attr('data-value'));
$('#linkModal').modal('show');
}

Expand Down

0 comments on commit 6d19da1

Please sign in to comment.