Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tus/server

Package Overview
Dependencies
Maintainers
3
Versions
20
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.0.0-beta.6 to 1.0.0-beta.7

18

dist/handlers/PostHandler.js

@@ -76,3 +76,3 @@ "use strict";

let newOffset;
let isFinal = false;
let isFinal = upload.size === 0 && !upload.sizeIsDeferred;
const headers = {};

@@ -85,11 +85,11 @@ // The request MIGHT include a Content-Type header when using creation-with-upload extension

upload.offset = newOffset;
if (isFinal && this.options.onUploadFinish) {
try {
res = await this.options.onUploadFinish(req, res, upload);
}
catch (error) {
log(`onUploadFinish: ${error.body}`);
throw error;
}
}
if (isFinal && this.options.onUploadFinish) {
try {
res = await this.options.onUploadFinish(req, res, upload);
}
catch (error) {
log(`onUploadFinish: ${error.body}`);
throw error;
}
}

@@ -96,0 +96,0 @@ // The Upload-Expires response header indicates the time after which the unfinished upload expires.

export { Server } from './server';
export * from './types';
export * from './models/';
export * from './models';
export * from './constants';

@@ -21,3 +21,3 @@ "use strict";

__exportStar(require("./types"), exports);
__exportStar(require("./models/"), exports);
__exportStar(require("./models"), exports);
__exportStar(require("./constants"), exports);
export { DataStore } from './DataStore';
export { MemoryConfigstore } from './MemoryConfigstore';
export * as Metadata from './Metadata';

@@ -4,0 +3,0 @@ export { StreamSplitter } from './StreamSplitter';

@@ -26,7 +26,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Upload = exports.Uid = exports.StreamSplitter = exports.Metadata = exports.MemoryConfigstore = exports.DataStore = void 0;
exports.Upload = exports.Uid = exports.StreamSplitter = exports.Metadata = exports.DataStore = void 0;
var DataStore_1 = require("./DataStore");
Object.defineProperty(exports, "DataStore", { enumerable: true, get: function () { return DataStore_1.DataStore; } });
var MemoryConfigstore_1 = require("./MemoryConfigstore");
Object.defineProperty(exports, "MemoryConfigstore", { enumerable: true, get: function () { return MemoryConfigstore_1.MemoryConfigstore; } });
exports.Metadata = __importStar(require("./Metadata"));

@@ -33,0 +31,0 @@ var StreamSplitter_1 = require("./StreamSplitter");

