added album support

This commit is contained in:
Niklas 2018-10-11 21:35:04 +02:00
parent f7114ef86c
commit d179895318
3 changed files with 38 additions and 7 deletions

View File

@ -118,7 +118,7 @@
} }
}; };
var lastCreated = $.urlParam('o') === null ? 2147483647 : $.urlParam('o'); var lastCreated = $.urlParam('o') === null ? -1 : $.urlParam('o');
var waitForIMG = 0; var waitForIMG = 0;
var loadedImages = 0; var loadedImages = 0;
var loading = false; var loading = false;
@ -188,7 +188,7 @@
} }
var elm = $(".grid").append("<div class='item' id='" + value.iid + "'><div class='content'>" + media + "<div class='overlay' style='" + (isMobile ? "" : "display:none") + "'><a href='https://reddit.com/r/" + value.subreddit + "'>" + value.subreddit + "</a><a href='https://reddit.com/r/" + value.subreddit + "/comments/" + value.id + "' target='_blank' style='padding-left: 0.4em;'><i class='fa fa-external-link' aria-hidden='true'></i></a>\</div></div></div>"); var elm = $(".grid").append("<div class='item' id='" + value.iid + "'><div class='content'>" + media + "<div class='overlay' style='" + (isMobile ? "" : "display:none") + "'><a href='https://reddit.com/r/" + value.subreddit + "'>" + value.subreddit + "</a><a href='https://reddit.com/r/" + value.subreddit + "/comments/" + value.id + "' target='_blank' style='padding-left: 0.4em;'><i class='fa fa-external-link' aria-hidden='true'></i></a>\</div></div></div>");
lastCreated = value.created; lastCreated = value.iid;
waitForIMG++; waitForIMG++;
$("#" + value.iid).hover(function () { $("#" + value.iid).hover(function () {

View File

@ -1,6 +1,7 @@
package de.gurkengewuerz.ripmewrapper; package de.gurkengewuerz.ripmewrapper;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.sql.Connection; import java.sql.Connection;
@ -44,16 +45,19 @@ public class ImageCrawler extends TimerTask {
.collect(Collectors.toList()); .collect(Collectors.toList());
PreparedStatement ps = connection.prepareStatement("INSERT INTO filelist VALUES (NULL, ?, ?)"); PreparedStatement ps = connection.prepareStatement("INSERT INTO filelist VALUES (NULL, ?, ?)");
HashSet<String> foundIds = new HashSet<>();
for (String s : pathList) { for (String s : pathList) {
String id = s.substring(s.lastIndexOf(File.separator) + 1).split("-")[0]; String id = s.substring(s.lastIndexOf(File.separator) + 1).split("-")[0];
if (!findIds.contains(id)) continue; if (!findIds.contains(id)) continue;
ps.setString(1, id); ps.setString(1, id);
ps.setString(2, s); ps.setString(2, s);
ps.executeUpdate(); ps.executeUpdate();
findIds.remove(id); foundIds.add(id);
} }
ps.close(); ps.close();
findIds.removeAll(foundIds);
ps = connection.prepareStatement("DELETE FROM metalist WHERE id = ?"); ps = connection.prepareStatement("DELETE FROM metalist WHERE id = ?");
for (String id : findIds) { for (String id : findIds) {
ps.setString(1, id); ps.setString(1, id);

View File

@ -46,24 +46,51 @@ public class APIHandler extends AbstractHandler {
if (request.getParameter("subreddits") != null) { if (request.getParameter("subreddits") != null) {
String[] subreddits = request.getParameter("subreddits").split(","); String[] subreddits = request.getParameter("subreddits").split(",");
int created = request.getParameter("offset") == null ? Integer.MAX_VALUE : Integer.valueOf(request.getParameter("offset")); int offset = request.getParameter("offset") == null ? -1 : Integer.valueOf(request.getParameter("offset"));
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 0; i < subreddits.length; i++) { for (int i = 0; i < subreddits.length; i++) {
builder.append("?,"); builder.append("?,");
} }
String builderString = builder.deleteCharAt(builder.length() - 1).toString();
int limit = 0;
int index = 1;
if (offset != -1) {
PreparedStatement psPre = connection.prepareStatement(
"SELECT iid FROM filelist LEFT JOIN metalist ON filelist.id = metalist.id WHERE subreddit IN (" + builderString + ") ORDER BY created DESC, iid DESC"
);
for (String o : subreddits) {
psPre.setString(index++, o);
}
ResultSet rsPre = psPre.executeQuery();
while (rsPre.next()) {
limit++;
if (rsPre.getInt("iid") == offset) {
break;
}
}
rsPre.close();
psPre.close();
}
// ----------------
PreparedStatement ps = connection.prepareStatement( PreparedStatement ps = connection.prepareStatement(
"SELECT iid, metalist.id, subreddit, created, path FROM filelist LEFT JOIN metalist ON filelist.id = metalist.id WHERE subreddit IN (" + builder.deleteCharAt(builder.length() - 1).toString() + ") AND created < ? ORDER BY created DESC LIMIT 10" "SELECT iid, metalist.id, subreddit, created, path FROM filelist LEFT JOIN metalist ON filelist.id = metalist.id WHERE subreddit IN (" + builderString + ") ORDER BY created DESC, iid DESC LIMIT 10 OFFSET ?"
); );
int index = 1; index = 1;
for (String o : subreddits) { for (String o : subreddits) {
ps.setString(index++, o); ps.setString(index++, o);
} }
ps.setInt(index, created); ps.setInt(index, limit);
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();