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,
|
||||
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api, user);
|
||||
|
||||
if (!buckets) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
power,
|
||||
powerInfo,
|
||||
|
@ -54,15 +54,20 @@ export const formMultipart = (req, res, { user }) =>
|
||||
const data = LibraryManager.createLocalDataIncomplete(target);
|
||||
|
||||
// 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;
|
||||
try {
|
||||
const {
|
||||
buckets,
|
||||
bucketKey,
|
||||
} = await Utilities.getBucketAPIFromUserToken(
|
||||
user.data.tokens.api,
|
||||
user
|
||||
);
|
||||
push = await buckets.pushPath(bucketKey, data.name, readStream);
|
||||
} catch (e) {
|
||||
await FS.unlinkSync(tempPath);
|
||||
@ -77,18 +82,23 @@ export const formMultipart = (req, res, { user }) =>
|
||||
// Delete temporary local file,
|
||||
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)
|
||||
// Get remote file size from bucket.
|
||||
// TODO(jim): Put this call into a file for all Textile related calls.
|
||||
let ipfs = push.path.path;
|
||||
try {
|
||||
const {
|
||||
buckets,
|
||||
bucketKey,
|
||||
} = await Utilities.getBucketAPIFromUserToken(
|
||||
user.data.tokens.api,
|
||||
user
|
||||
);
|
||||
const newUpload = await buckets.listIpfsPath(ipfs);
|
||||
data.size = newUpload.size;
|
||||
} catch (e) {
|
||||
|
@ -28,14 +28,24 @@ export const formMultipart = async (req, res, { user }) => {
|
||||
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;
|
||||
try {
|
||||
const token = user.data.tokens.api;
|
||||
const {
|
||||
buckets,
|
||||
bucketKey,
|
||||
} = await Utilities.getBucketAPIFromUserToken(token, user);
|
||||
console.log("[upload] pushing to textile");
|
||||
push = await buckets.pushPath(bucketKey, data.id, stream);
|
||||
console.log("[upload] finished pushing to textile");
|
||||
} catch (e) {
|
||||
Social.sendTextileSlackMessage({
|
||||
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.
|
||||
const token = user.data.tokens.api;
|
||||
const { buckets } = await Utilities.getBucketAPIFromUserToken(token, user);
|
||||
|
||||
if (!buckets) {
|
||||
return {
|
||||
decorator: "SERVER_BUCKET_INIT_FAILURE",
|
||||
error: true,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const token = user.data.tokens.api;
|
||||
const { buckets } = await Utilities.getBucketAPIFromUserToken(token, user);
|
||||
const newUpload = await buckets.listIpfsPath(response.data);
|
||||
data.size = newUpload.size;
|
||||
} 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.
|
||||
let target;
|
||||
console.log(`[buckets] getOrCreate`);
|
||||
try {
|
||||
target = await buckets.getOrCreate(BUCKET_NAME);
|
||||
} catch (e) {
|
||||
@ -141,8 +142,9 @@ export const getBucketAPIFromUserToken = async (token, user) => {
|
||||
functionName: `buckets.getOrCreate`,
|
||||
});
|
||||
|
||||
return null;
|
||||
return { buckets: null, bucketKey: null, bucketRoot: null };
|
||||
}
|
||||
console.log(`[buckets] getOrCreate succes!`);
|
||||
|
||||
return {
|
||||
buckets,
|
||||
|
@ -35,6 +35,13 @@ export default async (req, res) => {
|
||||
bucketRoot,
|
||||
} = 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.path
|
||||
|
||||
|
@ -26,6 +26,12 @@ export default async (req, res) => {
|
||||
bucketName,
|
||||
} = 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.
|
||||
let r = null;
|
||||
try {
|
||||
|
@ -54,6 +54,13 @@ export default async (req, res) => {
|
||||
bucketName,
|
||||
} = 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.
|
||||
let r = null;
|
||||
try {
|
||||
|
@ -51,6 +51,13 @@ export default async (req, res) => {
|
||||
bucketName,
|
||||
} = 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.
|
||||
let r = null;
|
||||
try {
|
||||
|
@ -54,6 +54,12 @@ export default async (req, res) => {
|
||||
username: newUsername,
|
||||
});
|
||||
|
||||
if (!buckets) {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ decorator: "SERVER_BUCKET_INIT_FAILURE", error: true });
|
||||
}
|
||||
|
||||
const user = await Data.createUser({
|
||||
password: hash,
|
||||
salt,
|
||||
|
Loading…
Reference in New Issue
Block a user