Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/spicy-garlics-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tus/server": major
"@tus/utils": minor
---

- `POST_RECEIVE_V2` has been renamed to `POST_RECEIVE`. The deprecated version of `POST_RECEIVE` has been removed.
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Sends the client's origin back in `Access-Control-Allow-Origin` if it matches.
#### `options.postReceiveInterval`

Interval in milliseconds for sending progress of an upload over
[`POST_RECEIVE_V2`](#eventspost_receive_v2) (`number`).
[`POST_RECEIVE`](#eventspost_receive) (`number`).

#### `options.relativeLocation`

Expand Down Expand Up @@ -255,21 +255,6 @@ server.on(EVENTS.POST_CREATE, (req, res, upload => {})

#### `POST_RECEIVE`

**Deprecated**.

Called every time an upload finished writing to the store. This event is emitted whenever
the request handling is completed (which is the same as `onUploadFinish`, almost the same
as `POST_FINISH`), whereas the `POST_RECEIVE_V2` event is emitted _while_ the request is
being handled.

```js
const {EVENTS} = require('@tus/server')
// ...
server.on(EVENTS.POST_RECEIVE, (req, res, upload => {})
```

#### `POST_RECEIVE_V2`

Called every [`postReceiveInterval`](#optionspostreceiveinterval) milliseconds for every
upload while it‘s being written to the store.

Expand All @@ -283,7 +268,7 @@ Use `POST_FINISH` if you need to know when an upload is done.
```js
const {EVENTS} = require('@tus/server')
// ...
server.on(EVENTS.POST_RECEIVE_V2, (req, upload => {})
server.on(EVENTS.POST_RECEIVE, (req, upload => {})
```

#### `POST_FINISH`
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/handlers/BaseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class BaseHandler extends EventEmitter {

const postReceive = throttle(
(offset: number) => {
this.emit(EVENTS.POST_RECEIVE_V2, data, {...upload, offset})
this.emit(EVENTS.POST_RECEIVE, data, {...upload, offset})
},
this.options.postReceiveInterval,
{leading: false}
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/handlers/PatchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class PatchHandler extends BaseHandler {
}

upload.offset = newOffset
this.emit(EVENTS.POST_RECEIVE, req, upload)

//Recommended response defaults
const responseData = {
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ type Handlers = {

interface TusEvents {
[EVENTS.POST_CREATE]: (req: Request, upload: Upload, url: string) => void
/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */
[EVENTS.POST_RECEIVE]: (req: Request, upload: Upload) => void
[EVENTS.POST_RECEIVE_V2]: (req: Request, upload: Upload) => void
[EVENTS.POST_FINISH]: (req: Request, res: Response, upload: Upload) => void
[EVENTS.POST_TERMINATE]: (req: Request, res: Response, id: string) => void
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type ServerOptions = {
allowedOrigins?: string[]

/**
* Interval in milliseconds for sending progress of an upload over `EVENTS.POST_RECEIVE_V2`
* Interval in milliseconds for sending progress of an upload over `EVENTS.POST_RECEIVE`
*/
postReceiveInterval?: number

Expand Down
15 changes: 1 addition & 14 deletions packages/server/test/PatchHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type http from 'node:http'
import sinon from 'sinon'

import {PatchHandler} from '../src/handlers/PatchHandler'
import {EVENTS, Upload, DataStore, type CancellationContext} from '@tus/utils'
import {Upload, DataStore, type CancellationContext} from '@tus/utils'
import {MemoryLocker} from '../src'
import streamP from 'node:stream/promises'
import stream, {PassThrough} from 'node:stream'
Expand Down Expand Up @@ -190,19 +190,6 @@ describe('PatchHandler', () => {
})
})

it('should emit POST_RECEIVE event', async () => {
req.headers.set('upload-offset', '0')
req.headers.set('content-type', 'application/offset+octet-stream')

store.getUpload.resolves(new Upload({id: '1234', offset: 0, size: 1024}))
store.write.resolves(10)
handler.on(EVENTS.POST_RECEIVE, sinon.spy())

await handler.send(req, context)

assert.equal(true, true) // The event emitter is not directly testable in this context
})

it('should throw max size exceeded error when upload-length is higher then the maxSize', async () => {
const handler = new PatchHandler(store, {
path,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/Server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ describe('Server', () => {
})
const size = 1024 * 1024
let received = 0
server.on(EVENTS.POST_RECEIVE_V2, () => {
server.on(EVENTS.POST_RECEIVE, () => {
received++
})

Expand Down
4 changes: 0 additions & 4 deletions packages/utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,12 @@ export const ERRORS = {
} as const

export const POST_CREATE = 'POST_CREATE' as const
/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */
export const POST_RECEIVE = 'POST_RECEIVE' as const
export const POST_RECEIVE_V2 = 'POST_RECEIVE_V2' as const
export const POST_FINISH = 'POST_FINISH' as const
export const POST_TERMINATE = 'POST_TERMINATE' as const
export const EVENTS = {
POST_CREATE,
/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */
POST_RECEIVE,
POST_RECEIVE_V2,
POST_FINISH,
POST_TERMINATE,
} as const
Expand Down