Skip to content

Commit e43053b

Browse files
committed
refactor(upload): remove localization - this is pure API
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent e740dce commit e43053b

6 files changed

Lines changed: 6 additions & 76 deletions

File tree

lib/upload/errors/UploadCancelledError.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import { t } from '../utils/l10n.ts'
65

76
export class UploadCancelledError extends Error {
87
__UPLOAD_CANCELLED__ = true
98

109
public constructor(cause?: unknown) {
11-
super(t('Upload has been cancelled'), { cause })
10+
super('Upload has been cancelled', { cause })
1211
}
1312

1413
public static isCancelledError(error: unknown): error is UploadCancelledError {

lib/upload/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
export type { Eta, EtaEventsMap } from './uploader/index.ts'
77
export type { Directory, IDirectory } from './utils/fileTree.ts'
88

9-
export { getUploader, upload } from './getUploader.ts'
9+
export { getUploader } from './getUploader.ts'
1010
export { Upload, UploadStatus } from './uploader/Upload.ts'
1111
export { EtaStatus, Uploader, UploaderStatus } from './uploader/index.ts'
1212
export { getConflicts, hasConflict } from './utils/conflicts.ts'

lib/upload/uploader/Eta.spec.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe('ETA - status', () => {
1111
const eta = new Eta()
1212
expect(eta.progress).toBe(0)
1313
expect(eta.time).toBe(Infinity)
14-
expect(eta.timeReadable).toBe('estimating time left')
1514
expect(eta.speed).toBe(-1)
1615
expect(eta.status).toBe(EtaStatus.Idle)
1716
})
@@ -21,7 +20,6 @@ describe('ETA - status', () => {
2120
expect(eta.status).toBe(EtaStatus.Running)
2221
expect(eta.progress).toBe(0)
2322
expect(eta.time).toBe(Infinity)
24-
expect(eta.timeReadable).toBe('estimating time left')
2523
expect(eta.speed).toBe(-1)
2624
})
2725

@@ -82,12 +80,11 @@ describe('ETA - progress', () => {
8280
eta.add(2.5 * 1024 * 1024)
8381
expect(eta.progress).toBe(i * 2.5)
8482
expect(eta.speed).toBe(-1)
85-
expect(eta.speedReadable).toBe('')
8683
expect(eta.time).toBe(Infinity)
8784
}
8885

8986
// this is reached after (virtual) 3s with 6 * 2.5MiB (=15MiB) data of 100MiB total
90-
expect(eta.timeReadable).toBe('estimating time left')
87+
expect(eta.time).toBe(Infinity)
9188

9289
// Adding another 500ms with 5MiB/s will result in enough information for estimating
9390
vi.advanceTimersByTime(500)
@@ -96,7 +93,6 @@ describe('ETA - progress', () => {
9693
expect(eta.speed).toMatchInlineSnapshot('4826778')
9794
expect(eta.speedReadable).toMatchInlineSnapshot('"4.6 MB∕s"')
9895
expect(eta.time).toMatchInlineSnapshot('18')
99-
expect(eta.timeReadable).toMatchInlineSnapshot('"18 seconds left"')
10096

10197
// Skip forward another 4.5seconds
10298
for (let i = 0; i < 9; i++) {
@@ -109,7 +105,6 @@ describe('ETA - progress', () => {
109105
expect(eta.speed).toMatchInlineSnapshot('5060836')
110106
expect(eta.speedReadable).toMatchInlineSnapshot('"4.8 MB∕s"')
111107
expect(eta.time).toMatchInlineSnapshot('12')
112-
expect(eta.timeReadable).toMatchInlineSnapshot('"12 seconds left"')
113108

114109
// Having a spike of 10MiB/s will not result in halfing the eta
115110
vi.advanceTimersByTime(500)
@@ -120,7 +115,6 @@ describe('ETA - progress', () => {
120115
expect(eta.speedReadable).toMatchInlineSnapshot('"5 MB∕s"')
121116
// And the time has not halved
122117
expect(eta.time).toMatchInlineSnapshot('11')
123-
expect(eta.timeReadable).toMatchInlineSnapshot('"11 seconds left"')
124118

125119
// Add another 3 seconds so we should see 'few seconds left'
126120
for (let i = 0; i < 6; i++) {
@@ -130,7 +124,6 @@ describe('ETA - progress', () => {
130124
expect(eta.progress).toBe(60)
131125
expect(eta.speed).toMatchInlineSnapshot('5344192')
132126
expect(eta.time).toMatchInlineSnapshot('8')
133-
expect(eta.timeReadable).toMatchInlineSnapshot('"a few seconds left"')
134127
})
135128

136129
test('long running progress', () => {
@@ -151,8 +144,6 @@ describe('ETA - progress', () => {
151144
eta.add(512 * 1024)
152145
expect(eta.progress).toBe(3.5)
153146
expect(eta.time).toBe(105)
154-
// time is over 1 minute so we see the formatted output
155-
expect(eta.timeReadable).toMatchInlineSnapshot('"00:01:45 left"')
156147

157148
// Add another minute and we should see only seconds:
158149
for (let i = 0; i < 120; i++) {
@@ -164,7 +155,6 @@ describe('ETA - progress', () => {
164155
// Now we have uploaded 63.5 MiB - so 36.5 MiB missing by having 1MiB/s upload speed we expect 37 seconds left:
165156
expect(eta.progress).toBe(63.5)
166157
expect(eta.time).toBe(37)
167-
expect(eta.timeReadable).toMatchInlineSnapshot('"37 seconds left"')
168158
})
169159

170160
test('progress calculation for fast uploads', () => {
@@ -180,15 +170,13 @@ describe('ETA - progress', () => {
180170
expect(eta.progress).toBe(20)
181171
expect(eta.speed).toBe(-1)
182172
expect(eta.time).toBe(Infinity)
183-
expect(eta.timeReadable).toBe('estimating time left')
184173

185174
// Now we have some information but not enough for normal estimation
186175
// yet we show some information as the upload is very fast (40% per second)
187176
vi.advanceTimersByTime(500)
188177
eta.add(20 * 1024 * 1024)
189178
expect(eta.progress).toBe(40)
190179
expect(eta.time).toBe(1.5)
191-
expect(eta.timeReadable).toBe('a few seconds left')
192180
// still no speed information
193181
expect(eta.speed).toBe(-1)
194182

@@ -198,7 +186,6 @@ describe('ETA - progress', () => {
198186
eta.add(20 * 1024 * 1024)
199187
expect(eta.progress).toBe(40 + i * 20)
200188
expect(eta.time).toBe(1.5 - (i / 2))
201-
expect(eta.timeReadable).toBe('a few seconds left')
202189
// still no speed information
203190
expect(eta.speed).toBe(-1)
204191
}
@@ -210,7 +197,6 @@ describe('ETA - progress', () => {
210197
expect(eta.status).toBe(EtaStatus.Running)
211198
expect(eta.progress).toBe(0)
212199
expect(eta.time).toBe(Infinity)
213-
expect(eta.timeReadable).toBe('estimating time left')
214200
expect(eta.speed).toBe(-1)
215201
})
216202

lib/upload/uploader/Eta.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { TypedEventTarget } from 'typescript-event-target'
77
import { formatFileSize } from '../../utils/fileSize.ts'
8-
import { n, t } from '../utils/l10n.ts'
98

109
export const EtaStatus = Object.freeze({
1110
Idle: 0,
@@ -183,29 +182,12 @@ export class Eta extends TypedEventTarget<EtaEventsMap> {
183182

184183
/**
185184
* Estimated time in seconds.
185+
* If the time is not yet estimated, it will return `Infinity`.
186186
*/
187187
public get time(): number {
188188
return this._eta
189189
}
190190

191-
/**
192-
* Human readable version of the estimated time.
193-
*/
194-
public get timeReadable(): string {
195-
if (this._eta === Infinity) {
196-
return t('estimating time left')
197-
} else if (this._eta < 10) {
198-
return t('a few seconds left')
199-
} else if (this._eta < 60) {
200-
return n('{seconds} seconds left', '{seconds} seconds left', this._eta, { seconds: this._eta })
201-
}
202-
203-
const hours = String(Math.floor(this._eta / 3600)).padStart(2, '0')
204-
const minutes = String(Math.floor((this._eta % 3600) / 60)).padStart(2, '0')
205-
const seconds = String(this._eta % 60).padStart(2, '0')
206-
return t('{time} left', { time: `${hours}:${minutes}:${seconds}` }) // TRANSLATORS time has the format 00:00:00
207-
}
208-
209191
/**
210192
* Transfer speed in bytes per second.
211193
* Returns `-1` if not yet estimated.

lib/upload/uploader/Uploader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { UploadCancelledError } from '../errors/UploadCancelledError.ts'
2222
import { getMaxChunksSize } from '../utils/config.ts'
2323
import { isFileSystemFileEntry } from '../utils/filesystem.ts'
2424
import { Directory } from '../utils/fileTree.ts'
25-
import { t } from '../utils/l10n.ts'
2625
import { getChunk, initChunkWorkspace, uploadData } from '../utils/upload.ts'
2726
import { Eta } from './Eta.ts'
2827
import { Upload, UploadStatus } from './Upload.ts'
@@ -630,7 +629,7 @@ export class Uploader {
630629
throw new UploadCancelledError(error)
631630
} else {
632631
upload.status = UploadStatus.FAILED
633-
throw new Error(t('Failed to assemble the chunks together'))
632+
throw new Error('Failed to assemble the chunks together')
634633
}
635634
} finally {
636635
// Notify listeners of the upload completion
@@ -689,7 +688,7 @@ export class Uploader {
689688

690689
upload.status = UploadStatus.FAILED
691690
logger.error(`Failed uploading ${file.name}`, { error, file, upload })
692-
throw new Error(t('Failed to upload the file'))
691+
throw new Error('Failed to upload the file')
693692
} finally {
694693
// Notify listeners of the upload completion
695694
this._notifyAll(upload)

lib/upload/utils/l10n.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)