summaryrefslogtreecommitdiffstats
path: root/application/controllers/api/v1/file.php
blob: 869d29ed105ddccccffc531977ff5f4daaf67b5b (plain)
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
<?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)) {
			show_error("No file was uploaded or unknown error occured.");
		}

		$errors = \service\files::verify_uploaded_files($files);
		if (!empty($errors)) {
			return send_json_error_reply("file/upload-verify-failed", "Failed to verify uploaded file", $errors);
		}

		$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 send_json_reply(array(
			"ids" => $ids,
			"urls" => $urls,
		));
	}

	public function get_config()
	{
		return send_json_reply(array(
			"upload_max_size" => $this->config->item("upload_max_size"),
		));
	}

	public function history()
	{
		$this->muser->require_access("apikey");
		$history = \service\files::history($this->muser->get_userid());
		return send_json_reply($history);
	}

	public function delete()
	{
		$this->muser->require_access("apikey");


	}
}
# vim: set noet: