Ejemplo n.º 1
0
 def deep_clear(di, pan_acc):
     if di:
         if di.isdir == 1:
             # 迭代处理
             size = 50
             l = size
             while l == size:
                 sub_items = DataDao.query_data_item_by_parent_all(di.id, limit=size)
                 l = 0
                 if sub_items:
                     l = len(sub_items)
                     for sub_item in sub_items:
                         deep_clear(sub_item, pan_acc)
                 time.sleep(0.2)
         else:
             fs_id = di.fs_id
             share_log: ShareLogs = DataDao.query_shared_log_by_fs_id(fs_id)
             if share_log:
                 self.clear_share_log(share_log.id)
             transfer_logs = DataDao.query_transfer_logs_by_fs_id(fs_id)
             if transfer_logs:
                 for tl in transfer_logs:
                     CommunityDao.del_transfer_log_by_id(tl.id)
         log.info("deep clear delete data item:{}, filename:{}".format(di.id, di.filename))
         _es_dao_item.delete(di.id)
         DataDao.del_data_item_by_id(di.id)
Ejemplo n.º 2
0
 def update_shared_sub_dir(self, parent_id, params):
     if parent_id:
         CommunityDao.new_community_visible_by_parent(
             parent_id, params['pin'])
         sp: SearchParams = SearchParams.build_params(0, 1000)
         sp.add_must(is_match=False, field="parent", value=parent_id)
         sp.add_must(is_match=False, field="isdir", value=1)
         es_body = build_query_item_es_body(sp)
         es_dao_share().update_by_query(es_body, params)
Ejemplo n.º 3
0
 def update_local_sub_dir(self, parent_id, params):
     if parent_id:
         print("local visible parent_id:", parent_id, ",params:", params)
         CommunityDao.new_local_visible_by_parent(parent_id, params['pin'])
         sp: SearchParams = SearchParams.build_params(0, 1000)
         sp.add_must(is_match=False, field="parent", value=parent_id)
         sp.add_must(is_match=False, field="isdir", value=0)
         es_body = build_query_item_es_body(sp)
         es_dao_local().update_by_query(es_body, params)
Ejemplo n.º 4
0
        def deep_clear(di: CommunityDataItem):
            if di:
                if di.isdir == 1:
                    # 迭代处理
                    size = 50
                    l = size
                    while l == size:
                        sub_items = CommunityDao.query_community_item_by_parent_all(di.fs_id, limit=size)
                        l = 0
                        if sub_items:
                            l = len(sub_items)
                            for sub_item in sub_items:
                                deep_clear(sub_item)
                        time.sleep(0.2)

                es_dao_share().delete(di.id)
                CommunityDao.del_community_item_by_id(di.id)
Ejemplo n.º 5
0
 def clear_share_log(self, share_log_id):
     transfer_logs = CommunityDao.query_transfer_logs_by_share_log_id(share_log_id)
     pan_map_cache = {}
     if transfer_logs:
         tl: TransferLogs = None
         for tl in transfer_logs:
             pan_id = tl.pan_account_id
             if pan_id not in pan_map_cache:
                 pan_acc: PanAccounts = DataDao.pan_account_by_id(pan_id)
                 pan_map_cache[pan_id] = pan_acc
             pan_acc = pan_map_cache[pan_id]
             restapi.del_file(pan_acc.access_token, tl.path)
             di: DataItem = DataDao.query_data_item_by_fs_id(tl.fs_id)
             if di:
                 self.es_dao_item.delete(di.id)
                 DataDao.del_data_item_by_id(di.id)
             CommunityDao.del_transfer_log_by_id(tl.id)
     CommunityDao.del_share_log_by_id(share_log_id)
Ejemplo n.º 6
0
    def get(self):
        path = self.request.path
        if path.endswith("/init"):
            tag_list = open_service.load_tags()
            # print('headers:', self.request.headers)
            bd_auth_query_path = bd_auth_path(skip_login=True)
            auth_dns_domain = "{}://{}".format(PAN_SERVICE['protocol'], PAN_SERVICE['auth_dns_domain'])
            bd_user_point = "/rest/2.0/passport/users/getInfo"
            pan_url = "/oauth/2.0/token"
            auth_point = "/oauth/2.0/{}".format(bd_auth_query_path)
            auth_params = {'grant_type': 'authorization_code', 'client_id': PAN_SERVICE["client_id"],
                           'redirect_uri': 'oob', 'client_secret': PAN_SERVICE["client_secret"]}
            rs = {'data': tag_list, 'contact': DEFAULT_CONTACT_QR_URI, 'auth': {
                'auth_dns_domain': auth_dns_domain,
                'bd_user_point': bd_user_point, 'bdauth': auth_point,
                  'auth_params': auth_params, 'auth_point': pan_url}}
            self.to_write_json(rs)
        elif path.endswith("/loops"):
            rs = CommunityDao.loop_ad_tasks()
            self.to_write_json(rs)
        elif path.endswith("/se"):
            kw = self.get_argument("kw")
            tag = self.get_argument("tag", None)
            path_tag = self.get_argument("path_tag", None)
            source = self.get_argument("source", "")
            page = self.get_argument("page", "0")
            # print("kw:", kw)
            # print("source:", source)
            rs = open_service.search(path_tag, tag, kw, source, page)
            self.to_write_json(rs)
        elif path.endswith("/shared"):
            fs_id = self.get_argument("fs_id")
            # rs = open_service.fetch_shared(fs_id)
            rs = open_service.fetch_shared_skip_visible(fs_id)

            self.to_write_json(rs)
        elif path.endswith("/cfg"):
            platform = self.get_argument("platform", "win32")
            logger.info("cfg platform:{}".format(platform))
            if platform.lower().find("darwin") < 0:
                platform = "win32"
            self.release_db = False
            rs = open_service.checkout_app_cfg(platform)
            self.to_write_json(rs)
        elif path.endswith("/update_cfg"):
            rs = open_service.sync_cfg()
            self.to_write_json(rs)
        elif path.endswith("/update_tags"):
            rs = open_service.sync_tags()
            self.to_write_json(rs)
        else:
            self.to_write_json({})
