Move web related stuff to root
This commit is contained in:
50
root/get-album-entries.php
Normal file
50
root/get-album-entries.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* Copyright (C) 2021 Alexander Rosenberg
|
||||
* This file is AGPL v3. See LICENSE file for more information
|
||||
*/
|
||||
require 'library.php';
|
||||
require 'Album.php';
|
||||
|
||||
header("Content-Type: text/html");
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
function get_albums() {
|
||||
global $LIBRARY_INFO;
|
||||
$albums = [];
|
||||
$start = $_GET['start'];
|
||||
$end = $_GET['end'];
|
||||
if (!ctype_digit($start) || !ctype_digit($end) || $start > $end) {
|
||||
echo 'Invalid range!';
|
||||
http_response_code(400);
|
||||
exit(0);
|
||||
}
|
||||
$len = count($LIBRARY_INFO['albums']);
|
||||
if ($start >= $len) {
|
||||
return array();
|
||||
}
|
||||
if ($end >= $len) {
|
||||
$end = $len - 1;
|
||||
}
|
||||
$albums = [];
|
||||
for ($i = $start; $i <= $end; ++$i) {
|
||||
$albums[] = new Album($LIBRARY_INFO['albums'][$i]);
|
||||
}
|
||||
return $albums;
|
||||
}
|
||||
|
||||
switch ($method) {
|
||||
case 'HEAD':
|
||||
case 'GET':
|
||||
$albums = get_albums();
|
||||
foreach ($albums as $album) {
|
||||
echo $album->get_html();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
echo 'Method not permitted';
|
||||
http_response_code(405);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user