sidebar: stubs out filecoin archive feature

This commit is contained in:
@wwwjim 2020-08-27 23:57:04 -07:00
parent 40cecb363e
commit a0082a7be5
6 changed files with 140 additions and 1 deletions

View File

@ -46,6 +46,12 @@ export const sendFilecoin = async (data) => {
}); });
}; };
export const archive = async () => {
return await returnJSON(`/api/data/archive`, {
...DEFAULT_OPTIONS,
});
};
export const getNetworkDirectory = async () => { export const getNetworkDirectory = async () => {
return await returnJSON(`/api/directory`, { return await returnJSON(`/api/directory`, {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,

View File

@ -33,6 +33,7 @@ import SidebarFileStorageDeal from "~/components/sidebars/SidebarFileStorageDeal
import SidebarAddFileToBucket from "~/components/sidebars/SidebarAddFileToBucket"; import SidebarAddFileToBucket from "~/components/sidebars/SidebarAddFileToBucket";
import SidebarDragDropNotice from "~/components/sidebars/SidebarDragDropNotice"; import SidebarDragDropNotice from "~/components/sidebars/SidebarDragDropNotice";
import SidebarSingleSlateSettings from "~/components/sidebars/SidebarSingleSlateSettings"; import SidebarSingleSlateSettings from "~/components/sidebars/SidebarSingleSlateSettings";
import SidebarFilecoinArchive from "~/components/sidebars/SidebarFilecoinArchive";
// NOTE(jim): // NOTE(jim):
// Core components to the application structure. // Core components to the application structure.
@ -45,6 +46,7 @@ import Cookies from "universal-cookie";
const cookies = new Cookies(); const cookies = new Cookies();
const SIDEBARS = { const SIDEBARS = {
SIDEBAR_FILECOIN_ARCHIVE: <SidebarFilecoinArchive />,
SIDEBAR_FILE_STORAGE_DEAL: <SidebarFileStorageDeal />, SIDEBAR_FILE_STORAGE_DEAL: <SidebarFileStorageDeal />,
SIDEBAR_WALLET_SEND_FUNDS: <SidebarWalletSendFunds />, SIDEBAR_WALLET_SEND_FUNDS: <SidebarWalletSendFunds />,
SIDEBAR_CREATE_WALLET_ADDRESS: <SidebarCreateWalletAddress />, SIDEBAR_CREATE_WALLET_ADDRESS: <SidebarCreateWalletAddress />,

View File

@ -0,0 +1,61 @@
import * as React from "react";
import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
import * as Actions from "~/common/actions";
import * as SVG from "~/components/system/svg";
import * as System from "~/components/system";
import { css } from "@emotion/react";
export default class SidebarFilecoinArchive extends React.Component {
async componentDidMount() {}
_handleMakeDeal = async () => {
const response = await Actions.archive();
console.log(response);
alert("TODO: Still working on archiving issues.");
};
_handleSubmit = async (e) => {
if (e) {
e.persist();
}
this.props.onSidebarLoading(true);
await this._handleMakeDeal();
await this.props.onSubmit({});
};
_handleCancel = () => {
this.props.onCancel();
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
console.log(this.props);
return (
<React.Fragment>
<System.P style={{ fontFamily: Constants.font.semiBold }}>
Make Filecoin storage deal
</System.P>
<System.P style={{ marginTop: 24 }}>
This will archive all of your data onto the Filecoin Network.
</System.P>
<System.ButtonPrimary
full
style={{ marginTop: 48 }}
onClick={this._handleSubmit}
loading={this.props.sidebarLoading}
>
Make storage deal
</System.ButtonPrimary>
</React.Fragment>
);
}
}

View File

@ -91,7 +91,12 @@ export const getBucketAPIFromUserToken = async (token) => {
await buckets.getToken(identity); await buckets.getToken(identity);
const target = await buckets.getOrInit(BUCKET_NAME); const target = await buckets.getOrInit(BUCKET_NAME);
return { buckets, bucketKey: target.root.key, bucketName: BUCKET_NAME }; return {
buckets,
bucketKey: target.root.key,
bucketRoot: target,
bucketName: BUCKET_NAME,
};
}; };
// NOTE(jim): Requires Powergate, does not require token. // NOTE(jim): Requires Powergate, does not require token.

60
pages/api/data/archive.js Normal file
View File

@ -0,0 +1,60 @@
import * as MW from "~/node_common/middleware";
import * as Constants from "~/node_common/constants";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Strings from "~/node_common/utilities";
import * as Powergate from "~/node_common/powergate";
import * as LibraryManager from "~/node_common/managers/library";
const initCORS = MW.init(MW.CORS);
const initAuth = MW.init(MW.RequireCookieAuthentication);
export default async (req, res) => {
initCORS(req, res);
initAuth(req, res);
const id = Utilities.getIdFromCookie(req);
if (!id) {
return res
.status(403)
.json({ decorator: "SERVER_REMOVE_DATA_NOT_ALLOWED", error: true });
}
const user = await Data.getUserById({
id,
});
if (!user) {
return res.status(404).json({
decorator: "SERVER_BUCKET_ARCHIVE_DEAL_USER_NOT_FOUND",
error: true,
});
}
if (user.error) {
return res.status(500).json({
decorator: "SERVER_BUCKET_ARCHIVE_DEAL_USER_NOT_FOUND",
error: true,
});
}
const {
buckets,
bucketKey,
bucketName,
bucketRoot,
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api);
console.log(bucketRoot.root);
// bucketRoot.root.key
// bucketRoot.root.path
const response = await buckets.archive(bucketRoot.root.key);
console.log(response);
return res.status(200).send({
decorator: "SERVER_BUCKET_ARCHIVE_DEAL",
data: {},
});
};

View File

@ -80,6 +80,11 @@ export default class SceneFilesFolder extends React.Component {
type: "SIDEBAR", type: "SIDEBAR",
value: "SIDEBAR_ADD_FILE_TO_BUCKET", value: "SIDEBAR_ADD_FILE_TO_BUCKET",
}, },
{
name: "Filecoin archive",
type: "SIDEBAR",
value: "SIDEBAR_FILECOIN_ARCHIVE",
},
]} ]}
viewer={this.props.viewer} viewer={this.props.viewer}
items={this.props.viewer.library[0].children} items={this.props.viewer.library[0].children}