From 901c82f0c235dbc736658db8e75e941a7334b010 Mon Sep 17 00:00:00 2001 From: "@wwwjim" Date: Thu, 8 Oct 2020 17:40:26 -0700 Subject: [PATCH] textile/hub 1.1.1 and nextjs 9.5.4 --- node_common/upload.js | 16 +++++++++++++--- package.json | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/node_common/upload.js b/node_common/upload.js index 35062c7b..3ffbf397 100644 --- a/node_common/upload.js +++ b/node_common/upload.js @@ -2,12 +2,15 @@ import * as LibraryManager from "~/node_common/managers/library"; import * as Utilities from "~/node_common/utilities"; import * as Social from "~/node_common/social"; +import AbortController from "abort-controller"; import B from "busboy"; const HIGH_WATER_MARK = 1024 * 1024 * 3; export const formMultipart = async (req, res, { user, bucketName }) => { let data = null; + const controller = new AbortController(); + const { signal } = controller; const upload = () => new Promise(async (resolve, reject) => { @@ -32,12 +35,14 @@ export const formMultipart = async (req, res, { user, bucketName }) => { const { buckets, bucketKey, + bucketRoot, } = await Utilities.getBucketAPIFromUserToken({ user, bucketName, }); if (!buckets) { + controller.abort(); return reject({ decorator: "SERVER_BUCKET_INIT_FAILURE", error: true, @@ -47,15 +52,19 @@ export const formMultipart = async (req, res, { user, bucketName }) => { let push; try { console.log("[upload] pushing to textile"); - push = await buckets.pushPath(bucketKey, data.id, stream); + push = await buckets.pushPath(bucketKey, data.id, stream, { + root: bucketRoot, + signal, + }); console.log("[upload] finished pushing to textile"); } catch (e) { + controller.abort(); Social.sendTextileSlackMessage({ file: "/node_common/upload.js", user, message: e.message, code: e.code, - functionName: `buckets.pushPath`, + functionName: `buckets.pushPath (aborting)`, }); return reject({ @@ -77,9 +86,10 @@ export const formMultipart = async (req, res, { user, bucketName }) => { user, message: e.message, code: e.code, - functionName: `form`, + functionName: `form (aborting)`, }); + controller.abort(); return reject({ decorator: "SERVER_UPLOAD_ERROR", error: true, diff --git a/package.json b/package.json index fd2a49df..b1ff11c5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "@react-hook/window-size": "^3.0.7", "@slack/webhook": "^5.0.3", "@textile/grpc-transport": "0.0.3", - "@textile/hub": "^1.1.0", + "@textile/hub": "^1.1.1", + "abort-controller": "^3.0.0", "babel-plugin-module-resolver": "^4.0.0", "bcrypt": "^5.0.0", "body-parser": "^1.19.0", @@ -66,7 +67,7 @@ "minisearch": "^2.5.1", "moment": "^2.27.0", "morgan": "^1.10.0", - "next": "^9.5.2", + "next": "^9.5.4", "pg": "^8.3.3", "prismjs": "^1.20.0", "react": "^16.13.1",