2021-03-28 00:33:47 +01:00
|
|
|
const API = 'https://api.lbry.com/';
|
|
|
|
const USER_TAG = 'lbry-sec';
|
|
|
|
|
2021-03-28 04:42:43 +02:00
|
|
|
function buildUrl(email) {
|
|
|
|
let url = `${API}/list/subscribe?email=${encodeURIComponent(
|
2021-03-28 00:33:47 +01:00
|
|
|
email
|
|
|
|
)}&tag=${USER_TAG}`;
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (req, res) => {
|
|
|
|
const { email } = req.body;
|
|
|
|
|
|
|
|
if (!email) {
|
|
|
|
res.statusCode = 400;
|
2021-03-28 00:37:51 +01:00
|
|
|
res.json({ error: 'no email passed to api' });
|
2021-03-28 00:33:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fetch(buildUrl(email))
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
2021-03-28 04:42:43 +02:00
|
|
|
if (res.error) {
|
|
|
|
throw Error(res.error);
|
2021-03-28 00:33:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
res.statusCode = 200;
|
|
|
|
res.json({ success: true });
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
res.statusCode = 400;
|
2021-03-28 04:42:43 +02:00
|
|
|
res.json({ error });
|
2021-03-28 00:33:47 +01:00
|
|
|
});
|
|
|
|
};
|