Skip to content

Commit 8509eaf

Browse files
committed
MOBILE-2272 attachments: Correctly handle maxSize=0
1 parent 0cf2b3c commit 8509eaf

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/components/attachments/attachments.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { Component, Input, OnInit } from '@angular/core';
1616
import { TranslateService } from '@ngx-translate/core';
1717
import { CoreAppProvider } from '@providers/app';
18+
import { CoreSites } from '@providers/sites';
1819
import { CoreDomUtilsProvider } from '@providers/utils/dom';
1920
import { CoreTextUtilsProvider } from '@providers/utils/text';
2021
import { CoreFileUploaderProvider } from '@core/fileuploader/providers/fileuploader';
@@ -39,7 +40,7 @@ import { CoreFileUploaderHelperProvider } from '@core/fileuploader/providers/hel
3940
})
4041
export class CoreAttachmentsComponent implements OnInit {
4142
@Input() files: any[]; // List of attachments. New attachments will be added to this array.
42-
@Input() maxSize: number; // Max size for attachments. -1 means unlimited, not defined or 0 means unknown limit.
43+
@Input() maxSize: number; // Max size for attachments. -1 means unlimited, 0 means user max size, not defined means unknown.
4344
@Input() maxSubmissions: number; // Max number of attachments. -1 means unlimited, not defined means unknown limit.
4445
@Input() component: string; // Component the downloaded files will be linked to.
4546
@Input() componentId: string | number; // Component ID.
@@ -61,14 +62,23 @@ export class CoreAttachmentsComponent implements OnInit {
6162
* Component being initialized.
6263
*/
6364
ngOnInit(): void {
64-
this.maxSize = Number(this.maxSize) || 0; // Make sure it's defined and it's a number.
65+
this.maxSize = this.maxSize !== null ? Number(this.maxSize) : NaN;
6566

6667
if (this.maxSize === 0) {
67-
this.maxSizeReadable = this.translate.instant('core.unknown');
68+
const currentSite = CoreSites.instance.getCurrentSite();
69+
const siteInfo = currentSite && currentSite.getInfo();
70+
71+
if (siteInfo && siteInfo.usermaxuploadfilesize) {
72+
this.maxSizeReadable = this.textUtils.bytesToSize(siteInfo.usermaxuploadfilesize, 2);
73+
} else {
74+
this.maxSizeReadable = this.translate.instant('core.unknown');
75+
}
6876
} else if (this.maxSize > 0) {
6977
this.maxSizeReadable = this.textUtils.bytesToSize(this.maxSize, 2);
70-
} else {
78+
} else if (this.maxSize === -1) {
7179
this.maxSizeReadable = this.translate.instant('core.unlimited');
80+
} else {
81+
this.maxSizeReadable = this.translate.instant('core.unknown');
7282
}
7383

7484
if (typeof this.maxSubmissions == 'undefined' || this.maxSubmissions < 0) {

upgrade.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ information provided here is intended especially for developers.
33

44
=== 3.9.3 ===
55

6-
- In the core-attachments component, passing a -1 as maxSize or maxSubmissions used to mean "unknown limit". Now -1 means unlimited.
6+
- In the core-attachments component, passing a -1 as maxSize or maxSubmissions used to mean "unknown limit". Now -1 means unlimited. Also, passing a 0 to maxSize used to mean "unknown" too, now 0 means user max size.
77

88
=== 3.8.3 ===
99

0 commit comments

Comments
 (0)