<?php
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
require_once __DIR__ . '/utils.php';

$data = read_db();

usort($data, function($a, $b) {
  return strtotime($b['uploaded_at'] ?? 0) <=> strtotime($a['uploaded_at'] ?? 0);
});

echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);