Exemple #1
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)
Exemple #2
0
def update_es_community_by_visible():
    offset = 0
    size = 200
    cdi: CommunityVisible = None
    ln = size
    dog = 1000000
    while ln == size and dog > 0:
        dog = dog - 1
        ms: ModelSelect = CommunityVisible.select().offset(offset).limit(size)
        ln = len(ms)
        for cdi in ms:
            # mpan_service.update_shared_item(cdi.id, {'pin': 1})
            es_dao_share().update_fields(cdi.id, **{'pin': 1})
        print("dog:", dog, ",offset:", offset)
        offset = offset + size
        time.sleep(1)
Exemple #3
0
 def sync_community_item_to_es(cls, data_item: CommunityDataItem, source):
     es_item_path = data_item.path
     pos = 0
     if es_item_path.endswith(data_item.filename):
         # print("new path:", data_item.id)
         es_item_path = es_item_path[:-len(data_item.filename)]
         _p = data_item.path.strip('/')
         if _p:
             pos = len(_p.split('/'))
     body = utils_es.build_es_item_json_body(data_item.id,
                                             data_item.category,
                                             data_item.isdir,
                                             data_item.pin,
                                             data_item.fs_id,
                                             data_item.size,
                                             data_item.account_id,
                                             data_item.filename,
                                             es_item_path,
                                             data_item.server_ctime,
                                             data_item.updated_at,
                                             data_item.created_at,
                                             data_item.parent,
                                             data_item.sourceid,
                                             data_item.sourceuid,
                                             source,
                                             pos=pos)
     # es = es_dao_dir()
     es = es_dao_share()
     # print("body:", body)
     es.index(data_item.id, body)
Exemple #4
0
 def query_shared_file_list(self, parent_id, account_id):
     params = []
     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="account", value=account_id)
     es_body = build_query_item_es_body(sp)
     # es_result = es_dao_dir().es_search_exec(es_body)
     es_result = es_dao_share().es_search_exec(es_body)
     hits_rs = es_result["hits"]
     total = hits_rs["total"]
     logger.info("files es total:{}".format(total))
     for _s in hits_rs["hits"]:
         params.append({
             "id": _s["_source"]["fs_id"],
             "text": _s["_source"]["filename"],
             "data": {
                 "path": _s["_source"]["path"],
                 "server_ctime": _s["_source"].get("server_ctime", 0),
                 "isdir": _s["_source"]["isdir"],
                 "source": "shared"
             },
             "children": True,
             "icon": "folder"
         })
     return params
Exemple #5
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)
Exemple #6
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)
Exemple #7
0
    def query_share_list(self, parent_item_id):
        params = []
        sp: SearchParams = SearchParams.build_params(0, 1000)
        # sp.add_must(is_match=False, field="path", value=parent_path)
        if parent_item_id:
            sp.add_must(is_match=False, field="parent", value=parent_item_id)
        else:
            sp.add_must(is_match=False, field="pos", value=SHARE_ES_TOP_POS)
            sp.add_must(is_match=False, field="parent", value=0)
        # sp.add_must(is_match=False, field="isdir", value=0)
        es_body = build_query_item_es_body(sp)
        print("query_share_list es_body:", es_body)
        es_result = es_dao_share().es_search_exec(es_body)
        hits_rs = es_result["hits"]
        total = hits_rs["total"]
        print("query_share_list files es total:", total)
        for _s in hits_rs["hits"]:
            icon_val = "jstree-file"
            fn_name = _s["_source"]["filename"]
            txt = fn_name
            aliasname = ''
            if "aliasname" in _s["_source"] and _s["_source"]["aliasname"]:
                aliasname = _s["_source"]["aliasname"]
            if aliasname:
                fn_name, extname = split_filename(fn_name)
                alias_fn, alias_extname = split_filename(aliasname)
                if not alias_extname:
                    alias_extname = extname
                aliasname = "{}{}".format(
                    alias_fn,
                    "." + alias_extname if alias_extname.strip() else "")
                txt = "[{}]{}".format(fn_name, aliasname)

            has_children = False
            a_attr = {}
            if _s["_source"]["isdir"] == 1:
                # icon_val = "jstree-folder"
                icon_val = "folder"
                has_children = True
                if _s["_source"]["pin"] == 1:
                    a_attr = {'style': 'color:red'}
            else:
                f_type = guess_file_type(txt)
                if f_type:
                    icon_val = "jstree-file file-%s" % f_type
            node_text = txt
            format_size = scale_size(_s["_source"]["size"])
            if format_size:
                if _s["_source"]["isdir"] == 1:
                    node_text = "{}(shared)({})".format(node_text, format_size)
                else:
                    node_text = "{}({})".format(node_text, format_size)
            node_param = {
                "id": "s_%s" % _s["_source"]["id"],
                "text": node_text,
                "data": {
                    "path": _s["_source"]["path"],
                    "fs_id": _s["_source"]["fs_id"],
                    "server_ctime": _s["_source"].get("server_ctime", 0),
                    "isdir": _s["_source"]["isdir"],
                    "source": _s["_source"]["source"],
                    "pin": _s["_source"]["pin"],
                    "_id": _s["_source"]["id"],
                    "sourceid": _s["_source"]["sourceid"],
                    "p_id": _s["_source"]["fs_id"]
                },
                "children": has_children,
                "icon": icon_val
            }
            if a_attr:
                node_param['a_attr'] = a_attr
            params.append(node_param)
        return params
Exemple #8
0
 def update_es_by_community_item(cls, doc_id, params):
     es = es_dao_share()
     es.update_fields(doc_id, **params)