坚果云使用控制台粉碎回收站已删目录和文件

Published: Tags: JAVASCRIPT

引入JQUERY框架简化请求

var jquery = document.createElement('script');
jquery.src = '//libs.baidu.com/jquery/2.0.0/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(jquery);

完成JQUERY载入后再执行

var href_string = window.location.href.split('#')[1].split('/');
var query_param = '?sndId='+href_string[2]+'&sndMagic='+href_string[3]+'&_='+Date.parse(new Date());

var list_trash = '//www.jianguoyun.com/d/ajax/listTrashDir/';
var purge_trash = '//www.jianguoyun.com/d/ajax/purge'+query_param;

function ergodic(list_path='') {
    $.ajax({
        url: list_trash+list_path+query_param,
        dataType: 'json', async: false,
        success: function(resp) {
            var list = resp.contents;
            
            var pt_param = {}; //被粉碎的列表
            for (var x=0; x<list.length; x++) {
                var listpath = (resp.path+'/'+list[x].name).replace(/^\/+/,'');
                
                if (list[x].isdir==true && list[x].isdel==false) {
                    ergodic(encodeURIComponent(listpath));
                    
                } else if (list[x].isdel==true) {
                    var body_key = '/' + listpath;
                    var body_value = list[x].version+' '+(list[x].isdir?'DIRECTORY':'FILE');
                    pt_param[body_key] = body_value; console.log(body_key+' -> '+body_value);
                    
                    if (Object.keys(pt_param).length>=30) {
                        $.post(purge_trash, pt_param); pt_param = {};
                    } //防止列表过大,导致提交POST参数失败
                }
            }
            if (Object.keys(pt_param).length>0) $.post(purge_trash, pt_param);
        }
    });
}
ergodic();