mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 01:23:08 +03:00
slate: cleans up state, guarantees JSON response from endpoints, updates server code
This commit is contained in:
parent
d346919a3f
commit
5542f76888
@ -53,7 +53,7 @@ export const getSelectedState = (props) => {
|
||||
|
||||
return {
|
||||
address: null,
|
||||
// address: info.defaultStorageConfig.cold.filecoin.addr,
|
||||
address: info.defaultStorageConfig.cold.filecoin.addr,
|
||||
};
|
||||
};
|
||||
|
||||
@ -62,6 +62,14 @@ export const getInitialState = (props) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { ...props };
|
||||
};
|
||||
|
||||
export const _deprecated_getInitialState = (props) => {
|
||||
if (!props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
id,
|
||||
status,
|
||||
@ -89,20 +97,28 @@ export const getInitialState = (props) => {
|
||||
settings_deals_auto_approve: settings.deals_auto_approve,
|
||||
|
||||
// NOTE(jim): Powergate Hot Settings
|
||||
// settings_hot_enabled: info.defaultStorageConfig.hot.enabled,
|
||||
// settings_hot_allow_unfreeze: info.defaultStorageConfig.hot.allowUnfreeze,
|
||||
// settings_hot_ipfs_add_timeout: info.defaultStorageConfig.hot.ipfs.addTimeout,
|
||||
settings_hot_enabled: info.defaultStorageConfig.hot.enabled,
|
||||
settings_hot_allow_unfreeze: info.defaultStorageConfig.hot.allowUnfreeze,
|
||||
settings_hot_ipfs_add_timeout:
|
||||
info.defaultStorageConfig.hot.ipfs.addTimeout,
|
||||
|
||||
// NOTE(jim): Powergate Cold Settings
|
||||
// settings_cold_enabled: info.defaultStorageConfig.cold.enabled,
|
||||
// settings_cold_default_address: info.defaultStorageConfig.cold.filecoin.addr,
|
||||
// settings_cold_default_duration: info.defaultStorageConfig.cold.filecoin.dealMinDuration,
|
||||
// settings_cold_default_replication_factor: info.defaultStorageConfig.cold.filecoin.repFactor,
|
||||
// settings_cold_default_excluded_miners: info.defaultStorageConfig.cold.filecoin.excludedMinersList,
|
||||
// settings_cold_default_trusted_miners: info.defaultStorageConfig.cold.filecoin.trustedMinersList,
|
||||
// settings_cold_default_max_price: info.defaultStorageConfig.cold.filecoin.maxPrice,
|
||||
// settings_cold_default_auto_renew: info.defaultStorageConfig.cold.filecoin.renew.enabled,
|
||||
// settings_cold_default_auto_renew_max_price: info.defaultStorageConfig.cold.filecoin.renew.threshold,
|
||||
settings_cold_enabled: info.defaultStorageConfig.cold.enabled,
|
||||
settings_cold_default_address: info.defaultStorageConfig.cold.filecoin.addr,
|
||||
settings_cold_default_duration:
|
||||
info.defaultStorageConfig.cold.filecoin.dealMinDuration,
|
||||
settings_cold_default_replication_factor:
|
||||
info.defaultStorageConfig.cold.filecoin.repFactor,
|
||||
settings_cold_default_excluded_miners:
|
||||
info.defaultStorageConfig.cold.filecoin.excludedMinersList,
|
||||
settings_cold_default_trusted_miners:
|
||||
info.defaultStorageConfig.cold.filecoin.trustedMinersList,
|
||||
settings_cold_default_max_price:
|
||||
info.defaultStorageConfig.cold.filecoin.maxPrice,
|
||||
settings_cold_default_auto_renew:
|
||||
info.defaultStorageConfig.cold.filecoin.renew.enabled,
|
||||
settings_cold_default_auto_renew_max_price:
|
||||
info.defaultStorageConfig.cold.filecoin.renew.threshold,
|
||||
|
||||
storageList,
|
||||
retrievalList,
|
||||
@ -110,7 +126,7 @@ export const getInitialState = (props) => {
|
||||
keys,
|
||||
stats,
|
||||
library,
|
||||
// peers: transformPeers(peersList),
|
||||
// addresses: transformAddresses(addrsList, info),
|
||||
peers: transformPeers(peersList),
|
||||
addresses: transformAddresses(addrsList, info),
|
||||
};
|
||||
};
|
||||
|
@ -72,8 +72,8 @@ const SCENES = {
|
||||
|
||||
export default class ApplicationPage extends React.Component {
|
||||
state = {
|
||||
selected: State.getSelectedState(this.props.viewer),
|
||||
viewer: State.getInitialState(this.props.viewer),
|
||||
selected: {},
|
||||
viewer: this.props.viewer,
|
||||
history: [{ id: "V1_NAVIGATION_HOME", scrollTop: 0, data: null }],
|
||||
currentIndex: 0,
|
||||
data: null,
|
||||
@ -120,7 +120,11 @@ export default class ApplicationPage extends React.Component {
|
||||
}
|
||||
|
||||
// NOTE(jim): Only allow the sidebar to show with file drag and drop.
|
||||
if (e.dataTransfer.items && e.dataTransfer.items.length && e.dataTransfer.items[0].kind !== "file") {
|
||||
if (
|
||||
e.dataTransfer.items &&
|
||||
e.dataTransfer.items.length &&
|
||||
e.dataTransfer.items[0].kind !== "file"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -274,7 +278,8 @@ export default class ApplicationPage extends React.Component {
|
||||
_handleDeleteYourself = async () => {
|
||||
// TODO(jim):
|
||||
// Put this somewhere better for messages.
|
||||
const message = "Do you really want to delete your account? It will be permanently removed";
|
||||
const message =
|
||||
"Do you really want to delete your account? It will be permanently removed";
|
||||
if (!window.confirm(message)) {
|
||||
return false;
|
||||
}
|
||||
@ -445,8 +450,12 @@ export default class ApplicationPage extends React.Component {
|
||||
<WebsitePrototypeWrapper
|
||||
title="Slate: sign in"
|
||||
description="Sign in to your Slate account to manage your assets."
|
||||
url="https://slate.host/_">
|
||||
<SceneSignIn onAuthenticate={this._handleAuthenticate} onNavigateTo={this._handleNavigateTo} />
|
||||
url="https://slate.host/_"
|
||||
>
|
||||
<SceneSignIn
|
||||
onAuthenticate={this._handleAuthenticate}
|
||||
onNavigateTo={this._handleNavigateTo}
|
||||
/>
|
||||
</WebsitePrototypeWrapper>
|
||||
);
|
||||
}
|
||||
@ -519,12 +528,17 @@ export default class ApplicationPage extends React.Component {
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<WebsitePrototypeWrapper description={description} title={title} url={url}>
|
||||
<WebsitePrototypeWrapper
|
||||
description={description}
|
||||
title={title}
|
||||
url={url}
|
||||
>
|
||||
<ApplicationLayout
|
||||
header={headerElement}
|
||||
navigation={navigationElement}
|
||||
sidebar={sidebarElement}
|
||||
onDismissSidebar={this._handleDismissSidebar}>
|
||||
onDismissSidebar={this._handleDismissSidebar}
|
||||
>
|
||||
{scene}
|
||||
</ApplicationLayout>
|
||||
<System.GlobalCarousel />
|
||||
|
@ -4,14 +4,17 @@ export default async ({ key }) => {
|
||||
return await runQuery({
|
||||
label: "GET_API_KEY_BY_KEY",
|
||||
queryFn: async (DB) => {
|
||||
const query = await DB.select("*").from("keys").where({ key }).first();
|
||||
const query = await DB.select("*")
|
||||
.from("keys")
|
||||
.where({ key })
|
||||
.first();
|
||||
|
||||
if (!query || query.error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -14,7 +14,7 @@ export default async ({ id }) => {
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -12,7 +12,7 @@ export default async ({ userId }) => {
|
||||
return [];
|
||||
}
|
||||
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
|
@ -14,7 +14,7 @@ export default async ({ id }) => {
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -14,7 +14,7 @@ export default async ({ slatename }) => {
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -4,21 +4,28 @@ export default async ({ userId, publicOnly = false }) => {
|
||||
return await runQuery({
|
||||
label: "GET_SLATES_BY_USER_ID",
|
||||
queryFn: async (DB) => {
|
||||
const hasUser = (id) => DB.raw(`?? @> ?::jsonb`, ["data", JSON.stringify({ ownerId: id })]);
|
||||
const isPublic = () => DB.raw(`?? @> ?::jsonb`, ["data", JSON.stringify({ public: true })]);
|
||||
const hasUser = (id) =>
|
||||
DB.raw(`?? @> ?::jsonb`, ["data", JSON.stringify({ ownerId: id })]);
|
||||
const isPublic = () =>
|
||||
DB.raw(`?? @> ?::jsonb`, ["data", JSON.stringify({ public: true })]);
|
||||
|
||||
let query;
|
||||
if (publicOnly) {
|
||||
query = await DB.select("*").from("slates").where(hasUser(userId)).where(isPublic());
|
||||
query = await DB.select("*")
|
||||
.from("slates")
|
||||
.where(hasUser(userId))
|
||||
.where(isPublic());
|
||||
} else {
|
||||
query = await DB.select("*").from("slates").where(hasUser(userId));
|
||||
query = await DB.select("*")
|
||||
.from("slates")
|
||||
.where(hasUser(userId));
|
||||
}
|
||||
|
||||
if (!query || query.error) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
|
@ -14,7 +14,7 @@ export default async ({ id }) => {
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -14,7 +14,7 @@ export default async ({ username }) => {
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return query;
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -17,11 +17,8 @@ export const getById = async ({ id }) => {
|
||||
}
|
||||
|
||||
let data = null;
|
||||
const response = await Data.getSlatesByUserId({ userId: id });
|
||||
const slates = JSON.parse(JSON.stringify(response));
|
||||
|
||||
const keysRaw = await Data.getAPIKeysByUserId({ userId: id });
|
||||
const keys = JSON.parse(JSON.stringify(keysRaw));
|
||||
const slates = await Data.getSlatesByUserId({ userId: id });
|
||||
const keys = await Data.getAPIKeysByUserId({ userId: id });
|
||||
|
||||
let bytes = 0;
|
||||
user.data.library[0].children.forEach((each) => {
|
||||
@ -54,17 +51,6 @@ export const getById = async ({ id }) => {
|
||||
addrsList: null,
|
||||
info: null,
|
||||
};
|
||||
|
||||
// TODO(jim): Disables Powergate Features
|
||||
/*
|
||||
const updates = await Utilities.refresh(user);
|
||||
const updatesWithToken = await Utilities.refreshWithToken(user);
|
||||
|
||||
data = await Utilities.updateStateData(data, {
|
||||
...updates,
|
||||
...updatesWithToken,
|
||||
});
|
||||
*/
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
|
@ -98,7 +98,9 @@ export default class SlatePage extends React.Component {
|
||||
return {
|
||||
id: each.id,
|
||||
data: each,
|
||||
component: <SlateMediaObject key={each.id} useImageFallback data={each} />,
|
||||
component: (
|
||||
<SlateMediaObject key={each.id} useImageFallback data={each} />
|
||||
),
|
||||
};
|
||||
}),
|
||||
},
|
||||
@ -112,8 +114,10 @@ export default class SlatePage extends React.Component {
|
||||
});
|
||||
|
||||
render() {
|
||||
const title = `${this.props.slate.ownername}/${this.props.slate.slatename}`;
|
||||
const url = `https://slate.host/${this.props.slate.ownername}`;
|
||||
const title = `${this.props.creator.username}/${
|
||||
this.props.slate.slatename
|
||||
}`;
|
||||
const url = `https://slate.host/${this.props.creator.username}`;
|
||||
const description = this.props.slate.data.body;
|
||||
|
||||
let image;
|
||||
@ -124,12 +128,17 @@ export default class SlatePage extends React.Component {
|
||||
});
|
||||
|
||||
return (
|
||||
<WebsitePrototypeWrapper title={title} description={description} url={url} image={image}>
|
||||
<WebsitePrototypeWrapper
|
||||
title={title}
|
||||
description={description}
|
||||
url={url}
|
||||
image={image}
|
||||
>
|
||||
<div css={STYLES_ROOT}>
|
||||
<WebsitePrototypeHeaderGeneric href={url}>
|
||||
<div css={STYLES_HEADER}>
|
||||
<div css={STYLES_HEADER_LEFT}>
|
||||
{this.props.slate.ownername} / {this.props.slate.slatename}
|
||||
{this.props.creator.username} / {this.props.slate.slatename}
|
||||
</div>
|
||||
<div css={STYLES_HEADER_RIGHT}>{this.props.slate.data.body}</div>
|
||||
</div>
|
||||
|
24
server.js
24
server.js
@ -106,12 +106,12 @@ app.prepare().then(async () => {
|
||||
viewer,
|
||||
creator: {
|
||||
username: creator.username,
|
||||
slates,
|
||||
data: {
|
||||
photo: creator.data.photo,
|
||||
name: creator.data.name ? creator.data.name : creator.username,
|
||||
body: creator.data.body ? creator.data.body : "A user on Slate.",
|
||||
},
|
||||
slates: JSON.parse(JSON.stringify(slates)),
|
||||
},
|
||||
});
|
||||
});
|
||||
@ -148,10 +148,26 @@ app.prepare().then(async () => {
|
||||
return res.redirect("/403");
|
||||
}
|
||||
|
||||
const id = Utilities.getIdFromCookie(req);
|
||||
|
||||
let viewer = null;
|
||||
if (id) {
|
||||
viewer = await ViewerManager.getById({
|
||||
id,
|
||||
});
|
||||
}
|
||||
|
||||
return app.render(req, res, "/_/slate", {
|
||||
slate: JSON.parse(
|
||||
JSON.stringify({ ...slate, ownername: req.params.username })
|
||||
),
|
||||
viewer,
|
||||
creator: {
|
||||
username: creator.username,
|
||||
data: {
|
||||
photo: creator.data.photo,
|
||||
name: creator.data.name ? creator.data.name : creator.username,
|
||||
body: creator.data.body ? creator.data.body : "A user on Slate.",
|
||||
},
|
||||
},
|
||||
slate,
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user