aboutsummaryrefslogtreecommitdiffstats
path: root/apidoc
Commit message (Expand)AuthorAgeFilesLines
* es6 migrationAdam Soltys2022-09-027-14/+14
* Documented /api/infoAdrien Hopkins2021-08-304-2/+76
* Compiled existing api docs to ./apidoc/Adrien Hopkins2021-08-3052-0/+5893
n12' href='#n12'>12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
import { auth, get, post } from '$lib/utils';
import { redirect } from '@sveltejs/kit';

export default async ({ cookies, request, url }) => {
	let form = await request.formData();

	let rates = await get('/rates');
	let amount = parseInt(form.get('amount'));
	let request_id = parseInt(form.get('request_id'));

	let invoice = {
		amount,
		tip: parseInt(form.get('tip')),
		network: form.get('network'),
		prompt: form.get('prompt') === 'true',
		rate: parseFloat(form.get('rate')) || rates[form.get('currency')],
		request_id
	};

	let user = { username: form.get('username') };

	let { uuid } = await post('/invoice', { invoice, user }, auth(cookies));

	if (request_id) {
		if (url.pathname.endsWith('tip')) {
			throw redirect(307, `/send/${uuid}`);
		}

		throw redirect(307, `/${user.username}/request/${request_id}`);
	}

	if (invoice.prompt) {
		throw redirect(307, `/invoice/${uuid}/tip`);
	} else {
		throw redirect(307, `/invoice/${uuid}`);
	}
};