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:
parent
b8eda54267
commit
88e78f2c4a
5 changed files with 89 additions and 0 deletions
12
public/assets/css/front/exports.css
Normal file
12
public/assets/css/front/exports.css
Normal 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);
|
||||
}
|
|
@ -7,3 +7,4 @@
|
|||
@import "about.css";
|
||||
@import "listing.css";
|
||||
@import "location.css";
|
||||
@import "exports.css";
|
||||
|
|
|
@ -12,6 +12,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use App\Service\Auth;
|
||||
use App\Service\Render;
|
||||
use App\Service\HandleLocations;
|
||||
use App\Service\HandleExports;
|
||||
|
||||
class Index extends AbstractController
|
||||
{
|
||||
|
@ -95,4 +96,27 @@ class Index extends AbstractController
|
|||
"prevPage" => $prev
|
||||
], "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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
41
src/Service/HandleExports.php
Normal file
41
src/Service/HandleExports.php
Normal 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;
|
||||
}
|
||||
}
|
11
templates/front/exports.twig
Normal file
11
templates/front/exports.twig
Normal 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 %}
|
Loading…
Reference in a new issue