2020-07-22 09:04:54 +03:00
|
|
|
import * as MW from "~/node_common/middleware";
|
|
|
|
import * as Utilities from "~/node_common/utilities";
|
|
|
|
import * as Data from "~/node_common/data";
|
2020-07-24 02:56:50 +03:00
|
|
|
import * as Powergate from "~/node_common/powergate";
|
2020-07-22 09:04:54 +03:00
|
|
|
|
|
|
|
const initCORS = MW.init(MW.CORS);
|
|
|
|
const initAuth = MW.init(MW.RequireCookieAuthentication);
|
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
initCORS(req, res);
|
|
|
|
initAuth(req, res);
|
|
|
|
|
2020-07-22 13:51:40 +03:00
|
|
|
const id = Utilities.getIdFromCookie(req);
|
|
|
|
if (!id) {
|
2020-07-22 09:04:54 +03:00
|
|
|
return res
|
|
|
|
.status(500)
|
|
|
|
.json({ decorator: "SERVER_SEND_FILECOIN", error: true });
|
|
|
|
}
|
|
|
|
|
2020-07-22 13:51:40 +03:00
|
|
|
const user = await Data.getUserById({
|
|
|
|
id,
|
2020-07-22 09:04:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return res
|
2020-07-27 05:06:45 +03:00
|
|
|
.status(404)
|
|
|
|
.json({ decorator: "SERVER_SEND_FILECOIN_USER_NOT_FOUND", error: true });
|
2020-07-22 09:04:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (user.error) {
|
|
|
|
return res
|
2020-07-27 05:06:45 +03:00
|
|
|
.status(500)
|
|
|
|
.json({ decorator: "SERVER_SEND_FILECOIN_USER_NOT_FOUND", error: true });
|
2020-07-22 09:04:54 +03:00
|
|
|
}
|
|
|
|
|
2020-07-24 02:56:50 +03:00
|
|
|
const PG = Powergate.get(user);
|
|
|
|
|
2020-07-22 09:04:54 +03:00
|
|
|
let data;
|
|
|
|
try {
|
|
|
|
data = await PG.ffs.sendFil(
|
|
|
|
req.body.data.source,
|
|
|
|
req.body.data.target,
|
|
|
|
req.body.data.amount
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
return res
|
|
|
|
.status(500)
|
2020-07-27 05:06:45 +03:00
|
|
|
.send({ decorator: "SERVER_SEND_FILECOIN_ACTION_FAILURE", error: true });
|
2020-07-22 09:04:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return res.status(200).json({ decorator: "SERVER_SEND_FILECOIN" });
|
|
|
|
};
|