Add dismiss for denied uploads
This commit is contained in:
@@ -173,7 +173,7 @@ function addRow (file: File, type: string): UploadRow {
|
|||||||
|
|
||||||
type Attempt =
|
type Attempt =
|
||||||
| { outcome: 'sent', duplicate: boolean }
|
| { outcome: 'sent', duplicate: boolean }
|
||||||
| { outcome: 'failed', message: string }
|
| { outcome: 'failed', message: string, retryable: boolean }
|
||||||
| { outcome: 'retry', waitMs: number }
|
| { outcome: 'retry', waitMs: number }
|
||||||
| { outcome: 'cancelled' }
|
| { outcome: 'cancelled' }
|
||||||
|
|
||||||
@@ -188,6 +188,17 @@ function failureMessage (xhr: XMLHttpRequest): string {
|
|||||||
return 'Could not be sent'
|
return 'Could not be sent'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A refused upload, with whether another try could succeed: the service or
|
||||||
|
* Immich is down, or a limit that lifts with time (the budget sends
|
||||||
|
* `Retry-After`). A refused file or a closed share fails the same way every
|
||||||
|
* time, so those rows get Dismiss rather than Retry.
|
||||||
|
*/
|
||||||
|
function failure (xhr: XMLHttpRequest): Attempt {
|
||||||
|
const retryable = xhr.status >= 500 || xhr.getResponseHeader('Retry-After') !== null
|
||||||
|
return { outcome: 'failed', message: failureMessage(xhr), retryable }
|
||||||
|
}
|
||||||
|
|
||||||
/** One request for one file. XHR rather than fetch, because only XHR reports upload progress. */
|
/** One request for one file. XHR rather than fetch, because only XHR reports upload progress. */
|
||||||
function attempt (row: UploadRow, attemptNumber: number): Promise<Attempt> {
|
function attempt (row: UploadRow, attemptNumber: number): Promise<Attempt> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
@@ -217,7 +228,7 @@ function attempt (row: UploadRow, attemptNumber: number): Promise<Attempt> {
|
|||||||
const seconds = Number(xhr.getResponseHeader('Retry-After'))
|
const seconds = Number(xhr.getResponseHeader('Retry-After'))
|
||||||
resolve(Number.isFinite(seconds) && seconds > 0 ? { outcome: 'retry', waitMs: seconds * 1000 } : backoff)
|
resolve(Number.isFinite(seconds) && seconds > 0 ? { outcome: 'retry', waitMs: seconds * 1000 } : backoff)
|
||||||
} else {
|
} else {
|
||||||
resolve({ outcome: 'failed', message: failureMessage(xhr) })
|
resolve(failure(xhr))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// A refusal that closes the connection mid-body often arrives as a network error
|
// A refusal that closes the connection mid-body often arrives as a network error
|
||||||
@@ -250,7 +261,7 @@ async function sendFile (row: UploadRow) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (result.outcome === 'failed') {
|
if (result.outcome === 'failed') {
|
||||||
finish(row, 'error', result.message, true)
|
finish(row, 'error', result.message, result.retryable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (attemptNumber >= ATTEMPTS || result.waitMs > MAX_RETRY_WAIT_MS) {
|
if (attemptNumber >= ATTEMPTS || result.waitMs > MAX_RETRY_WAIT_MS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user