Skip to content

Commit 26338fa

Browse files
committed
expose MaxUploadSize site setting to the client as QPixel.MAX_UPLOAD_SIZE
1 parent 924e5dd commit 26338fa

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

app/views/layouts/_expose.html.erb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script type="application/javascript">
2+
window.QPixel ||= {};
3+
4+
Object.defineProperty(QPixel, 'ALLOWED_POST_ATTRS', {
5+
configurable: false,
6+
value: Object.freeze(<%= raw PostsHelper::PostScrubber::ALLOWED_ATTRS %>),
7+
writable: false,
8+
});
9+
10+
Object.defineProperty(QPixel, 'ALLOWED_POST_TAGS', {
11+
configurable: false,
12+
value: Object.freeze(<%= raw PostsHelper::PostScrubber::ALLOWED_TAGS %>),
13+
writable: false,
14+
});
15+
16+
Object.defineProperty(QPixel, 'MAX_UPLOAD_SIZE', {
17+
configurable: false,
18+
value: "<%= SiteSetting['MaxUploadSize'] || '2MB' %>",
19+
writable: false,
20+
});
21+
</script>

app/views/layouts/_head.html.erb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,7 @@
4646
<%= javascript_include_tag 'application' %>
4747
<script src="https://cdn.jsdelivr.net/npm/@codidact/co-design@latest/js/co-design.js" defer></script>
4848

49-
<script type="application/javascript">
50-
window.QPixel ||= {};
51-
52-
Object.defineProperty(QPixel, 'ALLOWED_POST_ATTRS', {
53-
configurable: false,
54-
value: Object.freeze(<%= raw PostsHelper::PostScrubber::ALLOWED_ATTRS %>),
55-
writable: false,
56-
});
57-
58-
Object.defineProperty(QPixel, 'ALLOWED_POST_TAGS', {
59-
configurable: false,
60-
value: Object.freeze(<%= raw PostsHelper::PostScrubber::ALLOWED_TAGS %>),
61-
writable: false,
62-
});
63-
</script>
49+
<%= render 'layouts/expose' %>
6450

6551
<% if SiteSetting['SyntaxHighlightingEnabled'] %>
6652
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css">

global.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ interface QPixel {
386386
* List of attributes allowed on HTML tags in posts, supplied by the server
387387
*/
388388
readonly ALLOWED_POST_ATTRS?: readonly string[]
389+
/**
390+
* Maximum file upload size (arbitrary unit)
391+
*/
392+
readonly MAX_UPLOAD_SIZE?: string
389393

390394
// private properties
391395
_filters?: Record<string, QPixelFilter> | null;

0 commit comments

Comments
 (0)