Skip to content

Commit

Permalink
Improve playlist-size-error message (#3124)
Browse files Browse the repository at this point in the history
* Improve playlist-size-error message

* lint

---------

Co-authored-by: miko <[email protected]>
  • Loading branch information
keikari and miko authored Jul 15, 2024
1 parent 5e64a09 commit 613ebe6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions static/app-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,11 @@
"Larger upload list may take time to load with filters enabled": "Larger upload list may take time to load with filters enabled",
"Enable filters": "Enable filters",
"Past Due": "Past Due",
"Playlist exceeds size limits.": "Playlist exceeds size limits.",
"Please remove %itemsToDelete% items": "Please remove %itemsToDelete% items",
"Please remove 1 item": "Please remove 1 item",
"or %extraBytes% characters of text.": "or %extraBytes% characters of text.",
"or 1 character of text.": "or 1 character of text.",

"--end--": "--end--"
}
21 changes: 20 additions & 1 deletion ui/redux/actions/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,26 @@ export function doCollectionPublish(options: CollectionPublishCreateParams, coll

function failure(error) {
if (cb) cb();
dispatch(doToast({ message: error.message, isError: true }));

const scriptSizeError = error.message.match(/script size ([0-9]+) exceeds limit 8192/);
let customMessage = null;
if (scriptSizeError) {
const maxSize = 8192;
const itemSizeInTx = 24;
const extraBytes = parseInt(scriptSizeError.at(1).toString()) - maxSize;
const itemsToDelete = Math.ceil(extraBytes / itemSizeInTx);

customMessage = __('Playlist exceeds size limits.') +
' ' +
(itemsToDelete > 1
? __('Please remove %itemsToDelete% items', {itemsToDelete})
: __('Please remove 1 item')) +
' ' +
(extraBytes > 1
? __('or %extraBytes% characters of text.', {extraBytes})
: __('or 1 character of text.'));
}
dispatch(doToast({ message: customMessage || error.message, isError: true }));
reject(error);
throw new Error(error);
}
Expand Down

0 comments on commit 613ebe6

Please sign in to comment.