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
symfony-version
Ro 2 years ago
parent b8eda54267
commit 88e78f2c4a
Signed by untrusted user: are0h
GPG Key ID: 29B551CDBD4D3B50

@ -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);
}

@ -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";

@ -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;
}
}
} }

@ -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;
}
}

@ -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 %}
Loading…
Cancel
Save