2020-07-17 13:24:20 +03:00
|
|
|
import * as MW from "~/node_common/middleware";
|
|
|
|
import * as Utilities from "~/node_common/utilities";
|
|
|
|
import * as Constants from "~/node_common/constants";
|
|
|
|
import * as Data from "~/node_common/data";
|
|
|
|
|
|
|
|
import PG from "~/node_common/powergate";
|
2020-07-20 09:06:36 +03:00
|
|
|
import FS from "fs-extra";
|
|
|
|
import path from "path";
|
2020-07-17 13:24:20 +03:00
|
|
|
|
|
|
|
const initCORS = MW.init(MW.CORS);
|
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
initCORS(req, res);
|
|
|
|
|
|
|
|
const user = await Data.getUserByUsername({
|
|
|
|
username: req.body.data.username,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return res.status(200).json({ decorator: "SERVER_HYDRATE", error: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.error) {
|
|
|
|
return res.status(200).json({ decorator: "SERVER_HYDRATE", error: true });
|
|
|
|
}
|
|
|
|
|
2020-07-20 09:06:36 +03:00
|
|
|
const {
|
|
|
|
buckets,
|
|
|
|
bucketKey,
|
|
|
|
bucketName,
|
|
|
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api);
|
2020-07-17 13:24:20 +03:00
|
|
|
|
2020-07-20 09:06:36 +03:00
|
|
|
// TODO(jim): This is obviously a test!
|
|
|
|
// Slates will hold an index
|
|
|
|
// Library will hold an index
|
2020-07-17 13:24:20 +03:00
|
|
|
let data = {
|
|
|
|
peersList: null,
|
|
|
|
messageList: null,
|
|
|
|
status: null,
|
|
|
|
addrsList: null,
|
|
|
|
info: null,
|
|
|
|
state: null,
|
|
|
|
local: {
|
|
|
|
photo: null,
|
|
|
|
name: `node`,
|
|
|
|
settings_deals_auto_approve: false,
|
|
|
|
},
|
|
|
|
library: [
|
|
|
|
{
|
2020-07-20 09:06:36 +03:00
|
|
|
...Utilities.createFolder({ id: bucketName }),
|
|
|
|
file: bucketName,
|
|
|
|
name: bucketName,
|
|
|
|
children: [
|
|
|
|
await Utilities.addFileFromFilePath({
|
|
|
|
buckets,
|
|
|
|
bucketKey,
|
|
|
|
filePath: "./public/static/social.jpg",
|
|
|
|
}),
|
|
|
|
await Utilities.addFileFromFilePath({
|
|
|
|
buckets,
|
|
|
|
bucketKey,
|
|
|
|
filePath: "./public/static/cube_000.jpg",
|
|
|
|
}),
|
|
|
|
await Utilities.addFileFromFilePath({
|
|
|
|
buckets,
|
|
|
|
bucketKey,
|
|
|
|
filePath: "./public/static/cube_f7f7f7.jpg",
|
|
|
|
}),
|
|
|
|
],
|
2020-07-17 13:24:20 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-07-20 09:06:36 +03:00
|
|
|
// NOTE(jim): Should render a list of buckets.
|
|
|
|
const roots = await buckets.list();
|
|
|
|
console.log({ roots });
|
|
|
|
|
2020-07-17 13:24:20 +03:00
|
|
|
PG.setToken(user.data.tokens.pg);
|
|
|
|
|
|
|
|
const updates = await Utilities.refresh({ PG });
|
|
|
|
const updatesWithToken = await Utilities.refreshWithToken({
|
|
|
|
PG,
|
|
|
|
});
|
|
|
|
|
|
|
|
data = await Utilities.updateStateData(data, {
|
|
|
|
...updates,
|
|
|
|
...updatesWithToken,
|
|
|
|
});
|
|
|
|
|
|
|
|
return res
|
|
|
|
.status(200)
|
|
|
|
.send({ decorator: "SERVER_HYDRATE", success: true, data });
|
|
|
|
};
|