@tussle/core
Advanced tools
Comparing version 0.7.0 to 0.7.5
@@ -93,5 +93,7 @@ "use strict"; | ||
var _a; | ||
const version = ctx.request.getHeader('tus-resumable'); | ||
ctx.response = { | ||
status: 412, | ||
headers: Object.assign({}, (_a = ctx.response) === null || _a === void 0 ? void 0 : _a.headers), | ||
body: `Unsupported protocol version (received: "${version}")`, | ||
}; | ||
@@ -98,0 +100,0 @@ return ctx; |
@@ -1,11 +0,13 @@ | ||
import handlePost from './post'; | ||
import handlePatch from './patch'; | ||
import handleDelete from './delete'; | ||
import handleHead from './head'; | ||
import handleOptions from './options'; | ||
import handlePatch from './patch'; | ||
import handlePost from './post'; | ||
export declare const defaultHandlers: { | ||
POST: typeof handlePost; | ||
PATCH: typeof handlePatch; | ||
DELETE: typeof handleDelete; | ||
HEAD: typeof handleHead; | ||
OPTIONS: typeof handleOptions; | ||
PATCH: typeof handlePatch; | ||
POST: typeof handlePost; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,12 +7,14 @@ "use strict"; | ||
exports.defaultHandlers = void 0; | ||
const post_1 = __importDefault(require("./post")); | ||
const patch_1 = __importDefault(require("./patch")); | ||
const delete_1 = __importDefault(require("./delete")); | ||
const head_1 = __importDefault(require("./head")); | ||
const options_1 = __importDefault(require("./options")); | ||
const patch_1 = __importDefault(require("./patch")); | ||
const post_1 = __importDefault(require("./post")); | ||
exports.defaultHandlers = { | ||
'POST': post_1.default, | ||
'PATCH': patch_1.default, | ||
'DELETE': delete_1.default, | ||
'HEAD': head_1.default, | ||
'OPTIONS': options_1.default, | ||
'PATCH': patch_1.default, | ||
'POST': post_1.default, | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -6,4 +6,5 @@ "use strict"; | ||
const operators_1 = require("rxjs/operators"); | ||
const error_1 = require("@tussle/spec/lib/error"); | ||
function handlePatch(ctx) { | ||
return processUploadBodyAndCallHooks(ctx).pipe((0, operators_1.map)(({ ctx, patchedFile }) => { | ||
return processUploadBodyAndCallHooks(ctx).pipe(handleStorageErrors(ctx), (0, operators_1.map)(({ ctx, patchedFile }) => { | ||
if (!patchedFile) { | ||
@@ -16,2 +17,11 @@ return ctx; | ||
exports.default = handlePatch; | ||
function handleStorageErrors(ctx) { | ||
return (0, operators_1.catchError)((err) => { | ||
if ((0, error_1.isStorageError)(err)) { | ||
ctx.response = err.toResponse(); | ||
return (0, rxjs_1.of)({ ctx, patchedFile: null }); | ||
} | ||
throw err; | ||
}); | ||
} | ||
function processUploadBodyAndCallHooks(ctx) { | ||
@@ -21,4 +31,7 @@ const store = ctx.cfg.storage; | ||
if (!store) { | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service sleected')); | ||
return (0, rxjs_1.throwError)(() => new Error('no storage service selected')); | ||
} | ||
if (isNaN(params.length)) { | ||
return (0, rxjs_1.throwError)(() => new Error('request did not include Content-Length')); | ||
} | ||
// Upload requests MUST use Content-Type: application/offset+octet-stream | ||
@@ -32,3 +45,3 @@ if (params.contentType !== 'application/offset+octet-stream') { | ||
} | ||
return (0, rxjs_1.of)(params).pipe((0, operators_1.switchMap)(params => store.patchFile(params)), (0, operators_1.switchMap)((patchedFile) => callOptionalHooks(ctx, patchedFile)), (0, operators_1.switchMap)((patchedFile) => ctx.source.hook('after-patch', ctx, patchedFile)), (0, operators_1.map)((patchedFile) => ({ ctx, patchedFile }))); | ||
return (0, rxjs_1.of)(params).pipe((0, operators_1.switchMap)(params => ctx.source.hook('before-patch', ctx, params)), (0, operators_1.switchMap)(params => store.patchFile(params)), (0, operators_1.switchMap)((patchedFile) => callOptionalHooks(ctx, patchedFile)), (0, operators_1.switchMap)((patchedFile) => ctx.source.hook('after-patch', ctx, patchedFile)), (0, operators_1.map)((patchedFile) => ({ ctx, patchedFile }))); | ||
} | ||
@@ -66,2 +79,5 @@ exports.processUploadBodyAndCallHooks = processUploadBodyAndCallHooks; | ||
var _a; | ||
if (patchedFile === null) { | ||
return ctx; | ||
} | ||
if (patchedFile.success && patchedFile.offset !== undefined && !('error' in patchedFile)) { | ||
@@ -73,3 +89,3 @@ ctx.response = { | ||
} | ||
else { | ||
else if (ctx.response === null) { | ||
ctx.response = { | ||
@@ -76,0 +92,0 @@ status: 403, |
{ | ||
"name": "@tussle/core", | ||
"version": "0.7.0", | ||
"version": "0.7.5", | ||
"description": "Tussle tus daemon core module", | ||
@@ -23,3 +23,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@tussle/spec": "^0.7.0", | ||
"@tussle/spec": "^0.7.5", | ||
"jest": "^29.2.2", | ||
@@ -37,3 +37,3 @@ "npm-run-all": "^4.1.5", | ||
}, | ||
"gitHead": "5a1db14dc48c3082895197bd1e711339c0839e7f" | ||
"gitHead": "7e84c6331df32103b9544374a7b62029060d38f1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
57887
42
691