mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-28 05:52:49 +03:00
Merge pull request #329 from filecoin-project/@jimmylee/encrypted-bucket
encrypted buckets: encrypted buckets in production
This commit is contained in:
commit
8556cb7d09
@ -1,8 +1,6 @@
|
||||
import { dispatchCustomEvent } from "~/common/custom-events";
|
||||
|
||||
export const upload = async ({ file, context, bucketName }) => {
|
||||
console.log({ bucketName });
|
||||
|
||||
let formData = new FormData();
|
||||
const HEIC2ANY = require("heic2any");
|
||||
|
||||
@ -71,7 +69,8 @@ export const upload = async ({ file, context, bucketName }) => {
|
||||
});
|
||||
|
||||
let json;
|
||||
if (bucketName && bucketName === "deal") {
|
||||
// TODO(jim): Make this smarter.
|
||||
if (bucketName && bucketName === "encrypted-deal") {
|
||||
json = await _privateUploadMethod(`/api/data/deal/${file.name}`);
|
||||
} else {
|
||||
json = await _privateUploadMethod(`/api/data/${file.name}`);
|
||||
|
@ -150,8 +150,8 @@ export const getTextileById = async ({ id }) => {
|
||||
|
||||
const stagingData = await Utilities.getBucketAPIFromUserToken({
|
||||
user,
|
||||
bucketName: "deal",
|
||||
encrypted: false,
|
||||
bucketName: "encrypted-deal",
|
||||
encrypted: true,
|
||||
});
|
||||
|
||||
try {
|
||||
@ -189,16 +189,35 @@ export const getTextileById = async ({ id }) => {
|
||||
}
|
||||
|
||||
let items = null;
|
||||
const dealBucket = r.find((bucket) => bucket.name === "deal");
|
||||
// TODO(jim): There is no indicator on dealBucket that it is encrypted?
|
||||
const dealBucket = r.find((bucket) => bucket.name === "encrypted-deal");
|
||||
|
||||
/*
|
||||
TODO(sander): Would be nice if this existed in the response.
|
||||
{
|
||||
key: ...
|
||||
name: ...,
|
||||
path: ...,
|
||||
createdAt: ...,
|
||||
updatedAt: ...,
|
||||
thread: ...,
|
||||
encrypted: true/false
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
items = await stagingData.buckets.listIpfsPath(dealBucket.path);
|
||||
// NOTE(jim): Doesn't get it for encrypted buckets.
|
||||
// items = await stagingData.buckets.listIpfsPath(dealBucket.path);
|
||||
|
||||
const path = await stagingData.buckets.listPath(dealBucket.key, "/");
|
||||
items = path.item.items;
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/node_common/managers/viewer.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.listIpfsPath`,
|
||||
functionName: `buckets.listPath`,
|
||||
});
|
||||
}
|
||||
|
||||
@ -215,7 +234,7 @@ export const getTextileById = async ({ id }) => {
|
||||
errors,
|
||||
jobs,
|
||||
},
|
||||
deal: items ? items.items.filter((f) => f.name !== ".textileseed") : [],
|
||||
deal: items ? items.filter((f) => f.name !== ".textileseed") : [],
|
||||
dealJobs,
|
||||
};
|
||||
};
|
||||
|
@ -46,17 +46,36 @@ export default async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(sander+jim):
|
||||
// See line: 196 on https://github.com/filecoin-project/slate/blob/main/node_common/managers/viewer.js
|
||||
// Would be nice to be nice to get `entity.encrypted` on the bucket property.
|
||||
let items = null;
|
||||
try {
|
||||
items = await buckets.listIpfsPath(bucketRoot.path);
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/pages/api/data/archive.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.archive`,
|
||||
});
|
||||
if (bucketName === "encrypted-deal") {
|
||||
console.log("[ encrypted ] archiving encrypted bucket");
|
||||
try {
|
||||
const path = await buckets.listPath(bucketRoot.key, "/");
|
||||
items = path.item;
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/node_common/managers/viewer.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.listPath`,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
items = await buckets.listIpfsPath(bucketRoot.path);
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/pages/api/data/archive.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.listIpfsPath`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!items) {
|
||||
|
@ -62,18 +62,36 @@ export default async (req, res) => {
|
||||
.send({ decorator: "SERVER_BUCKET_NOT_FOUND", error: true });
|
||||
}
|
||||
|
||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||
// TODO(sander+jim):
|
||||
// See line: 196 on https://github.com/filecoin-project/slate/blob/main/node_common/managers/viewer.js
|
||||
// Would be nice to be nice to get `entity.encrypted` on the bucket property.
|
||||
let items = null;
|
||||
try {
|
||||
items = await buckets.listIpfsPath(targetBucket.path);
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/pages/api/data/bucket-remove.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.listIpfsPath`,
|
||||
});
|
||||
if (targetBucket.name === "encrypted-deal") {
|
||||
console.log("[ encrypted ] removing from encrypted bucket");
|
||||
try {
|
||||
const path = await buckets.listPath(targetBucket.key, "/");
|
||||
items = path.item;
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/pages/api/data/bucket-remove.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.listPath`,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
items = await buckets.listIpfsPath(targetBucket.path);
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
file: "/pages/api/data/bucket-remove.js",
|
||||
user,
|
||||
message: e.message,
|
||||
code: e.code,
|
||||
functionName: `buckets.listIpfsPath`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!items) {
|
||||
|
@ -25,7 +25,7 @@ export default async (req, res) => {
|
||||
|
||||
const response = await Upload.formMultipart(req, res, {
|
||||
user,
|
||||
bucketName: "deal",
|
||||
bucketName: "encrypted-deal",
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
|
@ -100,7 +100,7 @@ export default class SceneMakeFilecoinDeal extends React.Component {
|
||||
const file = e.target.files[i];
|
||||
|
||||
const response = await FileUtilities.upload({
|
||||
bucketName: "deal",
|
||||
bucketName: "encrypted-deal",
|
||||
file,
|
||||
});
|
||||
}
|
||||
@ -120,7 +120,7 @@ export default class SceneMakeFilecoinDeal extends React.Component {
|
||||
|
||||
_handleArchive = async (e) => {
|
||||
this.setState({ archiving: true });
|
||||
const response = await Actions.archive({ bucketName: "deal" });
|
||||
const response = await Actions.archive({ bucketName: "encrypted-deal" });
|
||||
|
||||
if (!response) {
|
||||
this.setState({ archiving: false });
|
||||
@ -169,7 +169,7 @@ export default class SceneMakeFilecoinDeal extends React.Component {
|
||||
_handleRemove = async (cid) => {
|
||||
this.setState({ loading: true });
|
||||
|
||||
await Actions.removeFromBucket({ bucketName: "deal", cid });
|
||||
await Actions.removeFromBucket({ bucketName: "encrypted-deal", cid });
|
||||
|
||||
let networkViewer;
|
||||
try {
|
||||
@ -239,7 +239,8 @@ export default class SceneMakeFilecoinDeal extends React.Component {
|
||||
|
||||
<ScenePageHeader title="Make an one-off Filecoin Storage Deal">
|
||||
This is a simple tool to upload data and make one-off storage deals in
|
||||
the Filecoin network.
|
||||
the Filecoin network. This deal is encrypted and you will need a key
|
||||
to view the contents.
|
||||
</ScenePageHeader>
|
||||
|
||||
{this.state.networkViewer ? (
|
||||
|
Loading…
Reference in New Issue
Block a user