Socket
Socket
Sign inDemoInstall

@tus/server

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tus/server - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

2

dist/handlers/PostHandler.d.ts
/// <reference types="node" />
import { BaseHandler } from './BaseHandler';
import { DataStore, CancellationContext } from '@tus/utils';
import type http from 'node:http';
import http from 'node:http';
import type { ServerOptions, WithRequired } from '../types';

@@ -6,0 +6,0 @@ export declare class PostHandler extends BaseHandler {

@@ -73,3 +73,16 @@ "use strict";

try {
res = await this.options.onUploadCreate(req, res, upload);
const resOrObject = await this.options.onUploadCreate(req, res, upload);
// Backwards compatibility, remove in next major
// Ugly check because we can't use `instanceof` because we mock the instance in tests
if (typeof resOrObject.write === 'function' &&
typeof resOrObject.writeHead === 'function') {
res = resOrObject;
}
else {
const obj = resOrObject;
res = obj.res;
if (obj.metadata) {
upload.metadata = obj.metadata;
}
}
}

@@ -76,0 +89,0 @@ catch (error) {

@@ -36,2 +36,5 @@ "use strict";

}
if (!options.lockDrainTimeout) {
options.lockDrainTimeout = 3000;
}
const { datastore, ...rest } = options;

@@ -193,3 +196,3 @@ this.options = rest;

requestAbortController.abort(err);
}, 3000);
}, this.options.lockDrainTimeout);
};

@@ -196,0 +199,0 @@ abortWithDelayController.signal.addEventListener('abort', onDelayedAbort);

@@ -59,2 +59,6 @@ /// <reference types="node" />

/**
* This timeout controls how long the server will wait a cancelled lock to do its cleanup.
*/
lockDrainTimeout?: number;
/**
* Disallow termination for finished uploads.

@@ -73,3 +77,6 @@ */

*/
onUploadCreate?: (req: http.IncomingMessage, res: http.ServerResponse, upload: Upload) => Promise<http.ServerResponse>;
onUploadCreate?: (req: http.IncomingMessage, res: http.ServerResponse, upload: Upload) => Promise<http.ServerResponse | {
res: http.ServerResponse;
metadata?: Upload['metadata'];
}>;
/**

@@ -76,0 +83,0 @@ * `onUploadFinish` will be invoked after an upload is completed but before a response is returned to the client.

{
"$schema": "https://json.schemastore.org/package.json",
"name": "@tus/server",
"version": "1.4.2",
"version": "1.5.0",
"description": "Tus resumable upload protocol in Node.js",

@@ -6,0 +6,0 @@ "main": "dist/index.js",

@@ -143,7 +143,8 @@ # `@tus/server`

`onUploadCreate` will be invoked before a new upload is created.
(`(req, res, upload) => Promise<res>`).
(`(req, res, upload) => Promise<{ res: http.ServerResponse, metadata?: Record<string, string>}>`).
If the function returns the (modified) response, the upload will be created. You can
`throw` an Object and the HTTP request will be aborted with the provided `body` and
`status_code` (or their fallbacks).
- If the function returns the (modified) response the upload will be created.
- You can optionally return `metadata` which will override (not merge!) `upload.metadata`.
- You can `throw` an Object and the HTTP request will be aborted with the provided `body`
and `status_code` (or their fallbacks).

@@ -449,3 +450,3 @@ This can be used to implement validation of upload metadata or add headers.

async onUploadCreate(req, res, upload) {
const {ok, expected, received} = validateMetadata(upload)
const {ok, expected, received} = validateMetadata(upload) // your logic
if (!ok) {

@@ -455,4 +456,6 @@ const body = `Expected "${expected}" in "Upload-Metadata" but received "${received}"`

}
// We have to return the (modified) response.
return res
// You can optionally return metadata to override the upload metadata,
// such as `{ storagePath: "/upload/123abc..." }`
const extraMeta = getExtraMetadata(req) // your logic
return {res, metadata: {...upload.metadata, ...extraMeta}}
},

@@ -459,0 +462,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc