diff --git a/js/app.js b/js/app.js index 377e69a..65103f0 100644 --- a/js/app.js +++ b/js/app.js @@ -517,42 +517,42 @@ items[key] = value; } } - var content = JSON.stringify(items); + var gistFiles = gist.json2gist(items); $scope.gistBackupLoading = true; - gist.backupMySettings2Gist(content).then(function(){ + gist.backupMySettings2Gist(gistFiles).then(function(){ Notification.clearAll(); - Notification.success("成功备份歌单到Gist"); + Notification.success("成功导出歌单到Gist"); $scope.gistBackupLoading = false; },function(err){ Notification.clearAll(); - Notification.warning("备份歌单失败,检查后重试"); + Notification.warning("导出歌单失败,检查后重试"); $scope.gistBackupLoading = false; }); - Notification({message: "正在备份歌单到Gist...", delay: null}); + Notification({message: "正在导出歌单到Gist...", delay: null}); } $scope.gistRestoreLoading = false; $scope.importMySettingsFromGist = function(){ $scope.gistRestoreLoading = true; gist.importMySettingsFromGist().then(function(raw){ - var data = JSON.parse(raw); + var data = gist.gist2json(raw); for ( var key in data) { var value = data[key]; localStorage.setObject(key, value); } Notification.clearAll(); - Notification.success("恢复我的歌单成功"); + Notification.success("导入歌单成功"); $scope.gistRestoreLoading = false; },function(err){ Notification.clearAll(); if(err==404){ Notification.warning("未找到备份歌单,请先备份"); }else{ - Notification.warning("恢复歌单失败,检查后重试"); + Notification.warning("导入歌单失败,检查后重试"); } $scope.gistRestoreLoading = false; }) - Notification({message: "正在从Gist恢复我的歌单...", delay: null}); + Notification({message: "正在从Gist导入歌单...", delay: null}); } diff --git a/js/github.js b/js/github.js index 2623c76..69bc30d 100644 --- a/js/github.js +++ b/js/github.js @@ -35,7 +35,37 @@ ngGithub.provider('gist', { return localStorage.getObject("gistid"); } - function backup(filecontent) { + function json2gist(jsonObject) { + var result = {}; + result['listen1_backup.json'] = {content: JSON.stringify(jsonObject)}; + //var markdown = '# My Listen1 Playlists\n'; + var playlistIds = jsonObject['playerlists']; + for(var i=0; i
'; + var title = playlist.info.title; + var tableHeader = '\n| 音乐标题 | 歌手 | 专辑 |\n'; + tableHeader += '| --- | --- | --- |\n'; + var tableBody = ''; + for(var j=0; j

\n' + tableHeader + tableBody +'

'; + var filename = 'listen1_'+playlistId + '.md'; + result[filename] = {content: content}; + } + + return result; + } + + function gist2json(gistFiles) { + var jsonString = gistFiles['listen1_backup.json'].content; + return JSON.parse(jsonString); + } + + function backup(files) { var deferred = $q.defer(); var gistId = _getGistId(); var method = ''; @@ -55,11 +85,7 @@ ngGithub.provider('gist', { data:{ "description": "updated by Listen1(http://listen1.github.io/listen1/) at " + new Date().toLocaleString(), "public": false, - "files": { - "listen1_backup.json": { - "content": filecontent - } - } + "files": files } }).then(function(res) { var newGistId = res.data.id; @@ -78,8 +104,8 @@ ngGithub.provider('gist', { url:apiUrl + '/' + _getGistId(), }).then(function(res) { try{ - var backupcontent = res.data.files["listen1_backup.json"].content; - deferred.resolve(backupcontent); + var files = res.data.files + deferred.resolve(files); }catch(e){ deferred.reject(404); } @@ -89,6 +115,8 @@ ngGithub.provider('gist', { return deferred.promise; } var gistApi = { + "gist2json": gist2json, + "json2gist": json2gist, "backupMySettings2Gist": backup, "importMySettingsFromGist": restore, }; diff --git a/listen1.html b/listen1.html index 010ed4f..337e408 100644 --- a/listen1.html +++ b/listen1.html @@ -279,21 +279,21 @@
豆瓣:
豆瓣:
--> -
数据备份
+
歌单导出

重装插件或清除缓存数据会导致我的歌单数据丢失,强烈建议在这些操作前,备份我的歌单。

- - + +
-
数据恢复
+
歌单导入

选择备份文件,恢复我的歌单。注意:恢复我的歌单会覆盖现有的歌单。

- +
连接到 Github.com