added album support
This commit is contained in:
parent
f7114ef86c
commit
d179895318
@ -118,7 +118,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
var lastCreated = $.urlParam('o') === null ? 2147483647 : $.urlParam('o');
|
||||
var lastCreated = $.urlParam('o') === null ? -1 : $.urlParam('o');
|
||||
var waitForIMG = 0;
|
||||
var loadedImages = 0;
|
||||
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>");
|
||||
lastCreated = value.created;
|
||||
lastCreated = value.iid;
|
||||
waitForIMG++;
|
||||
|
||||
$("#" + value.iid).hover(function () {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.gurkengewuerz.ripmewrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
@ -44,16 +45,19 @@ public class ImageCrawler extends TimerTask {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PreparedStatement ps = connection.prepareStatement("INSERT INTO filelist VALUES (NULL, ?, ?)");
|
||||
HashSet<String> foundIds = new HashSet<>();
|
||||
for (String s : pathList) {
|
||||
String id = s.substring(s.lastIndexOf(File.separator) + 1).split("-")[0];
|
||||
if (!findIds.contains(id)) continue;
|
||||
ps.setString(1, id);
|
||||
ps.setString(2, s);
|
||||
ps.executeUpdate();
|
||||
findIds.remove(id);
|
||||
foundIds.add(id);
|
||||
}
|
||||
ps.close();
|
||||
|
||||
findIds.removeAll(foundIds);
|
||||
|
||||
ps = connection.prepareStatement("DELETE FROM metalist WHERE id = ?");
|
||||
for (String id : findIds) {
|
||||
ps.setString(1, id);
|
||||
|
@ -46,24 +46,51 @@ public class APIHandler extends AbstractHandler {
|
||||
if (request.getParameter("subreddits") != null) {
|
||||
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();
|
||||
for (int i = 0; i < subreddits.length; i++) {
|
||||
builder.append("?,");
|
||||
}
|
||||
|
||||
String builderString = builder.deleteCharAt(builder.length() - 1).toString();
|
||||
|
||||
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"
|
||||
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"
|
||||
);
|
||||
|
||||
int index = 1;
|
||||
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(
|
||||
"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 ?"
|
||||
);
|
||||
|
||||
index = 1;
|
||||
for (String o : subreddits) {
|
||||
ps.setString(index++, o);
|
||||
}
|
||||
|
||||
ps.setInt(index, created);
|
||||
ps.setInt(index, limit);
|
||||
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
Loading…
Reference in New Issue
Block a user