Import document from Google Drive
This commit is contained in:
parent
e7800be299
commit
19c6c02786
@ -295,11 +295,7 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
|||||||
if(fileId.length === 0) {
|
if(fileId.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gdrive.downloadMetadata([fileId], function(result) {
|
gdrive.importFiles([fileId]);
|
||||||
if(result === undefined || result.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshManageSync() {
|
function refreshManageSync() {
|
||||||
|
48
js/gdrive.js
48
js/gdrive.js
@ -254,8 +254,8 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
message: jqXHR.statusText
|
message: jqXHR.statusText
|
||||||
};
|
};
|
||||||
// Handle error
|
// Handle error
|
||||||
if(error.code === 403) {
|
if(error.code === 403 || error.code === 404) {
|
||||||
error = "File is not available";
|
error = "File is not available.";
|
||||||
}
|
}
|
||||||
handleError(error, asyncTask, callback);
|
handleError(error, asyncTask, callback);
|
||||||
});
|
});
|
||||||
@ -366,6 +366,27 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
upload(id, undefined, title, content, callback);
|
upload(id, undefined, title, content, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
gdrive.importFiles = function(ids) {
|
||||||
|
gdrive.downloadMetadata(ids, function(result) {
|
||||||
|
if(result === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gdrive.downloadContent(result, function(result) {
|
||||||
|
if(result === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i=0; i<result.length; i++) {
|
||||||
|
var file = result[i];
|
||||||
|
fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id;
|
||||||
|
localStorage[fileSyncIndex + ".etag"] = file.etag;
|
||||||
|
var fileIndex = fileManager.createFile(file.title, file.content, [fileSyncIndex]);
|
||||||
|
fileManager.selectFile(fileIndex);
|
||||||
|
core.showMessage('"' + file.title + '" imported successfully from Google Drive.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
gdrive.init = function(fileManagerModule) {
|
gdrive.init = function(fileManagerModule) {
|
||||||
fileManager = fileManagerModule;
|
fileManager = fileManagerModule;
|
||||||
var state = localStorage["sync.gdrive.state"];
|
var state = localStorage["sync.gdrive.state"];
|
||||||
@ -386,7 +407,7 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (state.action == "open") {
|
else if (state.action == "open") {
|
||||||
var importIds = [];
|
var ids = [];
|
||||||
for(var i=0; i<state.ids.length; i++) {
|
for(var i=0; i<state.ids.length; i++) {
|
||||||
var id = state.ids[i];
|
var id = state.ids[i];
|
||||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + id;
|
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + id;
|
||||||
@ -394,27 +415,10 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
fileManager.selectFile(fileIndex);
|
fileManager.selectFile(fileIndex);
|
||||||
} else {
|
} else {
|
||||||
importIds.push(id);
|
ids.push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gdrive.downloadMetadata(importIds, function(result) {
|
gdrive.importFiles(ids);
|
||||||
if(result === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gdrive.downloadContent(result, function(result) {
|
|
||||||
if(result === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(var i=0; i<result.length; i++) {
|
|
||||||
var file = result[i];
|
|
||||||
fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id;
|
|
||||||
localStorage[fileSyncIndex + ".etag"] = file.etag;
|
|
||||||
var fileIndex = fileManager.createFile(file.title, file.content, [fileSyncIndex]);
|
|
||||||
fileManager.selectFile(fileIndex);
|
|
||||||
core.showMessage('"' + file.title + '" imported successfully from Google Drive.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user