3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 12:12:35 +01:00

Add basic hashing functionality to imgur

* There is probably a much nicer way of doing it (perhaps a better
  hash)?
* Added a counter to the imgur random page counting the number of
  [Facebook Monopoly Men](http://i.imgur.com/3Tt6N.gif).
* Added the md5sum of the current image to the getRandomImage api call.
* Future functionality might be storing every image md5 in an array and
  counting duplicates, instead of the current check-against-known-dupes.
This commit is contained in:
Douglas Gardner 2013-05-01 09:42:42 +00:00
parent 3097683e1c
commit e59e4c343f
3 changed files with 20 additions and 62 deletions

View File

@ -4,7 +4,8 @@
*/
var _ = require('underscore')._,
request = require('request');
request = require('request'),
crypto = require('crypto');
var imgur = function(dbot) {
this.db = dbot.db.imgur;
@ -50,7 +51,8 @@ var imgur = function(dbot) {
// 492 is body.length of a removed image
if(!error && response.statusCode == 200 && body.length != 492) {
this.db.totalImages += 1;
callback(testUrl, testSlug);
var hash = crypto.createHash('md5').update(body).digest("hex");
callback(testUrl, testSlug,hash);
} else {
this.api.getRandomImage(callback);
}

View File

@ -106,3 +106,15 @@ html,body {
overflow:auto;
padding:0;
}
#count2 {
bottom:25px;
position:absolute;
border-radius:5px;
display:none;
margin;5px;
padding:5px;
right:25px;
background-color:#3b5998;
color:white;
font-family:'Freight Sans Bold','Lucida Grande',verdana,arial,sans-serif;
}

View File

@ -3,73 +3,17 @@ html(lang='en')
head
meta(charset='utf-8')
script(type="text/javascript", src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js")
script(type="text/javascript", src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js")
script(type="text/javascript", src="/imgurr.js")
link(rel="stylesheet", href="/imgurr.css")
title random imgur
script
var count = 0;
function giveMessage(msg) {
$('<li>'+msg+'</li>').prependTo('#history').hide().slideDown();
}
var lock = false
var highscore = #{highscore} + 1;
var score = highscore;
$('#count').text(score);
function getNewImage() {
count += 1;
lock = true;
$('#loading').fadeIn();
$('#loading').text('Loading image ' + count + '...');
document.title = 'random imgur (' + count + ')';
$('#loading').fadeIn();
$('#image').load(function(){});
$.get("/api/imgur/getRandomImage", function(d) {
$('#image').attr('src', d.data[0]);
lock = false;
score -= 1;
$('#count').text(score);
$('#details').text("Fetching info...");
giveMessage('<a href="' + d.data[0] + '">' + d.data[0] + '</a>');
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
if(info.data[0].indexOf('undefined') == -1) {
$("#details").text(count + ': ' + info.data[0]);
$('#details').show();
} else {
$("#details").hide();
}
$('#loading').fadeOut();
}, "json");
}, "json");
}
$(getNewImage());
$(document).on('keydown', function(e){
switch(e.which){
case 82: // r
score = highscore;
$('#count').text(highscore);
giveMessage("Score reset.");
case 13: // enter
case 32: // space
if (lock) {
$('#loading').text(function(index, text){
return text.replace(/\.(?=[^.]*$)/, "!");
});
} else {
getNewImage();
}
break;
case 67:
$('#count').fadeToggle();
break;
case 83: // s
$('body').toggleClass('crop');
giveMessage("Toggled scrollbars.")
};
});
body
div#loading Loading image 1...
div#details Press [SPACE] to load a new image
div#count
#{highscore}
div#count2
ø
ul#history
li Press [SPACE] for next
div#container