mirror of https://github.com/keeweb/keeweb.git
save uuid
This commit is contained in:
parent
2998e3f614
commit
530596b615
|
@ -10,7 +10,8 @@ var Backbone = require('backbone'),
|
|||
FileInfoCollection = require('../collections/file-info-collection'),
|
||||
FileModel = require('./file-model'),
|
||||
FileInfoModel = require('./file-info-model'),
|
||||
Storage = require('../storage');
|
||||
Storage = require('../storage'),
|
||||
IdGenerator = require('../util/id-generator');
|
||||
|
||||
var AppModel = Backbone.Model.extend({
|
||||
defaults: {},
|
||||
|
@ -260,11 +261,12 @@ var AppModel = Backbone.Model.extend({
|
|||
}
|
||||
if (!params.offline) {
|
||||
if (params.availOffline) {
|
||||
Storage.cache.save(file.id, params.fileData, function(err) {
|
||||
var cacheId = IdGenerator.uuid();
|
||||
Storage.cache.save(cacheId, params.fileData, function(err) {
|
||||
if (err) {
|
||||
file.set('availOffline', false);
|
||||
}
|
||||
that.addToLastOpenFiles(file);
|
||||
that.addToLastOpenFiles(file, cacheId);
|
||||
});
|
||||
} else {
|
||||
Storage.cache.remove(file.id);
|
||||
|
@ -274,9 +276,9 @@ var AppModel = Backbone.Model.extend({
|
|||
});
|
||||
},
|
||||
|
||||
addToLastOpenFiles: function(file) {
|
||||
addToLastOpenFiles: function(file, id) {
|
||||
var fileInfo = new FileInfoModel({
|
||||
id: file.id,
|
||||
id: id,
|
||||
name: file.get('name'),
|
||||
storage: file.get('storage'),
|
||||
path: file.get('path'),
|
||||
|
@ -287,8 +289,8 @@ var AppModel = Backbone.Model.extend({
|
|||
pullDate: null,
|
||||
openDate: new Date()
|
||||
});
|
||||
this.fileInfos.remove(file.id);
|
||||
this.fileInfos.push(fileInfo);
|
||||
this.fileInfos.remove(id);
|
||||
this.fileInfos.unshift(fileInfo);
|
||||
this.fileInfos.save();
|
||||
},
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ var StorageFileCache = {
|
|||
path: null,
|
||||
|
||||
getPath: function(id) {
|
||||
// get safe file name by base64 as described in RFC3548: http://tools.ietf.org/html/rfc3548#page-6
|
||||
id = id.replace(/\//g, '_').replace(/\+/g, '-');
|
||||
return Launcher.req('path').join(this.path, id);
|
||||
},
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var IdGenerator = {
|
||||
uuid: function() {
|
||||
var s4 = IdGenerator.s4;
|
||||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
||||
},
|
||||
s4: function() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = IdGenerator;
|
|
@ -327,7 +327,7 @@ var OpenView = Backbone.View.extend({
|
|||
});
|
||||
that.model.fileInfos.forEach(function(fi) {
|
||||
if (fi.get('storage') === 'dropbox' && !fi.get('modified') && !allFileNames[fi.get('name')]) {
|
||||
that.model.removeFileInfo(fi.get('id'));
|
||||
that.model.removeFileInfo(fi.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue