This repository has been archived on 2021-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
backend/src/main.cpp

100 lines
2.4 KiB
C++

/* This file is part of FediBlock-backend.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cgi.hpp"
#include "files.hpp"
#include "fs-compat.hpp"
#include "git.hpp"
#include "gitea.hpp"
#include "json.hpp"
#include <git2/global.h>
#include <exception>
#include <iostream>
#include <string>
using std::cerr;
using std::cout;
using std::exception;
using std::to_string;
using namespace FediBlock;
void print_debug(const cgi::entry_type &entry)
{
cout << "\r\n\r\nDEBUG:\r\n";
cout << " Instance: " << entry.instance << "\r\n";
cout << " Tags:";
for (const auto &tag : entry.tags)
{
cout << " " << tag;
}
cout << "\r\n";
cout << " Receipts:";
for (const auto &receipt : entry.receipts)
{
cout << " " << receipt;
}
cout << "\r\n";
cout << " Description: " << entry.description << "\r\n";
cout << " Screenshot: " << entry.screenshot_filepath << "\r\n";
cout << "\r\n\r\nJSON:\r\n";
cout << json::to_json(entry) << "\r\n";
cout << "\r\n\r\nDATADIR: " << files::get_datadir() << "\r\n";
}
int main()
{
cout << "Content-Type: text/plain; charset=utf-8\r\n\r\n";
cout << "Received and filed to /dev/null. 😝\r\n";
const cgi::entry_type entry{cgi::parse_formdata()};
print_debug(entry);
git_libgit2_init();
git::clone();
git::create_branch();
git::commit(entry);
git::push();
cout << "Created branch: "
<< "<https://schlomp.space/FediBlock/data/src/branch/web-"
<< git::get_last_id() << ">\r\n";
gitea::init();
gitea::pull_request("web-" + to_string(git::get_last_id()), entry);
try
{
files::remove_tmpdir();
}
catch (const exception &e)
{
cerr << e.what() << '\n';
}
git_libgit2_shutdown();
gitea::cleanup();
return 0;
}