@@ -12,19 +12,34 @@ import { getExtension } from "./util";
12
12
13
13
const MB : number = 1000000 ;
14
14
15
- const LIMITS = {
15
+ const LISTED_LIMITS = {
16
16
listing : 3000 , // directory listing is truncated after this many files
17
17
ipynb : 7 * MB ,
18
18
sagews : 5 * MB ,
19
19
whiteboard : 3 * MB ,
20
20
slides : 3 * MB ,
21
21
other : 1 * MB ,
22
+ html : 3 * MB ,
22
23
// no special viewer
23
24
generic : 2 * MB ,
24
25
} ;
25
26
27
+ const UNLISTED_LIMITS = {
28
+ ...LISTED_LIMITS ,
29
+ ipynb : 15 * MB ,
30
+ sagews : 10 * MB ,
31
+ whiteboard : 10 * MB ,
32
+ slides : 10 * MB ,
33
+ other : 5 * MB ,
34
+ html : 40 * MB , // E.g., cambridge: https://cocalc.com/Cambridge/S002211202200903X/S002211202200903X-Figure-4/files/Figure4.html
35
+
36
+ // no special viewer
37
+ generic : 10 * MB ,
38
+ } ;
39
+
26
40
// also used for proxied content -- see https://github.com/sagemathinc/cocalc/issues/8020
27
- export function getSizeLimit ( path : string ) : number {
41
+ export function getSizeLimit ( path : string , unlisted : boolean = false ) : number {
42
+ const LIMITS = unlisted ? UNLISTED_LIMITS : LISTED_LIMITS ;
28
43
const ext = getExtension ( path ) ;
29
44
if ( hasSpecialViewer ( ext ) ) {
30
45
return LIMITS [ ext ] ?? LIMITS . other ;
@@ -53,6 +68,7 @@ export interface PathContents {
53
68
export default async function getContents (
54
69
project_id : string ,
55
70
path : string ,
71
+ unlisted ?: boolean , // if true, higher size limits, since much less likely to be abused
56
72
) : Promise < PathContents > {
57
73
const fsPath = pathToFiles ( project_id , path ) ;
58
74
const obj : PathContents = { } ;
@@ -70,7 +86,7 @@ export default async function getContents(
70
86
}
71
87
} else {
72
88
// get actual file content
73
- if ( stats . size >= getSizeLimit ( fsPath ) ) {
89
+ if ( stats . size >= getSizeLimit ( fsPath , unlisted ) ) {
74
90
obj . truncated = "File too big to be displayed; download it instead." ;
75
91
} else {
76
92
obj . content = ( await fs . readFile ( fsPath ) ) . toString ( ) ;
@@ -107,8 +123,8 @@ async function getDirectoryListing(
107
123
obj . error = err ;
108
124
}
109
125
listing . push ( obj ) ;
110
- if ( listing . length >= LIMITS . listing ) {
111
- truncated = `Too many files -- only showing ${ LIMITS . listing } of them.` ;
126
+ if ( listing . length >= LISTED_LIMITS . listing ) {
127
+ truncated = `Too many files -- only showing ${ LISTED_LIMITS . listing } of them.` ;
112
128
break ;
113
129
}
114
130
}
0 commit comments