mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-08-06 17:03:25 +02:00
Fix #67 - Add localStorage export and import feature
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="files-buttons">
|
||||
<a href="#" id="json-export" class="btn btn-info"><%= l('Export localStorage data') %></a>
|
||||
<a href="#" id="json-import" class="btn btn-info"><%= l('Import localStorage data') %></a>
|
||||
<input type="file" class="hidden" id="import">
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
|
||||
@@ -1,4 +1,57 @@
|
||||
% # vim:set sw=4 ts=4 sts=4 ft=javascript expandtab:
|
||||
function exportStorage() {
|
||||
var a = $('<a id="data-json">');
|
||||
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, '');
|
||||
|
||||
Reference in New Issue
Block a user