{
"$schema": "https://json.schemastore.org/package.json",
"name": "@tus/server",
"version": "1.0.0-beta.6",
"version": "1.0.0-beta.7",
"description": "Tus resumable upload protocol in Node.js",

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

@@ -5,3 +5,3 @@ # `@tus/server`

> The old package, `tus-node-server`, is considered unstable and will only receive security fixes.
> Make sure to use the new package, currently in beta at `1.0.0-beta.5`.
> Make sure to use the new package, currently in beta at `1.0.0-beta.7`.

@@ -39,12 +39,12 @@ ## Contents

```js
const {Server} = require('@tus/server')
const {FileStore} = require('@tus/file-store')
const host = '127.0.0.1'
const port = 1080
const { Server } = require("@tus/server");
const { FileStore } = require("@tus/file-store");
const host = "127.0.0.1";
const port = 1080;
const server = new Server({
path: '/files',
datastore: new FileStore({directory: './files'}),
})
server.listen({host, port})
path: "/files",
datastore: new FileStore({ directory: "./files" }),
});
server.listen({ host, port });
```

@@ -182,17 +182,17 @@

```js
const {Server} = require('@tus/server')
const {FileStore} = require('@tus/file-store')
const express = require('express')
const { Server } = require("@tus/server");
const { FileStore } = require("@tus/file-store");
const express = require("express");
const host = '127.0.0.1'
const port = 1080
const app = express()
const uploadApp = express()
const host = "127.0.0.1";
const port = 1080;
const app = express();
const uploadApp = express();
const server = new Server({
datastore: new FileStore({directory: '/files'}),
})
datastore: new FileStore({ directory: "/files" }),
});
uploadApp.all('*', server.handle.bind(server))
app.use('/uploads', uploadApp)
app.listen(port, host)
uploadApp.all("*", server.handle.bind(server));
app.use("/uploads", uploadApp);
app.listen(port, host);
```

@@ -203,28 +203,28 @@

```js
const http = require('node:http')
const url = require('node:url')
const Koa = require('koa')
const {Server} = require('@tus/server')
const {FileStore} = require('@tus/file-store')
const http = require("node:http");
const url = require("node:url");
const Koa = require("koa");
const { Server } = require("@tus/server");
const { FileStore } = require("@tus/file-store");
const app = new Koa()
const appCallback = app.callback()
const port = 1080
const app = new Koa();
const appCallback = app.callback();
const port = 1080;
const tusServer = new Server({
path: '/files',
datastore: new FileStore({directory: '/files'}),
})
path: "/files",
datastore: new FileStore({ directory: "/files" }),
});
const server = http.createServer((req, res) => {
const urlPath = url.parse(req.url).pathname
const urlPath = url.parse(req.url).pathname;
// handle any requests with the `/files/*` pattern
if (/^\/files\/.+/.test(urlPath.toLowerCase())) {
return tusServer.handle(req, res)
return tusServer.handle(req, res);
}
appCallback(req, res)
})
appCallback(req, res);
});
server.listen(port)
server.listen(port);
```

@@ -235,10 +235,10 @@

```js
const fastify = require('fastify')({ logger: true })
const {Server} = require('@tus/server')
const {FileStore} = require('@tus/file-store')
const fastify = require("fastify")({ logger: true });
const { Server } = require("@tus/server");
const { FileStore } = require("@tus/file-store");
const tusServer = new Server({
path: '/files',
datastore: new FileStore({ directory: './files' }),
})
path: "/files",
datastore: new FileStore({ directory: "./files" }),
});

@@ -251,4 +251,5 @@ /**

fastify.addContentTypeParser(
'application/offset+octet-stream', (request, payload, done) => done(null)
)
"application/offset+octet-stream",
(request, payload, done) => done(null)
);

@@ -261,14 +262,14 @@ /**

*/
fastify.all('/files', (req, res) => {
tusServer.handle(req.raw, res.raw)
})
fastify.all('/files/*', (req, res) => {
tusServer.handle(req.raw, res.raw)
})
fastify.all("/files", (req, res) => {
tusServer.handle(req.raw, res.raw);
});
fastify.all("/files/*", (req, res) => {
tusServer.handle(req.raw, res.raw);
});
fastify.listen(3000, (err) => {
if (err) {
fastify.log.error(err)
process.exit(1)
fastify.log.error(err);
process.exit(1);
}
})
});
```

@@ -283,5 +284,5 @@

```ts
import type {NextApiRequest, NextApiResponse} from 'next'
import {Server, Upload} from '@tus/server'
import {FileStore} from '@tus/file-store'
import type { NextApiRequest, NextApiResponse } from "next";
import { Server, Upload } from "@tus/server";
import { FileStore } from "@tus/file-store";

@@ -296,3 +297,3 @@ /**

},
}
};

@@ -302,8 +303,8 @@ const tusServer = new Server({

// ie /api/upload
path: '/api/upload',
datastore: new FileStore({directory: './files'}),
})
path: "/api/upload",
datastore: new FileStore({ directory: "./files" }),
});
export default function handler(req: NextApiRequest, res: NextApiResponse) {
return tusServer.handle(req, res)
return tusServer.handle(req, res);
}

@@ -315,3 +316,3 @@ ```

```js
const {Server} = require('@tus/server')
const { Server } = require("@tus/server");
// ...

@@ -322,13 +323,13 @@

async onUploadCreate(req, res, upload) {
const {ok, expected, received} = validateMetadata(upload)
const { ok, expected, received } = validateMetadata(upload);
if (!ok) {
const body = `Expected "${expected}" in "Upload-Metadata" but received "${received}"`
throw {status_code: 500, body} // if undefined, falls back to 500 with "Internal server error".
const body = `Expected "${expected}" in "Upload-Metadata" but received "${received}"`;
throw { status_code: 500, body }; // if undefined, falls back to 500 with "Internal server error".
}
// We have to return the (modified) response.
return res
return res;
},
})
});
server.listen({host, port})
server.listen({ host, port });
```

@@ -335,0 +336,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