Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
add album
Browse files Browse the repository at this point in the history
  • Loading branch information
acgotaku committed Nov 14, 2015
1 parent c91246a commit 844b82a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 153 deletions.
2 changes: 1 addition & 1 deletion chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ if(previousVersion == "" || previousVersion != manifest.version){
var opt={
type: "basic",
title: "更新",
message: "百度网盘助手更新到" +manifest.version + "版本啦~\n此次更新修复BUG~",
message: "百度网盘助手更新到" +manifest.version + "版本啦~\n此次更新增加专辑页面的导出~",
iconUrl: "images/icon.jpg"
}
var id= new Date().getTime().toString();
Expand Down
3 changes: 2 additions & 1 deletion chrome/css/setting.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#setting_div{
#setting_div,#download_ui{
border: 3px solid #999;
background: #FFF;
width: 568px;
box-shadow: 0 0 9px #999;
}

#setting_div_table input{
text-indent: 10px;
border: 1px solid #C6C6C6;
Expand Down
183 changes: 37 additions & 146 deletions chrome/js/album.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,132 +9,67 @@ var ALBUM =(function(){
*/
var setMessage =CORE.setMessage;
var HttpSend= CONNECT.HttpSend;
//两种导出模式 RPC模式 和 TXT模式
var MODE="RPC";
var RPC_PATH="http://localhost:6800/jsonrpc";
var FileList=null;
return {
//绑定事件
init:function(){
var menu=CORE.addMenu.init("album");
var self=this;
menu.find(".rpc_export_list").on("click",function(){
self.getALLFileList();
CORE.requestCookies([{"site": "http://pan.baidu.com/", "name": "BDUSS"},{"site": "http://pcs.baidu.com/", "name": "pcsett"}]);
menu.on("click",".rpc_export_list",function(){
MODE="RPC";
var RPC_PATH=$(this).attr('data-id');
RPC_PATH=$(this).attr('data-id');
self.getShareFile();

});
menu.find("#aria2_download").on("click",function(){
menu.on("click","#aria2_download",function(){
MODE="TXT";
CORE.dataBox.init("share").show();
self.getShareFile();
});
setMessage("初始化成功!", "MODE_SUCCESS");
},
//获得选中的文件
getShareFile:function(){
var self = this;
if (yunData.SHAREPAGETYPE=="single_file_page") {
var fid_list = 'fid_list=' + JSON.stringify([yunData.FS_ID]);
self.set_share_data(yunData, fid_list);
} else {
var File = require("common:widget/data-center/data-center.js");
var Filename = File.get("selectedItemList");
var file_info = File.get("selectedList");
if (file_info.length == 0) {
setMessage("先选择一下你要下载的文件哦", "MODE_CAUTION");
return;
}
for (var i = 0; i < Filename.length; i++) {
if (Filename[i].attr("data-extname") != "dir") {
var fid_list = 'fid_list=' + JSON.stringify([Filename[i].attr("data-id")]);
self.setFileData( fid_list);
}else{
self.getShareFold(Filename[i].attr("data-id"));

}
}
}
},
//设置要请求文件的POST数据
setFileData:function(fid_list){
var data = "encrypt=0&product=share&uk="+yunData.SHARE_UK+"&primaryid="+yunData.SHARE_ID+"&"+fid_list;
if(yunData.SHARE_PUBLIC == 0){
var Service = require("common:widget/commonService/commonService.js");
data = data+"&extra="+encodeURIComponent(JSON.stringify({sekey:Service.getCookie("BDCLND")}));
}
this.getFilemetas(data);
},
//获取要下载的文件夹
getShareFold:function(fs_id){
var self=this;
var API = (require("common:widget/restApi/restApi.js"),require("common:widget/hash/hash.js"));
var path_head=yunData.PATH.slice(0,yunData.PATH.lastIndexOf("/"));
var path=API.get("path");
if(path == "/"|| path == null){
path=yunData.PATH;
}else{
path=path_head+path;
}
var parameter = {'url': "//"+window.location.host+"/share/list?dir="+encodeURIComponent(path)+"&bdstoken="+yunData.MYBDSTOKEN+"&uk="+yunData.SHARE_UK+"&shareid="+yunData.SHARE_ID+"&channel=chunlei&clienttype=0&web=1", 'dataType': 'json', type: 'GET'};
HttpSend(parameter)
//获得全部文件的信息
getALLFileList:function(){
var album_id=(disk.ui.album.albuminfo && disk.ui.album.albuminfo.album_id) || disk.getParam("album_id") ;
var query_uk= (disk.ui.album.uinfo && disk.ui.album.uinfo.uk) || disk.getParam("uk") || disk.getParam("query_uk") ;
var url = "//"+window.location.host+disk.ui.album.RestAPI.listFile + "?album_id=" + album_id+ "&query_uk=" + query_uk + "&start=" + ($(".page-input").eq(0).val() - 1) * 60 + "&limit=" + 60;
var parameter = {'url': url, 'dataType': 'json', type: 'GET'};
CONNECT.HttpSend(parameter)
.done(function(json, textStatus, jqXHR) {
setMessage("获取共享列表成功!", "MODE_SUCCESS");
var array=json.list;
console.log(json);
for(var i=0;i<array.length;i++){
if(array[i].fs_id == fs_id ||API.get("path")=="/" || API.get("path") == null){
console.log(array[i]);
if(array[i].isdir == 1){
self.getRecursiveFold(array[i].path);
}else{
var fid_list = 'fid_list=' + JSON.stringify([array[i].fs_id]);
self.setFileData(fid_list);
}
}
}
setMessage("初始化成功!", "MODE_SUCCESS");
FileList=json.list;
})
.fail(function(jqXHR, textStatus, errorThrown) {
setMessage("获取共享列表失败!", "MODE_FAILURE");
setMessage("获取全部列表失败!", "MODE_FAILURE");
console.log(jqXHR);
});
},
//递归下载
getRecursiveFold:function(path){
var self=this;
var time=0;
var delay=parseInt(localStorage.getItem("rpc_delay"))||0;
var parameter = {'url': "//"+window.location.host+"/share/list?dir="+encodeURIComponent(path)+"&bdstoken="+yunData.MYBDSTOKEN+"&uk="+yunData.SHARE_UK+"&shareid="+yunData.SHARE_ID+"&channel=chunlei&clienttype=0&web=1", 'dataType': 'json', type: 'GET'};
HttpSend(parameter)
.done(function(json, textStatus, jqXHR) {
var array=json.list;
console.log(json);
for(var i=0;i<array.length;i++){
time=time+delay;
if(array[i].isdir == 1){
delayLoopList(array[i].path,time);
}else{
delayLoopFile(array[i].fs_id,time);
}
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
SetMessage("获取List失败!", "MODE_FAILURE");
console.log(textStatus);
});
function delayLoopList(path,time){
setTimeout(function(){
self.getRecursiveFold(path);
},time);
}
function delayLoopFile(fs_id,time){
setTimeout(function(){
var fid_list = 'fid_list=' + JSON.stringify([fs_id]);
self.setFileData(fid_list);

},time);
}
//获得选中的文件
getShareFile:function(){
var self = this;
var file_info = $("#fileItems .on");
if (file_info.length == 0) {
setMessage("先选择一下你要下载的文件哦", "MODE_CAUTION");
return;
}
var file_list=[];
for(var i = 0; i < file_info.length; i++){
var num = file_info.eq(0).attr("_position");
file_list.push({"name":FileList[num].server_filename,"link":FileList[num].dlink});
}
if(MODE =="TXT"){
CORE.dataBox.fillData(file_list);
}else{
var token=CORE.parseAuth(RPC_PATH)[0];
var rpc_list =CORE.aria2Data(file_list,token);
self.generateParameter(rpc_list);
}
},

alertDialog:function(json, params){
var self = this;
var id = json.request_id;
Expand Down Expand Up @@ -195,51 +130,7 @@ var ALBUM =(function(){
div.remove();
});
},
//根据文件路径获取文件的信息
getFilemetas:function(data){
var self = this;
var download = "//" + window.location.host + "/api/sharedownload?channel=chunlei&clienttype=0&web=1&app_id="+yunData.FILEINFO[0].app_id + "&timestamp=" + yunData.TIMESTAMP + "&sign=" + yunData.SIGN + "&bdstoken=" + yunData.MYBDSTOKEN;
var pic="//" + window.location.host + "/api/getcaptcha?prod=share&channel=chunlei&clienttype=0&web=1&bdstoken="+yunData.MYBDSTOKEN+"&app_id="+yunData.FILEINFO[0].app_id;
var parameter = {'url': download, 'dataType': 'json', type: 'POST', 'data': data};
HttpSend(parameter)
.done(function(json, textStatus, jqXHR) {
if (json.errno == -20) {
HttpSend({'url':pic,'dataType': 'json',type: 'GET'})
.done(function(json, textStatus, jqXHR){
if (data.indexOf("input") != -1) {
json.auth = true;
}
self.alertDialog(json, data);
setMessage("请输入验证码,以便继续下载", "MODE_CAUTION");
})
.fail(function(json, textStatus, jqXHR){
setMessage("获取验证码失败?", "MODE_FAILURE");
});

} else if (json.errno == 0) {
var file_list = [];
for(var i=0;i<json.list.length;i++){
var list=json.list[i];
file_list.push({"name": list.path.slice(yunData.PATH.lastIndexOf("/")+1,list.path.length), "link": list.dlink});
}
if(MODE =="TXT"){
CORE.dataBox.fillData(file_list);
}else{
var token=CORE.parseAuth(RPC_PATH)[0];
var rpc_list =CORE.aria2Data(file_list,token);
console.log(rpc_list);
self.generateParameter(rpc_list);
}
} else {
console.log(json);
setMessage("出现异常!", "MODE_FAILURE");
}

})
.fail(function(jqXHR, textStatus, errorThrown) {
setMessage("获取地址失败?", "MODE_FAILURE");
});
},
//生成请求参数 发送给后台 进行 http请求
generateParameter:function(rpc_list){
var paths=CORE.parseAuth(RPC_PATH);
Expand Down
1 change: 1 addition & 0 deletions chrome/js/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var port=null;
method:method,
data: data
});
console.log(data);
this.listenBackground(port);

},
Expand Down
6 changes: 3 additions & 3 deletions chrome/js/core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var CORE=(function(){
const defaultUA ="netdisk;5.3.4.5;PC;PC-Windows;5.1.2600;WindowsBaiduYunGuanJia";
const defaultreferer="http://pan.baidu.com/disk/home";
const version = "0.5.4";
const update_date = "2015/11/06";
const version = "0.5.5";
const update_date = "2015/11/14";
var cookies=null;
return {
init:function(){
Expand Down Expand Up @@ -142,7 +142,7 @@ var CORE=(function(){
//convert_btn.addClass("new-dbtn").append('<em class="global-icon-download"></em><b>批量转存</b>');
$('span a[class="new-dbtn"]').parent().prepend(aria2_btn);
}else if(type == "album"){
aria2_btn.addClass("new-dbtn").append('<em class="global-icon-download"></em><b>导出下载</b>');
aria2_btn.addClass("new-dbtn").append('<em class="quick_save_icon"></em><b>导出下载</b>');
$("#albumFileSaveKey").parent().prepend(aria2_btn);
}
aria2_btn.on("mouseover",function(){
Expand Down
4 changes: 2 additions & 2 deletions chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"128": "images/logo128.png"
},
"externally_connectable": {
"matches": ["*://pan.baidu.com/s/*", "*://yun.baidu.com/s/*", "*://pan.baidu.com/disk/home*", "*://yun.baidu.com/share/link*", "*://pan.baidu.com/share/link*", "*://yun.baidu.com/disk/home*"]
"matches": ["*://pan.baidu.com/s/*", "*://yun.baidu.com/s/*", "*://pan.baidu.com/disk/home*", "*://yun.baidu.com/share/link*", "*://pan.baidu.com/share/link*", "*://yun.baidu.com/disk/home*", "*://pan.baidu.com/pcloud/album/info*", "*://yun.baidu.com/pcloud/album/info*"]
},
"web_accessible_resources": [
"js/core.js",
Expand All @@ -30,5 +30,5 @@
"manifest_version": 2,
"permissions": [ "cookies", "tabs", "notifications", "*://*.baidu.com/*", "activeTab", "contextMenus"],
"name": "__MSG_appName__",
"version": "0.5.4"
"version": "0.5.5"
}

0 comments on commit 844b82a

Please sign in to comment.