integrate iqdbs
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
# todo: move this to iqdbs
|
||||||
class IqdbQueriesController < ApplicationController
|
class IqdbQueriesController < ApplicationController
|
||||||
before_filter :member_only
|
before_filter :member_only
|
||||||
|
|
||||||
@@ -19,14 +20,16 @@ class IqdbQueriesController < ApplicationController
|
|||||||
protected
|
protected
|
||||||
def create_by_url
|
def create_by_url
|
||||||
@download = Iqdb::Download.new(params[:url])
|
@download = Iqdb::Download.new(params[:url])
|
||||||
@download.download_and_find_similar
|
@download.find_similar
|
||||||
@results = @download.matches
|
@results = @download.matches
|
||||||
render :layout => false, :action => "create_by_url"
|
render :layout => false, :action => "create_by_url"
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_by_post
|
def create_by_post
|
||||||
@post = Post.find(params[:post_id])
|
@post = Post.find(params[:post_id])
|
||||||
@results = Iqdb::Server.default.query(3, @post.preview_file_path)
|
@download = Iqdb::Download.new(@post.complete_preview_file_url)
|
||||||
render :layout => false, :action => "create_by_post"
|
@download.find_similar
|
||||||
|
@results = @download.matches
|
||||||
|
render :layout => false, :action => "create_by_url"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -6,17 +6,37 @@ module Iqdb
|
|||||||
@source = source
|
@source = source
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_and_find_similar
|
def find_similar
|
||||||
tempfile = Tempfile.new("iqdb-#{$PROCESS_ID}")
|
if Danbooru.config.iqdbs_server
|
||||||
@download = Downloads::File.new(source, tempfile.path, :get_thumbnail => true)
|
params = {
|
||||||
@download.download!
|
"key" => Danbooru.config.iqdbs_auth_key,
|
||||||
|
"url" => source
|
||||||
|
}
|
||||||
|
uri = URI.parse("#{Danbooru.config.iqdbs_server}/similar")
|
||||||
|
uri.query = URI.encode_www_form(params)
|
||||||
|
|
||||||
if Danbooru.config.iqdb_hostname_and_port
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
@matches = Iqdb::Server.default.query(3, @download.file_path).matches
|
resp = http.request_get(uri.request_uri)
|
||||||
|
if resp.is_a?(Net::HTTPSuccess)
|
||||||
|
JSON.parse(resp.body)
|
||||||
|
else
|
||||||
|
raise "HTTP error code: #{resp.code} #{resp.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
tempfile = Tempfile.new("iqdb-#{$PROCESS_ID}")
|
||||||
|
@download = Downloads::File.new(source, tempfile.path, :get_thumbnail => true)
|
||||||
|
@download.download!
|
||||||
|
|
||||||
|
if Danbooru.config.iqdb_hostname_and_port
|
||||||
|
@matches = Iqdb::Server.default.query(3, @download.file_path).matches
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
tempfile.close
|
||||||
|
tempfile.unlink
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
tempfile.close
|
|
||||||
tempfile.unlink
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# iqdb
|
|
||||||
# chkconfig: 345 20 80
|
|
||||||
# description: iqdb
|
|
||||||
# processname: iqdb
|
|
||||||
|
|
||||||
DAEMON_PATH=/home/albert/iqdb
|
|
||||||
PORT=4000
|
|
||||||
IQDB_FILE=/var/www/danbooru2/iqdb.db
|
|
||||||
DAEMON=iqdb
|
|
||||||
DAEMONOPTS="listen2 localhost:$PORT -r $IQDB_FILE"
|
|
||||||
NAME=iqdb
|
|
||||||
DESC=iqdb
|
|
||||||
PIDFILE=/var/run/$NAME.pid
|
|
||||||
SCRIPTNAME=/etc/init.d/$NAME
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
printf "%-50s" "Starting $NAME..."
|
|
||||||
cd $DAEMON_PATH
|
|
||||||
PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
|
|
||||||
#echo "Saving PID" $PID " to " $PIDFILE
|
|
||||||
if [ -z $PID ]; then
|
|
||||||
printf "%s\n" "Fail"
|
|
||||||
else
|
|
||||||
echo $PID > $PIDFILE
|
|
||||||
printf "%s\n" "Ok"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
status)
|
|
||||||
printf "%-50s" "Checking $NAME..."
|
|
||||||
if [ -f $PIDFILE ]; then
|
|
||||||
PID=`cat $PIDFILE`
|
|
||||||
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
|
|
||||||
printf "%s\n" "Process dead but pidfile exists"
|
|
||||||
else
|
|
||||||
echo "Running"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "%s\n" "Service not running"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
printf "%-50s" "Stopping $NAME"
|
|
||||||
PID=`cat $PIDFILE`
|
|
||||||
cd $DAEMON_PATH
|
|
||||||
if [ -f $PIDFILE ]; then
|
|
||||||
kill -SIGTERM $PID
|
|
||||||
printf "%s\n" "Ok"
|
|
||||||
rm -f $PIDFILE
|
|
||||||
else
|
|
||||||
printf "%s\n" "pidfile not found"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
restart)
|
|
||||||
$0 start
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Usage: $0 {status|start|stop|restart}"
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
Reference in New Issue
Block a user