mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-25 01:52:45 +03:00
buckets: elegant failure modes for bucket getOrCreate failures
This commit is contained in:
parent
50e62a40be
commit
7b10703821
@ -122,6 +122,10 @@ export const getTextileById = async ({ id }) => {
|
|||||||
bucketRoot,
|
bucketRoot,
|
||||||
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
power,
|
power,
|
||||||
powerInfo,
|
powerInfo,
|
||||||
|
@ -54,15 +54,20 @@ export const formMultipart = (req, res, { user }) =>
|
|||||||
const data = LibraryManager.createLocalDataIncomplete(target);
|
const data = LibraryManager.createLocalDataIncomplete(target);
|
||||||
|
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
|
let { buckets, bucketKey } = await Utilities.getBucketAPIFromUserToken(
|
||||||
|
user.data.tokens.api,
|
||||||
|
user
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return reject({
|
||||||
|
decorator: "SERVER_BUCKETS_INIT_ISSUE",
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let push;
|
let push;
|
||||||
try {
|
try {
|
||||||
const {
|
|
||||||
buckets,
|
|
||||||
bucketKey,
|
|
||||||
} = await Utilities.getBucketAPIFromUserToken(
|
|
||||||
user.data.tokens.api,
|
|
||||||
user
|
|
||||||
);
|
|
||||||
push = await buckets.pushPath(bucketKey, data.name, readStream);
|
push = await buckets.pushPath(bucketKey, data.name, readStream);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await FS.unlinkSync(tempPath);
|
await FS.unlinkSync(tempPath);
|
||||||
@ -77,18 +82,23 @@ export const formMultipart = (req, res, { user }) =>
|
|||||||
// Delete temporary local file,
|
// Delete temporary local file,
|
||||||
await FS.unlinkSync(tempPath);
|
await FS.unlinkSync(tempPath);
|
||||||
|
|
||||||
|
let { buckets, bucketKey } = await Utilities.getBucketAPIFromUserToken(
|
||||||
|
user.data.tokens.api,
|
||||||
|
user
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return reject({
|
||||||
|
decorator: "SERVER_BUCKETS_INIT_ISSUE",
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE(jim)
|
// NOTE(jim)
|
||||||
// Get remote file size from bucket.
|
// Get remote file size from bucket.
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
let ipfs = push.path.path;
|
let ipfs = push.path.path;
|
||||||
try {
|
try {
|
||||||
const {
|
|
||||||
buckets,
|
|
||||||
bucketKey,
|
|
||||||
} = await Utilities.getBucketAPIFromUserToken(
|
|
||||||
user.data.tokens.api,
|
|
||||||
user
|
|
||||||
);
|
|
||||||
const newUpload = await buckets.listIpfsPath(ipfs);
|
const newUpload = await buckets.listIpfsPath(ipfs);
|
||||||
data.size = newUpload.size;
|
data.size = newUpload.size;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -28,14 +28,24 @@ export const formMultipart = async (req, res, { user }) => {
|
|||||||
type: mime,
|
type: mime,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const token = user.data.tokens.api;
|
||||||
|
const {
|
||||||
|
buckets,
|
||||||
|
bucketKey,
|
||||||
|
} = await Utilities.getBucketAPIFromUserToken(token, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return reject({
|
||||||
|
decorator: "SERVER_BUCKET_INIT_FAILURE",
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let push;
|
let push;
|
||||||
try {
|
try {
|
||||||
const token = user.data.tokens.api;
|
console.log("[upload] pushing to textile");
|
||||||
const {
|
|
||||||
buckets,
|
|
||||||
bucketKey,
|
|
||||||
} = await Utilities.getBucketAPIFromUserToken(token, user);
|
|
||||||
push = await buckets.pushPath(bucketKey, data.id, stream);
|
push = await buckets.pushPath(bucketKey, data.id, stream);
|
||||||
|
console.log("[upload] finished pushing to textile");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Social.sendTextileSlackMessage({
|
Social.sendTextileSlackMessage({
|
||||||
file: "/node_common/upload.js",
|
file: "/node_common/upload.js",
|
||||||
@ -84,9 +94,17 @@ export const formMultipart = async (req, res, { user }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
|
const token = user.data.tokens.api;
|
||||||
|
const { buckets } = await Utilities.getBucketAPIFromUserToken(token, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return {
|
||||||
|
decorator: "SERVER_BUCKET_INIT_FAILURE",
|
||||||
|
error: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = user.data.tokens.api;
|
|
||||||
const { buckets } = await Utilities.getBucketAPIFromUserToken(token, user);
|
|
||||||
const newUpload = await buckets.listIpfsPath(response.data);
|
const newUpload = await buckets.listIpfsPath(response.data);
|
||||||
data.size = newUpload.size;
|
data.size = newUpload.size;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -130,6 +130,7 @@ export const getBucketAPIFromUserToken = async (token, user) => {
|
|||||||
|
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
let target;
|
let target;
|
||||||
|
console.log(`[buckets] getOrCreate`);
|
||||||
try {
|
try {
|
||||||
target = await buckets.getOrCreate(BUCKET_NAME);
|
target = await buckets.getOrCreate(BUCKET_NAME);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -141,8 +142,9 @@ export const getBucketAPIFromUserToken = async (token, user) => {
|
|||||||
functionName: `buckets.getOrCreate`,
|
functionName: `buckets.getOrCreate`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
return { buckets: null, bucketKey: null, bucketRoot: null };
|
||||||
}
|
}
|
||||||
|
console.log(`[buckets] getOrCreate succes!`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buckets,
|
buckets,
|
||||||
|
@ -35,6 +35,13 @@ export default async (req, res) => {
|
|||||||
bucketRoot,
|
bucketRoot,
|
||||||
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return res.status(500).send({
|
||||||
|
decorator: "SERVER_BUCKET_INIT_FAILURE",
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// bucketRoot.root.key
|
// bucketRoot.root.key
|
||||||
// bucketRoot.root.path
|
// bucketRoot.root.path
|
||||||
|
|
||||||
|
@ -26,6 +26,12 @@ export default async (req, res) => {
|
|||||||
bucketName,
|
bucketName,
|
||||||
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return res
|
||||||
|
.status(500)
|
||||||
|
.send({ decorator: "SERVER_GET_BUCKET_INIT", error: true });
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
let r = null;
|
let r = null;
|
||||||
try {
|
try {
|
||||||
|
@ -54,6 +54,13 @@ export default async (req, res) => {
|
|||||||
bucketName,
|
bucketName,
|
||||||
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return res.status(500).send({
|
||||||
|
decorator: "SERVER_BUCKET_INIT_FAILURE",
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
let r = null;
|
let r = null;
|
||||||
try {
|
try {
|
||||||
|
@ -51,6 +51,13 @@ export default async (req, res) => {
|
|||||||
bucketName,
|
bucketName,
|
||||||
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return res.status(500).send({
|
||||||
|
decorator: "SERVER_BUCKET_INIT_FAILURE",
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||||
let r = null;
|
let r = null;
|
||||||
try {
|
try {
|
||||||
|
@ -54,6 +54,12 @@ export default async (req, res) => {
|
|||||||
username: newUsername,
|
username: newUsername,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!buckets) {
|
||||||
|
return res
|
||||||
|
.status(500)
|
||||||
|
.send({ decorator: "SERVER_BUCKET_INIT_FAILURE", error: true });
|
||||||
|
}
|
||||||
|
|
||||||
const user = await Data.createUser({
|
const user = await Data.createUser({
|
||||||
password: hash,
|
password: hash,
|
||||||
salt,
|
salt,
|
||||||
|
Loading…
Reference in New Issue
Block a user