Пример #1
0
def allowed_to_display_some_bucket_info(bucket=None):
    if bucket:
        set_pending_bucket_bucket_in_request(bucket)  # 校验用的
    logined_bucket = get_logined_bucket_by_token()
    if not logined_bucket:
        raw_token = request.values.get("api_token") or request.values.get(
            "token") or ""
        if raw_token:
            endpoint_password = get_env("endpoint_password")
            if endpoint_password and endpoint_password == raw_token:
                return True
    if not logined_bucket:
        logined_bucket = get_logined_bucket()  # try again, by cookie
    if logined_bucket and logined_bucket == bucket:
        return True
    return False
Пример #2
0
def wechat_bind_view():
    if not WECHAT_TOKEN or not wechat_account_url:
        abort(404, "Wechat is not valid in current service")
    else:
        logined_bucket = get_logined_bucket(check=True)
        if not logined_bucket:
            return abort(404, "not login")
        bind_code = get_wechat_bind_code_for_bucket(logined_bucket)
        wechat_user_docs = get_wechat_user_docs_by_bucket(logined_bucket,
                                                          with_name=True)
        response = render_api_template_as_response(
            "wechat_bind.jade",
            wechat_user_docs=wechat_user_docs,
            bind_code=bind_code,
            wechat_account_url=wechat_account_url,
            wechat_account_url2=wechat_account_url2)
        return response
Пример #3
0
def check_should_sync_files_by_web_request():
    bucket = get_logined_bucket() or get_logined_bucket_by_token()
    if not bucket:
        return jsonify([])
    raw_json_data = request.values.get("json")
    if raw_json_data:
        try:
            json_data = json.loads(raw_json_data)
        except:
            json_data = {}
    else:
        json_data = request.json or {}
    to_return = []  # 需要上传的 paths 集合
    if isinstance(json_data, dict):
        tried_times = 0
        for path, version in json_data.items():
            tried_times += 1
            if tried_times >= 1000: break
            if not isinstance(path, string_types) or not isinstance(
                    version, string_types):
                continue
            if path in to_return: continue
            matched_record = get_record_by_path(bucket, path, force_dict=True)
            if not matched_record:
                to_return.append(path)
            else:
                raw_content = matched_record.get(
                    'raw_content') or matched_record.get('content') or ''
                if not raw_content and storage.should_upload_file_by_client(
                        bucket, matched_record):
                    # 服务器上还没有,需要上传的
                    to_return.append(path)
                    continue
                matched_version = matched_record.get("version")
                if matched_version and matched_version == version:
                    continue
                else:
                    to_return.append(path)
    return jsonify(to_return)
Пример #4
0
 def logined_bucket(self):
     # 已登录的 bucket name
     bucket_name = get_logined_bucket(check=True) or ''
     return bucket_name