diff --git a/CHANGELOG b/CHANGELOG index ed90869..3656bc8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,6 +18,7 @@ Revision history for Lutim - Add .zip file check in the tests - Fix stats files place when using non-default theme - Allow to use a fixed domain + - Add localStorage export and import feature 0.10.4 2018-05-07 - Fix bug in cache system that would allow someone to view an image with an incorrect decryption key diff --git a/themes/default/lib/Lutim/I18N/lutim.pot b/themes/default/lib/Lutim/I18N/lutim.pot index 1452c66..e4bbad9 100644 --- a/themes/default/lib/Lutim/I18N/lutim.pot +++ b/themes/default/lib/Lutim/I18N/lutim.pot @@ -40,7 +40,7 @@ msgstr "" msgid "24 hours" msgstr "" -#: themes/default/templates/partial/myfiles.js.ep:62 +#: themes/default/templates/partial/myfiles.js.ep:120 msgid ": Error while trying to get the counter." msgstr "" @@ -60,7 +60,7 @@ msgstr "" msgid "Archives download" msgstr "" -#: themes/default/templates/about.html.ep:44 themes/default/templates/myfiles.html.ep:64 themes/default/templates/stats.html.ep:25 +#: themes/default/templates/about.html.ep:44 themes/default/templates/myfiles.html.ep:69 themes/default/templates/stats.html.ep:25 msgid "Back to homepage" msgstr "" @@ -84,11 +84,11 @@ msgstr "" msgid "Copy all view links to clipboard" msgstr "" -#: themes/default/templates/index.html.ep:18 themes/default/templates/index.html.ep:36 themes/default/templates/index.html.ep:69 themes/default/templates/index.html.ep:77 themes/default/templates/index.html.ep:85 themes/default/templates/index.html.ep:93 themes/default/templates/myfiles.html.ep:20 themes/default/templates/myfiles.html.ep:38 themes/default/templates/partial/common.js.ep:168 themes/default/templates/partial/lutim.js.ep:106 themes/default/templates/partial/lutim.js.ep:121 themes/default/templates/partial/lutim.js.ep:80 themes/default/templates/partial/lutim.js.ep:92 themes/default/templates/partial/myfiles.js.ep:30 +#: themes/default/templates/index.html.ep:18 themes/default/templates/index.html.ep:36 themes/default/templates/index.html.ep:69 themes/default/templates/index.html.ep:77 themes/default/templates/index.html.ep:85 themes/default/templates/index.html.ep:93 themes/default/templates/myfiles.html.ep:20 themes/default/templates/myfiles.html.ep:38 themes/default/templates/partial/common.js.ep:168 themes/default/templates/partial/lutim.js.ep:106 themes/default/templates/partial/lutim.js.ep:121 themes/default/templates/partial/lutim.js.ep:80 themes/default/templates/partial/lutim.js.ep:92 themes/default/templates/partial/myfiles.js.ep:88 msgid "Copy to clipboard" msgstr "" -#: themes/default/templates/myfiles.html.ep:52 +#: themes/default/templates/myfiles.html.ep:57 msgid "Counter" msgstr "" @@ -100,7 +100,7 @@ msgstr "" msgid "Delay repartition chart for enabled images" msgstr "" -#: themes/default/templates/index.html.ep:115 themes/default/templates/index.html.ep:147 themes/default/templates/index.html.ep:178 themes/default/templates/myfiles.html.ep:53 themes/default/templates/partial/lutim.js.ep:161 +#: themes/default/templates/index.html.ep:115 themes/default/templates/index.html.ep:147 themes/default/templates/index.html.ep:178 themes/default/templates/myfiles.html.ep:58 themes/default/templates/partial/lutim.js.ep:161 msgid "Delete at first view?" msgstr "" @@ -112,7 +112,7 @@ msgstr "" msgid "Deleted images in 30 days" msgstr "" -#: themes/default/templates/index.html.ep:98 themes/default/templates/myfiles.html.ep:56 themes/default/templates/partial/common.js.ep:160 themes/default/templates/partial/common.js.ep:163 +#: themes/default/templates/index.html.ep:98 themes/default/templates/myfiles.html.ep:61 themes/default/templates/partial/common.js.ep:160 themes/default/templates/partial/common.js.ep:163 msgid "Deletion link" msgstr "" @@ -148,11 +148,15 @@ msgstr "" msgid "Evolution of total files" msgstr "" -#: themes/default/templates/myfiles.html.ep:55 +#: themes/default/templates/myfiles.html.ep:60 msgid "Expires at" msgstr "" -#: themes/default/templates/myfiles.html.ep:50 +#: themes/default/templates/myfiles.html.ep:46 +msgid "Export localStorage data" +msgstr "" + +#: themes/default/templates/myfiles.html.ep:55 msgid "File name" msgstr "" @@ -208,6 +212,10 @@ msgstr "" msgid "Image not found." msgstr "" +#: themes/default/templates/myfiles.html.ep:47 +msgid "Import localStorage data" +msgstr "" + #: themes/default/templates/partial/navbar.html.ep:61 msgid "Informations" msgstr "" @@ -276,7 +284,7 @@ msgstr "" msgid "Next (arrow right)" msgstr "" -#: themes/default/templates/partial/myfiles.js.ep:20 +#: themes/default/templates/partial/myfiles.js.ep:78 msgid "No limit" msgstr "" @@ -354,6 +362,10 @@ msgstr "" msgid "The automatic download process will open a tab in your browser for each link. You need to allow popups for Lutim." msgstr "" +#: themes/default/templates/partial/myfiles.js.ep:32 +msgid "The data has been successfully imported." +msgstr "" + #: lib/Lutim/Controller.pm:158 lib/Lutim/Controller.pm:226 msgid "The delete token is invalid." msgstr "" @@ -446,7 +458,7 @@ msgstr "" msgid "Upload an image with its URL" msgstr "" -#: themes/default/templates/myfiles.html.ep:54 +#: themes/default/templates/myfiles.html.ep:59 msgid "Uploaded at" msgstr "" @@ -459,7 +471,7 @@ msgstr "" msgid "Uploading is currently disabled, please try later or contact the administrator (%1)." msgstr "" -#: themes/default/templates/index.html.ep:65 themes/default/templates/index.html.ep:67 themes/default/templates/myfiles.html.ep:51 themes/default/templates/partial/lutim.js.ep:72 themes/default/templates/partial/lutim.js.ep:76 +#: themes/default/templates/index.html.ep:65 themes/default/templates/index.html.ep:67 themes/default/templates/myfiles.html.ep:56 themes/default/templates/partial/lutim.js.ep:72 themes/default/templates/partial/lutim.js.ep:76 msgid "View link" msgstr "" diff --git a/themes/default/public/js/lutim.js b/themes/default/public/js/lutim.js index 1446489..ddb4a1b 100644 --- a/themes/default/public/js/lutim.js +++ b/themes/default/public/js/lutim.js @@ -105,6 +105,9 @@ $('document').ready(function() { }); } else if ($('#myfiles').length !== 0) { populateFilesTable(); + $('#json-export').on('click', function() { exportStorage(); }); + $('#json-import').on('click', function() { $('#import').click(); }); + $('#import').on('change', function() { importStorage(this.files); }) } $('.copy-to-clipboard-link').on('click', clickOnCopyLink); $('.copy-all-to-clipboard-link').on('click', copyAllToClipboard); diff --git a/themes/default/templates/myfiles.html.ep b/themes/default/templates/myfiles.html.ep index 50acd8a..2f77605 100644 --- a/themes/default/templates/myfiles.html.ep +++ b/themes/default/templates/myfiles.html.ep @@ -42,6 +42,11 @@ +
+ <%= l('Export localStorage data') %> + <%= l('Import localStorage data') %> + +
diff --git a/themes/default/templates/partial/myfiles.js.ep b/themes/default/templates/partial/myfiles.js.ep index 0a4814a..54a53d8 100644 --- a/themes/default/templates/partial/myfiles.js.ep +++ b/themes/default/templates/partial/myfiles.js.ep @@ -1,4 +1,57 @@ % # vim:set sw=4 ts=4 sts=4 ft=javascript expandtab: +function exportStorage() { + var a = $(''); + a.hide(); + $('body').append(a); + + var storageData = [localStorage.getItem('images')]; + var exportFile = new Blob(storageData, {type : 'application/json'}); + var url = window.URL.createObjectURL(exportFile); + + a.attr('href', url); + a.attr('download', 'data.json'); + $('#data-json')[0].click(); + $('#data-json').remove(); +} +function importStorage(f) { + var reader = new FileReader(); + reader.addEventListener("loadend", function() { + try { + var newFiles = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(reader.result))); + var i; + var hasImported = 0; + for (i = 0; i < newFiles.length; i++) { + var item = newFiles[i]; + if (!itemExists(item.short)) { + addItem(item); + hasImported++; + } + } + populateFilesTable(); + + goodToast('<%= l('The data has been successfully imported.') %>'); + } catch(err) { + alert(err); + } + }); + reader.readAsArrayBuffer(f[0]); +} +function itemExists(name) { + var files = localStorage.getItem('images'); + console.log(files); + if (files === null) { + return false; + } else { + files = JSON.parse(files); + var i; + for (i = 0; i < files.length; i++) { + if (files[i].short === name) { + return true; + } + } + return false; + } +} function onCheck(e, short, ext) { e.preventDefault(); if ($(this).is(':checked')) { @@ -10,8 +63,13 @@ function onCheck(e, short, ext) { } } function populateFilesTable() { - var files = JSON.parse(localStorage.getItem('images')); + var localImages = localStorage.getItem('images'); + if (localImages === null) { + return null; + } + var files = JSON.parse(localImages); files.reverse(); + $('#myfiles').empty(); files.forEach(function(element, index, array) { var real_short = element.real_short; var vlink = link(element.short+'.'+element.ext, '');