diff options
Diffstat (limited to 'application/controllers/api')
-rw-r--r-- | application/controllers/api/api_controller.php | 14 | ||||
-rw-r--r-- | application/controllers/api/v1/api_info.php | 16 | ||||
-rw-r--r-- | application/controllers/api/v1/file.php | 81 | ||||
-rw-r--r-- | application/controllers/api/v1/user.php | 39 |
4 files changed, 150 insertions, 0 deletions
diff --git a/application/controllers/api/api_controller.php b/application/controllers/api/api_controller.php new file mode 100644 index 000000000..2b9054b17 --- /dev/null +++ b/application/controllers/api/api_controller.php @@ -0,0 +1,14 @@ +<?php +/* + * Copyright 2014 Florian "Bluewind" Pritz <bluewind@server-speed.net> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +namespace controllers\api; + +abstract class api_controller extends \CI_Controller { +} + diff --git a/application/controllers/api/v1/api_info.php b/application/controllers/api/v1/api_info.php new file mode 100644 index 000000000..3feaadfda --- /dev/null +++ b/application/controllers/api/v1/api_info.php @@ -0,0 +1,16 @@ +<?php +/* + * Copyright 2014 Florian "Bluewind" Pritz <bluewind@server-speed.net> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ +namespace controllers\api\v1; + +class api_info extends \controllers\api\api_controller { + static public function get_version() + { + return "1.0.0"; + } +} diff --git a/application/controllers/api/v1/file.php b/application/controllers/api/v1/file.php new file mode 100644 index 000000000..a10aaf63a --- /dev/null +++ b/application/controllers/api/v1/file.php @@ -0,0 +1,81 @@ +<?php +/* + * Copyright 2014 Florian "Bluewind" Pritz <bluewind@server-speed.net> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ +namespace controllers\api\v1; + +class file extends \controllers\api\api_controller { + public function __construct() + { + parent::__construct(); + + $this->load->model('mfile'); + $this->load->model('mmultipaste'); + } + + public function upload() + { + $this->muser->require_access("basic"); + + $files = getNormalizedFILES(); + + if (empty($files)) { + throw new \exceptions\PublicApiException("file/no-file", "No file was uploaded or unknown error occurred."); + } + + \service\files::verify_uploaded_files($files); + + $limits = $this->muser->get_upload_id_limits(); + $urls = array(); + + foreach ($files as $file) { + $id = $this->mfile->new_id($limits[0], $limits[1]); + \service\files::add_file($id, $file["tmp_name"], $file["name"]); + $ids[] = $id; + $urls[] = site_url($id).'/'; + } + + return array( + "ids" => $ids, + "urls" => $urls, + ); + } + + public function get_config() + { + // TODO: return more fields? + return array( + "upload_max_size" => $this->config->item("upload_max_size"), + "max_files_per_request" => intval(ini_get("max_file_uploads")), + ); + } + + public function history() + { + $this->muser->require_access("apikey"); + $history = \service\files::history($this->muser->get_userid()); + return $history; + } + + public function delete() + { + $this->muser->require_access("apikey"); + $ids = $this->input->post("ids"); + return \service\files::delete($ids); + } + + public function create_multipaste() + { + $this->muser->require_access("apikey"); + $ids = $this->input->post("ids"); + $userid = $this->muser->get_userid(); + $limits = $this->muser->get_upload_id_limits(); + + return \service\files::create_multipaste($ids, $userid, $limits); + } +} +# vim: set noet: diff --git a/application/controllers/api/v1/user.php b/application/controllers/api/v1/user.php new file mode 100644 index 000000000..e49b7c657 --- /dev/null +++ b/application/controllers/api/v1/user.php @@ -0,0 +1,39 @@ +<?php +/* + * Copyright 2014 Florian "Bluewind" Pritz <bluewind@server-speed.net> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ +namespace controllers\api\v1; + +class user extends \controllers\api\api_controller { + public function __construct() + { + parent::__construct(); + + $this->load->model('muser'); + } + + public function apikeys() + { + $this->muser->require_access("full"); + return \service\user::apikeys($this->muser->get_userid()); + } + + public function create_apikey() + { + $this->muser->require_access("full"); + $userid = $this->muser->get_userid(); + $comment = $this->input->post("comment"); + $comment = $comment === false ? "" : $comment; + $access_level = $this->input->post("access_level"); + + $key = \service\user::create_apikey($userid, $comment, $access_level); + + return array( + "new_key" => $key, + ); + } +} |