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
| namespace App\Http\Controllers\Api\Gallery;
use Cache; use Storage; use App\Helpers\Link; use Illuminate\Http\Request; use App\Http\Controllers\Controller;
class PhotoController extends Controller { protected $request;
public function __construct(Request $request) { $this->request = $request; }
public function index() { $resource = implode('/', [ 'images', 'web', $this->request->category, $this->request->album, ]);
$minutes = config('default.cache.minutes.photos');
$photos = Cache::remember($resource, $minutes, function () use ($resource) { $explode = function($self) { $array = explode('/', str_replace('images/web/', '', $self));
$params = config('app.url') . '/gallery/photos?' . http_build_query([ 'category' => $array[0], 'album' => $array[1], 'photo' => $array[2], ]);
return [ 'name' => basename($self, '.jpg'), 'path' => [ 'web' => $params . '&size=web', 'raw' => $params . '&size=raw', 'download' => $params . '&size=raw&download=true', 'share' => Link::shorten($params . '&size=raw'), ], ]; };
return array_map($explode, Storage::files($resource)); });
return response([ 'data' => $photos, ], 200); } }
|