web.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /** @var \Laravel\Lumen\Routing\Router $router */
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Application Routes
  6. |--------------------------------------------------------------------------
  7. |
  8. | Here is where you can register all of the routes for an application.
  9. | It is a breeze. Simply tell Lumen the URIs it should respond to
  10. | and give it the Closure to call when that URI is requested.
  11. |
  12. */
  13. use Illuminate\Support\Facades\Http;
  14. use Illuminate\Http\Request;
  15. $router->get('.well-known/webfinger', function (Request $request) use ($router) {
  16. $id = array();
  17. preg_match("/acct:(.+)@.+/", $request->input('resource'), $id);
  18. $id = $id[1];
  19. $userdir = '../userdata/'.$id;
  20. $webfingerfile = $userdir.'/webfinger.json';
  21. if (!file_exists($userdir)) {
  22. abort(404);
  23. } else {
  24. $myfile = fopen($webfingerfile, "r");
  25. $content = fread($myfile,filesize($webfingerfile));
  26. fclose($myfile);
  27. return response($content);
  28. }
  29. });
  30. $router->get('user/{id}', function ($id) use ($router) {
  31. $userdir = '../userdata/'.$id;
  32. $webfingerfile = $userdir.'/webfinger.json';
  33. if (!file_exists($userdir)) {
  34. abort(404);
  35. } else {
  36. $myfile = fopen($webfingerfile, "r");
  37. $content = fread($myfile,filesize($webfingerfile));
  38. fclose($myfile);
  39. return response($content);
  40. }
  41. });
  42. $router->get('/', function () use ($router) {
  43. return Http::withHeaders([
  44. 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
  45. ])->get('https://floss.social/api/v1/timelines/public');
  46. });