CSV Export for Mastdon

Added a link to export current active sites in the DB to a consumable
CSV file. More formats will be added but this one needs to be tested
first based on the ubiquity of Mastodon
This commit is contained in:
Ro 2023-04-12 16:46:21 -07:00
parent b8eda54267
commit 88e78f2c4a
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
5 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,12 @@
section[role="exports"] {
background: var(--primary);
width: 100%;
max-width: 600px;
padding: 10px;
margin: 0 auto;
color: var(--white);
}
section[role="exports"] a {
color: var(--highlight);
}

View file

@ -7,3 +7,4 @@
@import "about.css"; @import "about.css";
@import "listing.css"; @import "listing.css";
@import "location.css"; @import "location.css";
@import "exports.css";

View file

@ -12,6 +12,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Service\Auth; use App\Service\Auth;
use App\Service\Render; use App\Service\Render;
use App\Service\HandleLocations; use App\Service\HandleLocations;
use App\Service\HandleExports;
class Index extends AbstractController class Index extends AbstractController
{ {
@ -95,4 +96,27 @@ class Index extends AbstractController
"prevPage" => $prev "prevPage" => $prev
], "About The Bad Space", "front/listing.twig"); ], "About The Bad Space", "front/listing.twig");
} }
/**
* @Route("/exports/{type}", name="exports")
*/
public function showExports(
Request $request,
Auth $auth,
Render $render,
HandleLocations $locations,
HandleExports $exports,
string $type = "none"
): Response {
switch ($type) {
case 'none':
case '':
return $render->page([], "File Exports", "front/exports.twig");
break;
case 'mastodon':
return $exports->buildMastodonCSV();
break;
}
}
} }

View file

@ -0,0 +1,41 @@
<?php
namespace App\Service;
use Symfony\Component\HttpFoundation\Response;
use League\Csv\Reader;
class HandleExports
{
private $locations;
public function __construct(HandleLocations $locations)
{
$this->locations = $locations;
}
public function buildMastodonCSV()
{
$records = [['domain', 'severity', 'public_comment', 'reject_media', 'reject_reports', 'obfuscate']];
$entries = $this->locations->getActiveLocations();
foreach ($entries as $entry) {
$item = [$entry->getUrl(), $entry->getRating(), $entry->getDescription(), "FALSE", "FALSE", "FALSE"];
array_push($records, $item);
}
$tmp = new \SplTempFileObject();
foreach ($records as $record) {
$tmp->fputcsv($record);
}
$reader = Reader::createFromFileObject($tmp);
return new Response($reader->getContent(), 200, [
'Content-Encoding' => 'none',
'Content-Type' => 'text/csv; charset=UTF-8',
'Content-Disposition' => 'attachment; filename="the-bad-space-mastodon.csv"',
'Content-Description' => 'File Transfer',
]);
//return $path;
}
}

View file

@ -0,0 +1,11 @@
{% extends "base/frame.twig" %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=sdfsdf">
{% endblock %}
{% block main %}
<section role="exports">
<h1>File Exports</h1>
<a href="/exports/mastodon">For Mastodon</a>
</section>
{% endblock %}