Skip to content

Commit

Permalink
Move max file size from inline to setting in config.js (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oglopf authored Jan 31, 2023
1 parent b32c3ac commit 7c55e1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apps/dashboard/app/javascript/packs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ function navbarHighlight(theme, color) {
}`;
}

function getConfigData() {
const cfgData = configData();

return cfgData;
}

export { setNavbarColor };
export { getConfigData};
17 changes: 16 additions & 1 deletion apps/dashboard/app/javascript/packs/files/uppy_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import XHRUpload from '@uppy/xhr-upload'
import _ from 'lodash';
import {CONTENTID, EVENTNAME as DATATABLE_EVENTNAME} from './data_table.js';
import { dupSafeName } from './utils.js';
import { getConfigData } from '../config.js';

let uppy = null;

Expand Down Expand Up @@ -67,7 +68,7 @@ jQuery(function() {

uppy = new Uppy({
restrictions: {
maxFileSize: maxFileSize,
maxFileSize: maxFileSize(),
},
onBeforeFileAdded: renameIfDuplicate,
onBeforeUpload: updateEndpoint,
Expand Down Expand Up @@ -184,3 +185,17 @@ function updateEndpoint() {
function reloadTable() {
$(CONTENTID).trigger(DATATABLE_EVENTNAME.reloadTable,{});
}

function maxFileSize () {
const cfgData = getConfigData();

// Check if cfgData['maxFileSize'] is just empty string,
// if so set default of maxFileUpload=10737420000 bytes.
if (cfgData['maxFileSize'].length == 0) {
return parseInt(10737420000, 10);
}
else {
const maxFileSize = cfgData['maxFileSize'];
return parseInt(maxFileSize, 10);
}
}
1 change: 0 additions & 1 deletion apps/dashboard/app/views/files/_inline_js.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
const csrf_token = document.querySelector('meta[name="csrf-token"]').content;
const dashboard_files_directory_download_error_modal_title = '<%= t('dashboard.files_directory_download_error_modal_title') %>';
const maxFileSize = '<%= Configuration.file_upload_max %>';
const transfersPath = '<%= transfers_path(format: "json") %>';
const alert = '<%= alert %>';
history.replaceState({
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<meta id="ood_config"
data-bg-color="<%= @user_configuration.brand_bg_color %>"
data-link-bg-color="<%= @user_configuration.brand_link_active_bg_color %>"
data-max-file-size="<%= Configuration.file_upload_max %>"
/>
</head>
<body>
Expand Down

0 comments on commit 7c55e1b

Please sign in to comment.