Ejemplo n.º 7
0
 def clear_all_expired_share_log(self):
     item_list = CommunityDao.query_share_logs_by_hours(-48, 0, 50)
     sl: ShareLogs = None
     for sl in item_list:
         self.clear_share_log(sl.id)
Ejemplo n.º 8
0
 def update_shared_item(self, doc_id, params):
     if doc_id:
         CommunityDao.new_community_visible(doc_id, params['pin'])
         es_dao_share().update_fields(doc_id, **params)
Ejemplo n.º 9
0
 def update_local_item(self, doc_id, params):
     if doc_id:
         CommunityDao.new_local_visible(doc_id, params['pin'])
         es_dao_local().update_fields(doc_id, **params)
Ejemplo n.º 10
0
    def get(self):
        path = self.request.path
        if path.endswith("/init"):
            pan_acc_list = CommunityDao.pan_account_list(self.request.user_id)
            for pan in pan_acc_list:
                if compare_dt_by_now(pan['expires_at']) <= 0:
                    pan['expired'] = 1
                else:
                    pan['expired'] = 0
            params = {'items': pan_acc_list}
            # print("params:", params)
            self.render('panmanage.html', **params)
        elif path.endswith("/ftree"):
            pan_id = self.get_argument("panid", "0")
            params = {'pan_id': pan_id}
            self.render('mantree.html', **params)
        elif path.endswith("/fload"):
            # pan_id = self.get_argument("panid", "0")
            source = self.get_argument("source", "")
            node_id = self.get_argument("id")
            parent_path = self.get_argument("path")
            # if not parent_path.endswith("/"):
            #     parent_path = "%s/" % parent_path

            # print("user_payload:", self.user_payload)
            params = []
            if not source or "local" == source:
                # print("fload node_id:", node_id, ", pan_id:", pan_id, ", source:", source)
                if not '#' == node_id:
                    node_id_val = decrypt_id(node_id)
                    parent_id = int(node_id_val)
                    params = mpan_service.query_file_list(parent_id)
                else:
                    params = mpan_service.fetch_root_item_by_user(self.user_id)

                # pan_id = int(pan_id)
                # print("parent_id, pan_id:", parent_id, pan_id)
                # params = mpan_service.query_file_list(parent_id, pan_id)
            if not source or "shared" == source:
                # print("fload node_id:", node_id, ",fs_id:", self.get_argument("fs_id", "0"), ", source:", source)
                shared_params = []
                if not '#' == node_id:
                    parent_id = int(self.get_argument("fs_id", "0"))
                    if parent_id == 0:
                        shared_params = mpan_service.query_share_list(None)
                    else:
                        shared_params = mpan_service.query_share_list(
                            parent_id)
                else:
                    node_param = {
                        "id": "s_0",
                        "text": "外部分享(shared)",
                        "data": {
                            "path": "/",
                            "fs_id": 0,
                            "server_ctime": 0,
                            "isdir": 1,
                            "source": "shared",
                            "_id": 0,
                            "pin": 0
                        },
                        "children": True,
                        "icon": "folder"
                    }

                    shared_params = [node_param]
                if shared_params:
                    if not params:
                        params = shared_params
                    else:
                        params = params + shared_params

            self.to_write_json(params)
        elif path.endswith("/show"):
            source = self.get_argument("source", "")
            parent = self.get_argument("parent", "")
            node_id = self.get_argument("id")
            logger.info("source:{},parent:{},node_id:{}".format(
                source, parent, node_id))
            if "local" == source:
                if parent:
                    mpan_service.update_local_sub_dir(parent, {'pin': 1})
                else:
                    mpan_service.update_local_item(node_id, {'pin': 1})
            else:
                if parent:
                    mpan_service.update_shared_sub_dir(parent, {'pin': 1})
                else:
                    mpan_service.update_shared_item(node_id, {'pin': 1})
            self.to_write_json({})
        elif path.endswith("/hide"):
            source = self.get_argument("source", "")
            parent = self.get_argument("parent", "")
            node_fuzzy_id = self.get_argument("id")
            node_id = decrypt_id(node_fuzzy_id)
            logger.info("hide source:{},parent:{},node_id:{}".format(
                source, parent, node_id))
            if "local" == source:
                if parent:
                    mpan_service.update_local_sub_dir(parent, {'pin': 0})
                else:
                    mpan_service.update_local_item(node_id, {'pin': 0})
            else:
                if parent:
                    mpan_service.update_shared_sub_dir(parent, {'pin': 0})
                else:
                    mpan_service.update_shared_item(node_id, {'pin': 0})

            self.to_write_json({})
        elif path.endswith("/clear"):
            item_fuzzy_id = self.get_argument("id", None)
            item_id = int(decrypt_id(item_fuzzy_id))
            # pan_id = int(self.get_argument("panid", "0"))
            source = self.get_argument("source", "")
            rs = sync_pan_service.clear(item_id, source)
            self.to_write_json(rs)
        elif path.endswith("/clearbyid"):
            item_id = int(self.get_argument("id", "0"))
            # pan_id = int(self.get_argument("panid", "0"))
            source = self.get_argument("source", "")
            logger.info("clearbyid item_id:{}, source:{}".format(
                item_id, source))
            rs = sync_pan_service.clear(item_id, source)
            logger.info("clearbyid rs:{}".format(rs))
            self.to_write_json(rs)
        elif path.endswith("/rename"):
            item_fuzzy_id = self.get_argument("itemid", None)
            item_id = int(decrypt_id(item_fuzzy_id))
            old_name = self.get_argument("old_name", "")
            alias_name = self.get_argument("alias_name", "")
            source = self.get_argument("source", "")
            result = sync_pan_service.rename(item_id, old_name, alias_name,
                                             source)
            self.to_write_json(result)

        elif path.endswith("/free"):
            item_fuzzy_id = self.get_argument("itemid", None)
            item_id = int(decrypt_id(item_fuzzy_id))
            source = self.get_argument("source", "")
            desc = self.get_argument("desc", "")
            tags = self.get_argument("tags", "")
            if tags:
                tags = tags.split(',')
            else:
                tags = []
            if "local" != source:
                self.to_write_json({"state": -1})
            else:
                rs = mpan_service.free(self.user_id, item_id, desc, tags)
                self.to_write_json(rs)
        elif path.endswith("/unfree"):
            item_fuzzy_id = self.get_argument("itemid", None)
            item_id = int(decrypt_id(item_fuzzy_id))
            fs_id = self.get_argument("fs_id", "")
            source = self.get_argument("source", "")
            tags = self.get_argument("tags", "")
            if tags:
                tags = tags.split(',')
            else:
                tags = []
            if "local" != source:
                self.to_write_json({"state": -1})
            else:
                rs = mpan_service.unfree(self.user_id, item_id, fs_id, tags)
                self.to_write_json(rs)

        elif path.endswith("/fparts"):
            # pan_id = self.get_argument("id", "0")
            # print("hello fparts!")
            item_list = CommunityDao.query_share_logs_by_hours(-24, 0, 100)
            # print("item_list:", item_list)
            # for item in item_list:
            #     print("item:", item.filename)
            params = {"list": item_list}
            # print("params:", params)
            self.render('fparts.html', **params)
        elif path.endswith("/clearshare"):
            share_item_id = int(self.get_argument("id", "0"))
            sync_pan_service.clear_share_log(share_item_id)
            self.to_write_json({'state': 0})
        elif path.endswith("/pan_acc_list"):
            need_renew_pan_acc = pan_service.all_pan_acc_list_by_user(
                self.user_id)
            result = {"result": "ok", "pan_acc_list": need_renew_pan_acc}
            # print("result:", result)
            self.to_write_json(result)
        elif path.endswith("/batchupdate"):
            pan_id = self.get_argument("panid", "0")
            pan_acc = pan_service.get_pan_account(pan_id, self.user_id)
            cls = [
                fn for fn in DataItem.field_names() if fn not in
                ["id", "created_at", "updated_at", "pan_acc", "account_id"]
            ]
            params = {
                "pan_id": int(pan_id),
                "name": pan_acc.name,
                "columns": cls
            }
            self.render('batchupdate.html', **params)
        elif path.endswith("/batchupdatedo"):
            pan_id = self.get_argument("panid", "0")
            cname = self.get_argument("cname")
            datas = self.get_argument("datas", "")
            lines = datas.split("\n")
            kv = {}
            cnt = 0
            for line in lines:
                vals = line.split("\t")
                if len(vals) == 2:
                    cnt = cnt + 1
                    kv[vals[0]] = vals[1]
                    DataDao.update_data_item(int(vals[0]),
                                             {cname: vals[1].strip()})
                    # print("update id:", vals[0], ",", cname, "=", vals[1])
            rs = {
                "state": 0,
                "cnt": cnt,
                "lines_cnt": len(lines),
                "cname": cname
            }
            # print("kv:", kv)
            # print("cnt:", cnt, ",lines cnt:", len(lines), "cname:", cname, "pan_id:", pan_id)
            self.to_write_json(rs)
        else:
            self.to_write_json({})