[danbooru api] fixed for trunk, hopefully

git-svn-id: file:///home/shish/svn/shimmie2/trunk@724 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
jjs 2008-03-02 01:11:52 +00:00
parent 7948202337
commit 430163c29d

View File

@ -16,6 +16,10 @@ find_posts - sort of works, filename is returned as the original filename and pr
find_tags - id, name, and after_id all work but the tags parameter is ignored just like danbooru 1.0 ignores it find_tags - id, name, and after_id all work but the tags parameter is ignored just like danbooru 1.0 ignores it
CHANGELOG CHANGELOG
01-MAR-08 7:00PM CST - JJS
Rewrote to make it compatible with Shimmie trunk again (r723 at least)
It may or may not support the new file handling stuff correctly, I'm only testing with images and the danbooru uploader for firefox
21-OCT-07 9:07PM CST - JJS 21-OCT-07 9:07PM CST - JJS
Turns out I actually did need to implement the new parameter names Turns out I actually did need to implement the new parameter names
for danbooru api v1.8.1. Now danbooruup should work when used with /api/danbooru/post/create.xml for danbooru api v1.8.1. Now danbooruup should work when used with /api/danbooru/post/create.xml
@ -47,7 +51,7 @@ class DanbooruApi extends Extension
$matches = array(); $matches = array();
if(preg_match("/md5:([0-9a-fA-F]*)/i", $event->term, $matches)) if(preg_match("/md5:([0-9a-fA-F]*)/i", $event->term, $matches))
{ {
$hash = strtolower($matches[2]); $hash = strtolower($matches[1]);
$event->set_querylet(new Querylet("AND (images.hash = '$hash')")); $event->set_querylet(new Querylet("AND (images.hash = '$hash')"));
} }
} }
@ -216,36 +220,23 @@ class DanbooruApi extends Extension
} }
// Get tags out of url // Get tags out of url
$posttags = isset($_REQUEST['tags']) ? $_REQUEST['tags'] : $_REQUEST['post']['tags']; $posttags = tag_explode(isset($_REQUEST['tags']) ? $_REQUEST['tags'] : $_REQUEST['post']['tags']);
$hash = md5_file($file);
// Now that we have some sort of physical file, process it // Was an md5 supplied? Does it match the file hash?
$image = new Image($file, $filename, $posttags, $source);
// This occurs if the uploaded file is not an image
if(!$image->is_ok())
{
header("HTTP/1.0 409 Conflict");
header("X-Danbooru-Errors: unknown");
return;
}
// Was an md5 supplied? Does it match the image hash?
if(isset($_REQUEST['md5'])) if(isset($_REQUEST['md5']))
{ {
if($_REQUEST['md5'] != $image->hash) if(strtolower($_REQUEST['md5']) != $hash)
{ {
header("HTTP/1.0 409 Conflict"); header("HTTP/1.0 409 Conflict");
header("X-Danbooru-Errors: md5 mismatch"); header("X-Danbooru-Errors: md5 mismatch");
return; return;
} }
} }
// Is the image too large? // Upload size checking is now performed in the upload extension
if(filesize($file['tmp_name']) > $config->get_int('upload_size')) // It is also currently broken due to some confusion over file variable ($tmp_filename?)
{
header("HTTP/1.0 409 Conflict");
header("X-Danbooru-Errors: too large");
return;
}
// Does it exist already? // Does it exist already?
$existing = $database->get_image_by_hash($image->hash); $existing = $database->get_image_by_hash($hash);
if(!is_null($existing)) { if(!is_null($existing)) {
header("HTTP/1.0 409 Conflict"); header("HTTP/1.0 409 Conflict");
header("X-Danbooru-Errors: duplicate"); header("X-Danbooru-Errors: duplicate");
@ -253,8 +244,14 @@ class DanbooruApi extends Extension
header("X-Danbooru-Location: $existinglink"); header("X-Danbooru-Location: $existinglink");
} }
// Fire off an event which should process the new image and add it to the db // Fire off an event which should process the new file and add it to the db
$nevent = new UploadingImageEvent($user, $image); $fileinfo = pathinfo($filename);
$metadata['filename'] = $fileinfo['basename'];
$metadata['extension'] = $fileinfo['extension'];
$metadata['tags'] = $posttags;
$metadata['source'] = $source;
$nevent = new DataUploadEvent($user, $file, $metadata);
send_event($nevent); send_event($nevent);
// Did something screw up? // Did something screw up?
if($event->vetoed) { if($event->vetoed) {
@ -263,7 +260,7 @@ class DanbooruApi extends Extension
return; return;
} else } else
{ // If it went ok, grab the id for the newly uploaded image and pass it in the header { // If it went ok, grab the id for the newly uploaded image and pass it in the header
$newimg = $database->get_image_by_hash($image->hash); $newimg = $database->get_image_by_hash($hash);
$newid = make_link("post/view/" . $newimg->id); $newid = make_link("post/view/" . $newimg->id);
// Did we POST or GET this call? // Did we POST or GET this call?
if($_SERVER['REQUEST_METHOD'] == 'POST') if($_SERVER['REQUEST_METHOD'] == 'POST')