mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-14 12:08:01 +00:00
added new api and updated readme
This commit is contained in:
45
api/info.php
Normal file
45
api/info.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
// basic path definitions
|
||||||
|
define('DS', DIRECTORY_SEPARATOR);
|
||||||
|
define('ROOT', dirname(__FILE__).'/..');
|
||||||
|
|
||||||
|
//loading default settings if exist
|
||||||
|
if(!file_exists(ROOT.DS.'inc'.DS.'config.inc.php'))
|
||||||
|
exit('Rename /inc/example.config.inc.php to /inc/config.inc.php first!');
|
||||||
|
include_once(ROOT.DS.'inc'.DS.'config.inc.php');
|
||||||
|
|
||||||
|
//loading core and controllers
|
||||||
|
include_once(ROOT . DS . 'inc' . DS. 'core.php');
|
||||||
|
require_once(ROOT . DS . 'content-controllers' . DS. 'video'. DS . 'video.controller.php');
|
||||||
|
|
||||||
|
$hash = $_REQUEST['hash'];
|
||||||
|
|
||||||
|
if(!isExistingHash($hash))
|
||||||
|
{
|
||||||
|
//check storage controllers
|
||||||
|
|
||||||
|
exit(json_encode(array('status'=>'err','reason'=>'File not found')));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$answer = getInfoAboutHash($hash);
|
||||||
|
$answer['status'] = 'ok';
|
||||||
|
exit(json_encode($answer));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getInfoAboutHash($hash)
|
||||||
|
{
|
||||||
|
$file = ROOT.DS.'data'.DS.$hash.DS.$hash;
|
||||||
|
$size = filesize($file);
|
||||||
|
$size_hr = renderSize($size);
|
||||||
|
$content_type = exec("file -bi " . escapeshellarg($file));
|
||||||
|
if($content_type && $content_type!=$type && strpos($content_type,'/')!==false && strpos($content_type,';')!==false)
|
||||||
|
{
|
||||||
|
$type = $content_type;
|
||||||
|
$c = explode(';',$type);
|
||||||
|
$type = $c[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('hash'=>$hash,'size_bytes'=>$size,'size_interpreted'=>$size_hr,'type'=>$type,'type_interpreted'=>getTypeOfFile($file));
|
||||||
|
}
|
||||||
@@ -298,9 +298,11 @@ function getTypeOfFile($url)
|
|||||||
$type = $a2[1];
|
$type = $a2[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if($type=='octet-stream' && (new VideoController())->isProperMP4($url)) return 'mp4';
|
if($type=='octet-stream')
|
||||||
if($type=='mp4' && !(new VideoController())->isProperMP4($url))
|
if((new VideoController())->isProperMP4($url)) return 'mp4';
|
||||||
return false;
|
if($type=='mp4')
|
||||||
|
if(!(new VideoController())->isProperMP4($url))
|
||||||
|
return false;
|
||||||
|
|
||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|||||||
101
rtfm/API.md
101
rtfm/API.md
@@ -1,6 +1,6 @@
|
|||||||
# API
|
# API
|
||||||
|
|
||||||
## upload.php
|
# upload.php
|
||||||
|
|
||||||
- URL https://pictshare.net/api/upload.php
|
- URL https://pictshare.net/api/upload.php
|
||||||
- Method: POST file
|
- Method: POST file
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
If the upload was successful answer will look like this
|
If the upload was successful answer will look like this
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status":"ok",
|
"status":"ok",
|
||||||
"hash":"y1b6hr.jpg",
|
"hash":"y1b6hr.jpg",
|
||||||
@@ -19,7 +19,7 @@ If the upload was successful answer will look like this
|
|||||||
|
|
||||||
If there is an error the server will answer with status:err and a reason
|
If there is an error the server will answer with status:err and a reason
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status":"err",
|
"status":"err",
|
||||||
"reason":"Unsupported filetype"
|
"reason":"Unsupported filetype"
|
||||||
@@ -33,18 +33,76 @@ If there is an error the server will answer with status:err and a reason
|
|||||||
```curl -F "file=@test.jpg" https://pictshare.net/api/upload.php```
|
```curl -F "file=@test.jpg" https://pictshare.net/api/upload.php```
|
||||||
|
|
||||||
Answer from the server:
|
Answer from the server:
|
||||||
```{"status":"ok","hash":"y1b6hr.jpg","url":"https://pictshare.net/y1b6hr.jpg"}```
|
```json
|
||||||
|
{"status":"ok","hash":"y1b6hr.jpg","url":"https://pictshare.net/y1b6hr.jpg"}
|
||||||
|
```
|
||||||
|
|
||||||
2. Uploading a file called test.jpg via curl and requesting a custom hash
|
# geturl.php
|
||||||
|
|
||||||
```curl -F "file=@test.jpg" -F "hash=helloworld.jpg" https://pictshare.net/api/upload.php```
|
- URL https://pictshare.net/api/geturl.php
|
||||||
|
- Method: GET
|
||||||
|
- Var name: url
|
||||||
|
- Answer type: JSON
|
||||||
|
|
||||||
|
Upload content by providing a link to the content. If the link points to a website, the HTML of the page is uploaded as a text bin.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status":"ok",
|
||||||
|
"hash":"y1b6hr.jpg",
|
||||||
|
"url":"https://pictshare.net/y1b6hr.jpg",
|
||||||
|
"delete_code": "aqxqlv3kqokxd15xpkqp8zjljpqerveu",
|
||||||
|
"delete_url": "https://pictshare.net/delete_aqxqlv3kqokxd15xpkqp8zjljpqerveu/2mr2va.txt"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If there is an error the server will answer with status:err and a reason
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status":"err",
|
||||||
|
"reason":"Unsupported filetype"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
1. Uploading the HTML of xkcd.com
|
||||||
|
|
||||||
|
```curl -s https://pictshare.net/api/geturl.php?url=https://xkcd.com```
|
||||||
|
|
||||||
Answer from the server:
|
Answer from the server:
|
||||||
```{"status":"ok","hash":"helloworld.jpg","url":"https://pictshare.net/helloworld.jpg"}```
|
```json
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"hash": "2mr2va.txt",
|
||||||
|
"url": "https://pictshare.net/2mr2va.txt",
|
||||||
|
"filetype": "text",
|
||||||
|
"delete_code": "aqxqlv3kqokxd15xpkqp8zjljpqerveu",
|
||||||
|
"delete_url": "https://pictshare.net/delete_aqxqlv3kqokxd15xpkqp8zjljpqerveu/2mr2va.txt"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Uploading a Video from Imgur
|
||||||
|
|
||||||
|
```curl https://pictshare.net/api/geturl.php?url=https://i.imgur.com/qQstLQt.mp4```
|
||||||
|
|
||||||
|
Answer from the server:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"hash": "u0ni1m.mp4",
|
||||||
|
"url": "https://pictshare.net/u0ni1m.mp4",
|
||||||
|
"filetype": "mp4",
|
||||||
|
"delete_code": "aqxqlv3kqokxd15xpkqp8zjljpqerveu",
|
||||||
|
"delete_url": "https://pictshare.net/delete_aqxqlv3kqokxd15xpkqp8zjljpqerveu/u0ni1m.mp4"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## pasetebin.php
|
# pasetebin.php
|
||||||
- URL https://pictshare.net/api/pastebin.php
|
- URL https://pictshare.net/api/pastebin.php
|
||||||
- Method: POST/GET text
|
- Method: POST/GET text
|
||||||
- Post var name: api_paste_code
|
- Post var name: api_paste_code
|
||||||
@@ -56,7 +114,32 @@ This API can be used to directly post text. Server responds with the URL to the
|
|||||||
|
|
||||||
Creating a new text bin that ready "Hello World"
|
Creating a new text bin that ready "Hello World"
|
||||||
|
|
||||||
```url -F "api_paste_code=Hello World" https://pictshare.net/api/pastebin.php```
|
```curl -F "api_paste_code=Hello World" https://pictshare.net/api/pastebin.php```
|
||||||
|
|
||||||
Answer from the server:
|
Answer from the server:
|
||||||
```https://pictshare.net/vekjy4e5rr.txt```
|
```https://pictshare.net/vekjy4e5rr.txt```
|
||||||
|
|
||||||
|
# info.php
|
||||||
|
- URL https://pictshare.net/api/info.php
|
||||||
|
- Method: POST/GET text
|
||||||
|
- Query var name: hash
|
||||||
|
- Answer: JSON
|
||||||
|
|
||||||
|
This API will get information about any given hash.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```curl https://pictshare.net/api/info.php?hash=9k3rbw.mp4```
|
||||||
|
|
||||||
|
Answer from the server:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"hash": "9k3rbw.mp4",
|
||||||
|
"size_bytes": 2513225,
|
||||||
|
"size_interpreted": "2.4 MB",
|
||||||
|
"type": "video/mp4",
|
||||||
|
"type_interpreted": "mp4"
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user