Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Lightshot API
<?php
function addLog($text, $debug = false) {
if ($debug) {
file_put_contents("debug_log.txt", $text . PHP_EOL, FILE_APPEND);
}
}
function makeResponse($request) {
return array(
"jsonrpc" => "2.0",
"id" => $request["id"],
"result" => array(
"url" => $request["params"]["img_url"],
"info" => "The image saved to user gallery (short url)",
"success" => true
) ,
);
}
//Get the raw POST data.
$raw_json = file_get_contents("php://input");
addLog("Request: " . $raw_json);
//Decode the JSON request.
$request = json_decode($raw_json, true);
addLog("img_url: " . $request["params"]["img_url"]);
//Construct the response.
$response = makeResponse($request);
$response_json = json_encode($response);
addLog("Response: " . $response_json);
//Set the response header and echo the response.
header('Content-type: application/json');
echo $response_json;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment