-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deps upgrade, custom tus options (#440)
- Loading branch information
Showing
14 changed files
with
1,802 additions
and
3,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { CancellationContext, ERRORS, Server } from '@tus/server' | ||
import http from 'node:http' | ||
|
||
export class TusServer extends Server { | ||
protected createContext(req: http.IncomingMessage) { | ||
// Initialize two AbortControllers: | ||
// 1. `requestAbortController` for instant request termination, particularly useful for stopping clients to upload when errors occur. | ||
// 2. `abortWithDelayController` to introduce a delay before aborting, allowing the server time to complete ongoing operations. | ||
// This is particularly useful when a future request may need to acquire a lock currently held by this request. | ||
const requestAbortController = new AbortController() | ||
const abortWithDelayController = new AbortController() | ||
|
||
const onDelayedAbort = (err: unknown) => { | ||
abortWithDelayController.signal.removeEventListener('abort', onDelayedAbort) | ||
setTimeout(() => { | ||
requestAbortController.abort(err) | ||
}, 200) | ||
} | ||
abortWithDelayController.signal.addEventListener('abort', onDelayedAbort) | ||
|
||
req.on('close', () => { | ||
abortWithDelayController.signal.removeEventListener('abort', onDelayedAbort) | ||
}) | ||
|
||
return { | ||
signal: requestAbortController.signal, | ||
abort: () => { | ||
// abort the request immediately | ||
if (!requestAbortController.signal.aborted) { | ||
requestAbortController.abort(ERRORS.ABORTED) | ||
} | ||
}, | ||
cancel: () => { | ||
// Initiates the delayed abort sequence unless it's already in progress. | ||
if (!abortWithDelayController.signal.aborted) { | ||
abortWithDelayController.abort(ERRORS.ABORTED) | ||
} | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters