slate/node_common/models.js

57 lines
1.1 KiB
JavaScript
Raw Normal View History

import * as Utilities from "~/node_common/utilities";
import * as Data from "~/node_common/data";
import PG from "~/node_common/powergate";
export const getViewer = async ({ username }) => {
const user = await Data.getUserByUsername({
username,
});
if (!user) {
return null;
}
if (user.error) {
return null;
}
// NOTE(jim): Essential for getting the right Powergate data for a user.
PG.setToken(user.data.tokens.pg);
const {
buckets,
bucketKey,
bucketName,
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api);
let data = {
id: user.id,
data: user.data,
peersList: null,
messageList: null,
status: null,
addrsList: null,
info: null,
state: null,
local: {
photo: null,
name: `node`,
settings_deals_auto_approve: false,
},
library: user.data.library,
};
const updates = await Utilities.refresh({ PG });
const updatesWithToken = await Utilities.refreshWithToken({
PG,
});
data = await Utilities.updateStateData(data, {
...updates,
...updatesWithToken,
});
return data;
};