aboutsummaryrefslogtreecommitdiffstats
path: root/apidoc/api_data.json
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-03-04 09:47:26 -0800
committerAdam Soltys <[email protected]>2020-03-04 09:47:26 -0800
commit6411dcd13897ba69cc252dd26b5cb5b9b2560aca (patch)
tree5ff48f27bb62851e5f8704bc853143e4ea704baa /apidoc/api_data.json
parent816d3c6e8e054c649b6d5dc48bc900fa7b6b842e (diff)
downloadcoinos-server-6411dcd13897ba69cc252dd26b5cb5b9b2560aca.tar.gz
coinos-server-6411dcd13897ba69cc252dd26b5cb5b9b2560aca.zip
add long dependency
Diffstat (limited to 'apidoc/api_data.json')
0 files changed, 0 insertions, 0 deletions
a id='n7' href='#n7'>7 8 9 10 11 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 = form.get("request_id");
  if (request_id === "undefined") request_id = undefined;

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

  let user = { username: form.get("username"), currency: form.get("currency") };

  invoice = await post("/invoice", { invoice, user }, auth(cookies));
  let { id } = invoice;

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

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

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