transloadit 4.0.7 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +200 -21
- package/dist/ApiError.d.ts +1 -1
- package/dist/ApiError.d.ts.map +1 -1
- package/dist/ApiError.js.map +1 -1
- package/dist/Transloadit.d.ts +23 -4
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +62 -28
- package/dist/Transloadit.js.map +1 -1
- package/dist/apiTypes.d.ts +1 -1
- package/dist/apiTypes.d.ts.map +1 -1
- package/dist/cli/OutputCtl.d.ts +46 -0
- package/dist/cli/OutputCtl.d.ts.map +1 -0
- package/dist/cli/OutputCtl.js +85 -0
- package/dist/cli/OutputCtl.js.map +1 -0
- package/dist/cli/commands/BaseCommand.d.ts +23 -0
- package/dist/cli/commands/BaseCommand.d.ts.map +1 -0
- package/dist/cli/commands/BaseCommand.js +52 -0
- package/dist/cli/commands/BaseCommand.js.map +1 -0
- package/dist/cli/commands/assemblies.d.ts +93 -0
- package/dist/cli/commands/assemblies.d.ts.map +1 -0
- package/dist/cli/commands/assemblies.js +1021 -0
- package/dist/cli/commands/assemblies.js.map +1 -0
- package/dist/cli/commands/auth.d.ts +28 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.js +280 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/bills.d.ts +14 -0
- package/dist/cli/commands/bills.d.ts.map +1 -0
- package/dist/cli/commands/bills.js +69 -0
- package/dist/cli/commands/bills.js.map +1 -0
- package/dist/cli/commands/index.d.ts +3 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +39 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/notifications.d.ts +16 -0
- package/dist/cli/commands/notifications.d.ts.map +1 -0
- package/dist/cli/commands/notifications.js +44 -0
- package/dist/cli/commands/notifications.js.map +1 -0
- package/dist/cli/commands/templates.d.ts +81 -0
- package/dist/cli/commands/templates.d.ts.map +1 -0
- package/dist/cli/commands/templates.js +428 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/helpers.d.ts +13 -0
- package/dist/cli/helpers.d.ts.map +1 -0
- package/dist/cli/helpers.js +39 -0
- package/dist/cli/helpers.js.map +1 -0
- package/dist/cli/template-last-modified.d.ts +10 -0
- package/dist/cli/template-last-modified.d.ts.map +1 -0
- package/dist/cli/template-last-modified.js +134 -0
- package/dist/cli/template-last-modified.js.map +1 -0
- package/dist/cli/types.d.ts +152 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +64 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli.d.ts +2 -12
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -256
- package/dist/cli.js.map +1 -1
- package/dist/tus.d.ts +2 -1
- package/dist/tus.d.ts.map +1 -1
- package/dist/tus.js +33 -5
- package/dist/tus.js.map +1 -1
- package/package.json +12 -7
- package/src/ApiError.ts +2 -1
- package/src/Transloadit.ts +98 -39
- package/src/apiTypes.ts +1 -1
- package/src/cli/OutputCtl.ts +115 -0
- package/src/cli/commands/BaseCommand.ts +71 -0
- package/src/cli/commands/assemblies.ts +1373 -0
- package/src/cli/commands/auth.ts +354 -0
- package/src/cli/commands/bills.ts +91 -0
- package/src/cli/commands/index.ts +65 -0
- package/src/cli/commands/notifications.ts +63 -0
- package/src/cli/commands/templates.ts +556 -0
- package/src/cli/helpers.ts +50 -0
- package/src/cli/template-last-modified.ts +156 -0
- package/src/cli/types.ts +183 -0
- package/src/cli.ts +12 -305
- package/src/tus.ts +37 -5
package/src/tus.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { basename } from 'node:path'
|
|
|
3
3
|
import type { Readable } from 'node:stream'
|
|
4
4
|
import debug from 'debug'
|
|
5
5
|
import pMap from 'p-map'
|
|
6
|
-
import {
|
|
6
|
+
import type { OnSuccessPayload, UploadOptions } from 'tus-js-client'
|
|
7
|
+
import { Upload } from 'tus-js-client'
|
|
7
8
|
import type { AssemblyStatus } from './alphalib/types/assemblyStatus.ts'
|
|
8
9
|
import type { UploadProgress } from './Transloadit.ts'
|
|
9
10
|
|
|
@@ -20,6 +21,7 @@ interface SendTusRequestOptions {
|
|
|
20
21
|
requestedChunkSize: number
|
|
21
22
|
uploadConcurrency: number
|
|
22
23
|
onProgress: (options: UploadProgress) => void
|
|
24
|
+
signal?: AbortSignal
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export async function sendTusRequest({
|
|
@@ -28,6 +30,7 @@ export async function sendTusRequest({
|
|
|
28
30
|
requestedChunkSize,
|
|
29
31
|
uploadConcurrency,
|
|
30
32
|
onProgress,
|
|
33
|
+
signal,
|
|
31
34
|
}: SendTusRequestOptions) {
|
|
32
35
|
const streamLabels = Object.keys(streamsMap)
|
|
33
36
|
|
|
@@ -42,6 +45,9 @@ export async function sendTusRequest({
|
|
|
42
45
|
await pMap(
|
|
43
46
|
streamLabels,
|
|
44
47
|
async (label) => {
|
|
48
|
+
// Check if aborted before each operation
|
|
49
|
+
if (signal?.aborted) throw new Error('Upload aborted')
|
|
50
|
+
|
|
45
51
|
const streamInfo = streamsMap[label]
|
|
46
52
|
if (!streamInfo) {
|
|
47
53
|
throw new Error(`Stream info not found for label: ${label}`)
|
|
@@ -54,7 +60,7 @@ export async function sendTusRequest({
|
|
|
54
60
|
totalBytes += size
|
|
55
61
|
}
|
|
56
62
|
},
|
|
57
|
-
{ concurrency: 5 },
|
|
63
|
+
{ concurrency: 5, signal },
|
|
58
64
|
)
|
|
59
65
|
|
|
60
66
|
const uploadProgresses: Record<string, number> = {}
|
|
@@ -102,12 +108,29 @@ export async function sendTusRequest({
|
|
|
102
108
|
|
|
103
109
|
const filename = path ? basename(path) : label
|
|
104
110
|
|
|
105
|
-
await new Promise<OnSuccessPayload>((
|
|
111
|
+
await new Promise<OnSuccessPayload>((resolvePromise, rejectPromise) => {
|
|
106
112
|
if (!assembly.assembly_ssl_url) {
|
|
107
|
-
|
|
113
|
+
rejectPromise(new Error('assembly_ssl_url is not present in the assembly status'))
|
|
108
114
|
return
|
|
109
115
|
}
|
|
110
116
|
|
|
117
|
+
// Check if already aborted before starting
|
|
118
|
+
if (signal?.aborted) {
|
|
119
|
+
rejectPromise(new Error('Upload aborted'))
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Wrap resolve/reject to clean up abort listener
|
|
124
|
+
let abortHandler: (() => void) | undefined
|
|
125
|
+
const resolve = (payload: OnSuccessPayload) => {
|
|
126
|
+
if (abortHandler) signal?.removeEventListener('abort', abortHandler)
|
|
127
|
+
resolvePromise(payload)
|
|
128
|
+
}
|
|
129
|
+
const reject = (err: unknown) => {
|
|
130
|
+
if (abortHandler) signal?.removeEventListener('abort', abortHandler)
|
|
131
|
+
rejectPromise(err)
|
|
132
|
+
}
|
|
133
|
+
|
|
111
134
|
const tusOptions: UploadOptions = {
|
|
112
135
|
endpoint: assembly.tus_url,
|
|
113
136
|
metadata: {
|
|
@@ -126,11 +149,20 @@ export async function sendTusRequest({
|
|
|
126
149
|
|
|
127
150
|
const tusUpload = new Upload(stream, tusOptions)
|
|
128
151
|
|
|
152
|
+
// Handle abort signal
|
|
153
|
+
if (signal) {
|
|
154
|
+
abortHandler = () => {
|
|
155
|
+
tusUpload.abort()
|
|
156
|
+
reject(new Error('Upload aborted'))
|
|
157
|
+
}
|
|
158
|
+
signal.addEventListener('abort', abortHandler, { once: true })
|
|
159
|
+
}
|
|
160
|
+
|
|
129
161
|
tusUpload.start()
|
|
130
162
|
})
|
|
131
163
|
|
|
132
164
|
log(label, 'upload done')
|
|
133
165
|
}
|
|
134
166
|
|
|
135
|
-
await pMap(streamLabels, uploadSingleStream, { concurrency: uploadConcurrency })
|
|
167
|
+
await pMap(streamLabels, uploadSingleStream, { concurrency: uploadConcurrency, signal })
|
|
136
168
|
}
|