From c4eebb74f520c122800c000c2329d3b6b7520c65 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Wed, 30 Jul 2014 16:47:29 +0700
Subject: Reader link tracking
---
src/java/com/juick/http/www/Reader.java | 37 +++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
(limited to 'src/java/com/juick/http/www/Reader.java')
diff --git a/src/java/com/juick/http/www/Reader.java b/src/java/com/juick/http/www/Reader.java
index dc356482..75a0e774 100644
--- a/src/java/com/juick/http/www/Reader.java
+++ b/src/java/com/juick/http/www/Reader.java
@@ -54,11 +54,11 @@ public class Reader {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("SELECT rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100");
+ stmt = sql.prepareStatement("SELECT link_id,rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
- out.println("
" + rs.getString(3) + "");
+ out.println("
" + rs.getString(4) + "");
}
} catch (SQLException e) {
System.err.println(e);
@@ -75,4 +75,37 @@ public class Reader {
out.close();
}
}
+
+ protected void doGetOut(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
+ int lid = Utils.parseInt(request.getParameter("lid"), 0);
+ if (lid == 0) {
+ response.sendError(404);
+ return;
+ }
+
+ String url = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT url FROM reader_links WHERE link_id=?");
+ stmt.setInt(1, lid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ url = rs.getString(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (url == null) {
+ response.sendError(404);
+ return;
+ }
+
+ Utils.sendTemporaryRedirect(response, url);
+ }
}
--
cgit v1.2.3