1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
/*
* Copyright 2014-2015 Florian "Bluewind" Pritz <bluewind@server-speed.net>
*
* Licensed under AGPLv3
* (see COPYING for full license text)
*
*/
namespace controllers\api\v2;
class file extends \controllers\api\api_controller {
public function __construct()
{
parent::__construct();
$this->CI->load->model('mfile');
$this->CI->load->model('mmultipaste');
}
public function upload()
{
$this->CI->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->CI->muser->get_upload_id_limits();
$userid = $this->CI->muser->get_userid();
$urls = array();
foreach ($files as $file) {
$id = $this->CI->mfile->new_id($limits[0], $limits[1]);
\service\files::add_uploaded_file($userid, $id, $file["tmp_name"], $file["name"]);
$ids[] = $id;
$urls[] = site_url($id).'/';
}
return array(
"ids" => $ids,
"urls" => $urls,
);
}
public function get_config()
{
return array(
"upload_max_size" => $this->CI->config->item("upload_max_size"),
"max_files_per_request" => intval(ini_get("max_file_uploads")),
"max_input_vars" => intval(ini_get("max_input_vars")),
"request_max_size" => return_bytes(ini_get("post_max_size")),
);
}
public function history()
{
$this->CI->muser->require_access("apikey");
$history = \service\files::history($this->CI->muser->get_userid());
foreach ($history['items'] as $key => $item) {
unset($history['items'][$key]['preview_text']);
}
foreach ($history['multipaste_items'] as $key => $item) {
foreach ($item['items'] as $inner_key => $item) {
unset($history['multipaste_items'][$key]['items'][$inner_key]['sort_order']);
}
}
$history = ensure_json_keys_contain_objects($history, array("items", "multipaste_items"));
return $history;
}
public function delete()
{
$this->CI->muser->require_access("apikey");
$ids = $this->CI->input->post_array("ids");
$ret = \service\files::delete($ids);
$ret = ensure_json_keys_contain_objects($ret, array("errors", "deleted"));
return $ret;
}
public function create_multipaste()
{
$this->CI->muser->require_access("basic");
$ids = $this->CI->input->post_array("ids");
$userid = $this->CI->muser->get_userid();
$limits = $this->CI->muser->get_upload_id_limits();
return \service\files::create_multipaste($ids, $userid, $limits);
}
}
# vim: set noet:
|