soselo/api/v1/cache/put/mod.php

31 lines
982 B
PHP

<?php
$_ = function() {
if (!isset($_GET['keys']))
return apiresult(['error' => '<key> parameter was not provided'], 400);
if (!isset($_GET['content']))
return apiresult(['error' => '<content> parameter was not provided'], 400);
$expires = 3600;
if (isset($_GET['expires']))
$expires = intval($_GET['expires']);
$keys = explode(';', trim($_GET['keys']));
$content = trim($_GET['content']);
$nkeys = [];
foreach ($keys as $key) {
$key = trim($key);
if (strpos($key, 'hash:') === 0)
$key = md5(trim(substr($key, strpos($key, 'hash:')+5)));
$key = _cachekey($key);
$nkeys [] = $key;
}
$key = implode(',', $nkeys);
$result = content_cache__put($key, 'ondemand,'.$expires, $content);
$realkey = md5($key).',ondemand,'.$expires;
if (gettype($result) === 'integer')
return apiresult(['ok' => 'Cached content created with key: '.$key, 'data' => $realkey]);
return apiresult(['error' => 'Unknown error when creating the cache key: '.$key], 500);
};
$_();