2021-08-27 08:03:24 -05:00
|
|
|
/*!
|
|
|
|
toot - Cross-instance share page for Mastodon
|
2022-02-12 06:36:08 -05:00
|
|
|
Copyright (C) 2020-2022 Nikita Karamov <me@kytta.dev>
|
2021-08-27 08:03:24 -05:00
|
|
|
|
|
|
|
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, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-08-27 08:49:51 -05:00
|
|
|
const http = require("http");
|
|
|
|
|
|
|
|
http
|
2023-03-01 06:42:33 -05:00
|
|
|
.createServer(async (request, response) => {
|
2021-08-27 08:49:51 -05:00
|
|
|
const buffers = [];
|
2023-03-01 06:42:33 -05:00
|
|
|
for await (const chunk of request) {
|
2021-08-27 08:49:51 -05:00
|
|
|
buffers.push(chunk);
|
2021-08-27 08:03:24 -05:00
|
|
|
}
|
2021-08-27 08:49:51 -05:00
|
|
|
const data = Buffer.concat(buffers).toString();
|
2023-03-01 06:42:33 -05:00
|
|
|
const searchParameters = new URLSearchParams(data);
|
2021-08-27 08:49:51 -05:00
|
|
|
|
2023-03-01 06:42:33 -05:00
|
|
|
const text = searchParameters.get("text") || "";
|
|
|
|
const instanceURL =
|
|
|
|
searchParameters.get("instance") || "https://mastodon.social/";
|
2021-08-27 08:49:51 -05:00
|
|
|
|
|
|
|
const finalURL = new URL("share", instanceURL);
|
|
|
|
finalURL.search = new URLSearchParams({ text }).toString();
|
2021-08-27 08:03:24 -05:00
|
|
|
|
2023-03-01 06:42:33 -05:00
|
|
|
response.writeHead(303, { Location: finalURL.toString() }).end();
|
2021-08-27 08:49:51 -05:00
|
|
|
})
|
|
|
|
.listen(8000);
|