diff --git a/.changeset/config.json b/.changeset/config.json index e0322447..7886c74f 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -7,5 +7,5 @@ "access": "public", "baseBranch": "main", "updateInternalDependencies": "patch", - "ignore": ["demo", "test"] + "ignore": ["test"] } diff --git a/README.md b/README.md index 9401e18a..d181d493 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ easily be added to tus-node-server - [Quick start](#quick-start) - [Packages](#packages) - [Extensions](#extensions) -- [Demos](#demos) - [Types](#types) - [Compatibility](#compatibility) - [Contribute](#contribute) @@ -49,6 +48,9 @@ integrate it into your existing one. There are also other mature servers, like A standalone server which stores files on disk. +> [!TIP] +> Try it yourself in [StackBlitz](https://stackblitz.com/edit/stackblitz-starters-zg6mgnuf?file=index.js) + ```js const {Server} = require('@tus/server') const {FileStore} = require('@tus/file-store') @@ -116,31 +118,6 @@ extensions. | [Termination][] | ✅ | ✅ | ❌ | ❌ | | [Concatenation][] | ❌ | ❌ | ❌ | ❌ | -## Demos - -Start the demo server using Local File Storage - -```bash -npm run build && npm run demo -``` - -Start up the demo server using AWS S3. The environment variables `AWS_BUCKET`, -`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_REGION` need to be present. - -```bash -npm run build && npm run demo:s3 -``` - -Start up the demo server using Google Cloud Storage. A `keyfile.json` needs to be present -in the root of the repository. - -```bash -npm run build && npm run demo:gcs -``` - -Then navigate to the demo ([localhost:1080](http://localhost:1080)) which uses -[`tus-js-client`](https://github.com/tus/tus-js-client). - ## Types All packages are fully typed with TypeScript. diff --git a/biome.json b/biome.json index e37f1fb2..d78b0720 100644 --- a/biome.json +++ b/biome.json @@ -4,7 +4,7 @@ "enabled": true }, "files": { - "ignore": ["./demo", "./**/dist/**/*"] + "ignore": ["./**/dist/**/*"] }, "linter": { "enabled": true, diff --git a/demo/package.json b/demo/package.json deleted file mode 100644 index 101e71b1..00000000 --- a/demo/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/package.json", - "name": "demo", - "private": true, - "scripts": { - "start": "node server.js", - "start:gcs": "cross-env DATA_STORE=GCSDataStore node server.js", - "start:s3": "cross-env DATA_STORE=S3Store node server.js", - "start:azure": "cross-env DATA_STORE=AzureBlobStore node server.js" - }, - "dependencies": { - "@tus/file-store": "^1.5.1", - "@tus/gcs-store": "^1.4.1", - "@tus/s3-store": "^1.7.0", - "@tus/azure-store": "^0.1.2", - "@tus/server": "^1.10.1", - "tus-js-client": "^2.3.2" - }, - "devDependencies": { - "cross-env": "^7.0.3" - } -} diff --git a/demo/server.js b/demo/server.js deleted file mode 100644 index cb2387ef..00000000 --- a/demo/server.js +++ /dev/null @@ -1,139 +0,0 @@ -const path = require('path') -const fs = require('fs') -const assert = require('assert') - -const { Server, EVENTS } = require('@tus/server') -const { GCSDataStore } = require('@tus/gcs-store') -const { S3Store } = require('@tus/s3-store') -const { FileStore } = require('@tus/file-store') -const { AzureStore } = require('@tus/azure-store') - -const stores = { - GCSDataStore: () => - new GCSDataStore({ - projectId: 'vimeo-open-source', - keyFilename: path.resolve(__dirname, '../keyfile.json'), - bucket: 'tus-node-server', - }), - S3Store: () => { - assert.ok( - process.env.AWS_ACCESS_KEY_ID, - 'environment variable `AWS_ACCESS_KEY_ID` must be set' - ) - assert.ok( - process.env.AWS_SECRET_ACCESS_KEY, - 'environment variable `AWS_SECRET_ACCESS_KEY` must be set' - ) - assert.ok(process.env.AWS_BUCKET, 'environment variable `AWS_BUCKET` must be set') - assert.ok(process.env.AWS_REGION, 'environment variable `AWS_REGION` must be set') - - return new S3Store({ - partSize: 8 * 1024 * 1024, // each uploaded part will have ~8MiB, - s3ClientConfig: { - bucket: process.env.AWS_BUCKET, - accessKeyId: process.env.AWS_ACCESS_KEY_ID, - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, - region: process.env.AWS_REGION, - }, - }) - }, - FileStore: () => new FileStore({ directory: './files' }), - - AzureBlobStore: () => { - assert.ok( - process.env.AZURE_ACCOUNT_ID, - 'environment variable `AZURE_ACCOUNT_ID` must be set' - ) - - assert.ok( - process.env.AZURE_ACCOUNT_KEY, - 'environment variable `AZURE_ACCOUNT_KEY` must be set' - ) - - assert.ok( - process.env.AZURE_CONTAINER_NAME, - 'environment variable `AZURE_CONTAINER_NAME` must be set' - ) - - return new AzureStore({ - account: process.env.AZURE_ACCOUNT_ID, - accountKey: process.env.AZURE_ACCOUNT_KEY, - containerName: process.env.AZURE_CONTAINER_NAME, - }) - } -} -const storeName = process.env.DATA_STORE || 'FileStore' -const store = stores[storeName] -const server = new Server({ path: '/files', datastore: store() }) - -/** - * Basic GET handler to serve the demo html/js - * - * @param {object} req http.incomingMessage - * @param {object} res http.ServerResponse - */ -const writeFile = (req, res) => { - // Determine file to serve - let filename = req.url - if (filename == '/') { - filename = '/index.html' - } - if (!filename.startsWith('/dist/')) { - filename = '/demos/browser' + filename - } - filename = path.join(process.cwd(), '../node_modules/tus-js-client', filename) - fs.readFile(filename, 'binary', (err, file) => { - if (err) { - res.writeHead(500, { 'Content-Type': 'text/plain' }) - console.log(err); - res.write(err) - res.end() - return - } - - // Update demo URL to point to our local server - file = file.replace( - 'https://tusd.tusdemo.net/files/', - `http://${host}:${port}/files/` - ) - - res.writeHead(200) - res.write(file) - res.end() - }) -} - -// Define routes to serve the demo html/js files. -server.get('/', writeFile) -server.get('/index.html', writeFile) -server.get('/demo.js', writeFile) -server.get('/demo.css', writeFile) -server.get('/video.html', writeFile) -server.get('/video.js', writeFile) -server.get('/dist/tus.js', writeFile) -server.get('/dist/tus.js.map', writeFile) -server.get('/dist/tus.min.js', writeFile) -server.get('/dist/tus.min.js.map', writeFile) - -server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => { - console.log( - `[${new Date().toLocaleTimeString()}] [EVENT HOOK] Upload complete for file ${event.file.id - }` - ) -}) - -// // this is the express stile ;) -// const express = require('express'); -// const app = express(); -// const uploadApp = express(); -// uploadApp.all('*', server.handle.bind(server)); -// app.use('/uploads', uploadApp); -// app.get('*', writeFile); - -const host = '127.0.0.1' -const port = 1080 -server.listen({ host, port }, () => { - console.log( - `[${new Date().toLocaleTimeString()}] tus server listening at http://${host}:${port} using ${storeName}` - ) -}) diff --git a/package-lock.json b/package-lock.json index f4896d1c..4c5a489c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ } }, "demo": { + "extraneous": true, "dependencies": { "@tus/azure-store": "^0.1.2", "@tus/file-store": "^1.5.1", @@ -3250,10 +3251,6 @@ "dev": true, "license": "BSD-3-Clause" }, - "node_modules/buffer-from": { - "version": "1.1.2", - "license": "MIT" - }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -3327,13 +3324,6 @@ "node": ">=0.10.0" } }, - "node_modules/combine-errors": { - "version": "3.0.3", - "dependencies": { - "custom-error-instance": "2.1.1", - "lodash.uniqby": "4.5.0" - } - }, "node_modules/combined-stream": { "version": "1.0.8", "dev": true, @@ -3387,23 +3377,6 @@ "dev": true, "license": "MIT" }, - "node_modules/cross-env": { - "version": "7.0.3", - "dev": true, - "license": "MIT", - "dependencies": { - "cross-spawn": "^7.0.1" - }, - "bin": { - "cross-env": "src/bin/cross-env.js", - "cross-env-shell": "src/bin/cross-env-shell.js" - }, - "engines": { - "node": ">=10.14", - "npm": ">=6", - "yarn": ">=1" - } - }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -3438,10 +3411,6 @@ "node": ">=8" } }, - "node_modules/custom-error-instance": { - "version": "2.1.1", - "license": "ISC" - }, "node_modules/dataloader": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/dataloader/-/dataloader-1.4.0.tgz", @@ -3490,10 +3459,6 @@ "node": ">=0.4.0" } }, - "node_modules/demo": { - "resolved": "demo", - "link": true - }, "node_modules/denque": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", @@ -4059,6 +4024,7 @@ }, "node_modules/graceful-fs": { "version": "4.2.11", + "dev": true, "license": "ISC" }, "node_modules/gtoken": { @@ -4305,6 +4271,7 @@ }, "node_modules/is-stream": { "version": "2.0.1", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -4367,10 +4334,6 @@ "@pkgjs/parseargs": "^0.11.0" } }, - "node_modules/js-base64": { - "version": "2.6.4", - "license": "BSD-3-Clause" - }, "node_modules/js-yaml": { "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", @@ -4440,40 +4403,6 @@ "node": ">=8" } }, - "node_modules/lodash._baseiteratee": { - "version": "4.7.0", - "license": "MIT", - "dependencies": { - "lodash._stringtopath": "~4.8.0" - } - }, - "node_modules/lodash._basetostring": { - "version": "4.12.0", - "license": "MIT" - }, - "node_modules/lodash._baseuniq": { - "version": "4.6.0", - "license": "MIT", - "dependencies": { - "lodash._createset": "~4.0.0", - "lodash._root": "~3.0.0" - } - }, - "node_modules/lodash._createset": { - "version": "4.0.3", - "license": "MIT" - }, - "node_modules/lodash._root": { - "version": "3.0.1", - "license": "MIT" - }, - "node_modules/lodash._stringtopath": { - "version": "4.8.0", - "license": "MIT", - "dependencies": { - "lodash._basetostring": "~4.12.0" - } - }, "node_modules/lodash.defaults": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", @@ -4503,14 +4432,6 @@ "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", "integrity": "sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==" }, - "node_modules/lodash.uniqby": { - "version": "4.5.0", - "license": "MIT", - "dependencies": { - "lodash._baseiteratee": "~4.7.0", - "lodash._baseuniq": "~4.6.0" - } - }, "node_modules/log-symbols": { "version": "4.1.0", "dev": true, @@ -5215,24 +5136,6 @@ "node": ">= 0.6.0" } }, - "node_modules/proper-lockfile": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.1.2", - "retry": "^0.10.0" - }, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/proper-lockfile/node_modules/retry": { - "version": "0.10.1", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/qs": { "version": "6.11.2", "dev": true, @@ -5247,10 +5150,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/querystringify": { - "version": "2.2.0", - "license": "MIT" - }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -5364,10 +5263,6 @@ "node": ">=0.10.0" } }, - "node_modules/requires-port": { - "version": "1.0.0", - "license": "MIT" - }, "node_modules/resolve-from": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", @@ -5974,19 +5869,6 @@ "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", "license": "0BSD" }, - "node_modules/tus-js-client": { - "version": "2.3.2", - "license": "MIT", - "dependencies": { - "buffer-from": "^1.1.2", - "combine-errors": "^3.0.3", - "is-stream": "^2.0.0", - "js-base64": "^2.6.1", - "lodash.throttle": "^4.1.1", - "proper-lockfile": "^2.0.1", - "url-parse": "^1.5.7" - } - }, "node_modules/type-detect": { "version": "4.0.8", "dev": true, @@ -6036,14 +5918,6 @@ "node": ">= 4.0.0" } }, - "node_modules/url-parse": { - "version": "1.5.10", - "license": "MIT", - "dependencies": { - "querystringify": "^2.1.1", - "requires-port": "^1.0.0" - } - }, "node_modules/util-deprecate": { "version": "1.0.2", "license": "MIT" diff --git a/package.json b/package.json index bcb75116..a940681c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,9 @@ { "$schema": "https://json.schemastore.org/package.json", "private": true, - "workspaces": ["packages/*", "demo", "test"], + "workspaces": ["packages/*", "test"], "scripts": { "build": "tsc --build", - "demo": "npm run --workspace demo start", - "demo:gcs": "npm run --workspace demo start:gcs", - "demo:s3": "npm run --workspace demo start:s3", - "demo:azure": "npm run --workspace demo start:azure", "lint": "biome lint --write .", "format": "biome format --write .", "format:check": "biome format --error-on-warnings .",