show post images
This commit is contained in:
@@ -20,7 +20,7 @@ public class FediMedium implements Serializable {
|
||||
this.mediumType = IMAGE;
|
||||
this.description = "missing alt text";
|
||||
this.mediumUrl = "unknown";
|
||||
this.mediumImage = "unknown";
|
||||
this.mediumImage = "assets/splash.jpg";
|
||||
}
|
||||
|
||||
public String getMediumType() {
|
||||
|
||||
@@ -41,7 +41,15 @@ public class FediServlet extends HttpServlet {
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
final JSONLoader loader = new JSONLoader(instance, account);
|
||||
final String scheme = request.getScheme();
|
||||
final String serverName = request.getServerName();
|
||||
final int serverPort = request.getServerPort();
|
||||
final String contextPath = request.getContextPath();
|
||||
String contextUrl = scheme + "://" + serverName + ":" + serverPort + "/" + contextPath;
|
||||
if (!contextUrl.endsWith("/")) {
|
||||
contextUrl += "/";
|
||||
}
|
||||
final JSONLoader loader = new JSONLoader(instance, account, contextUrl);
|
||||
final VelocityContext context = new VelocityContext();
|
||||
context.put("dateformatter", new PostDateFormatter());
|
||||
context.put("page", loader.loadPage());
|
||||
|
||||
@@ -18,12 +18,14 @@ public class JSONLoader implements Serializable {
|
||||
|
||||
private final String instance;
|
||||
private final String account;
|
||||
|
||||
private final String contextUrl;
|
||||
|
||||
private long id;
|
||||
|
||||
public JSONLoader(String instance, String account) {
|
||||
public JSONLoader(final String instance, final String account, final String contextUrl) {
|
||||
this.instance = instance;
|
||||
this.account = account;
|
||||
this.contextUrl = contextUrl;
|
||||
this.id = -1L;
|
||||
}
|
||||
|
||||
@@ -67,13 +69,20 @@ public class JSONLoader implements Serializable {
|
||||
post.setPostUrl(jsonStatus.getString("url"));
|
||||
final JSONArray mediaJsonArray = jsonStatus.getJSONArray("media_attachments");
|
||||
if (mediaJsonArray.length() == 0) {
|
||||
final JSONObject jsonCard = jsonStatus.getJSONObject("card");
|
||||
if (jsonCard != null && jsonCard.getString("image") != null) {
|
||||
final Object cardItem = jsonStatus.get("card");
|
||||
if (cardItem != null && cardItem instanceof JSONObject) {
|
||||
final JSONObject jsonCard = jsonStatus.getJSONObject("card");
|
||||
final FediMedium medium = new FediMedium();
|
||||
medium.setMediumType(FediMedium.CARD);
|
||||
medium.setDescription(jsonCard.getString("description"));
|
||||
medium.setMediumUrl(jsonCard.getString("url"));
|
||||
medium.setMediumImage(jsonCard.getString("image"));
|
||||
final Object imageObject = jsonCard.get("image");
|
||||
if (imageObject != null && imageObject instanceof String) {
|
||||
medium.setMediumImage(jsonCard.getString("image"));
|
||||
} else {
|
||||
final String defaultImage = contextUrl + medium.getMediumImage();
|
||||
medium.setMediumImage(defaultImage);
|
||||
}
|
||||
post.addFediMedium(medium);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>FediServlet</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
<url-pattern></url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>/</welcome-file>
|
||||
<welcome-file></welcome-file>
|
||||
</welcome-file-list>
|
||||
</web-app>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Reference in New Issue
Block a user