Giter Site home page Giter Site logo

feishu_minutes's Issues

```python

    def upload_blocks(self):
        with open(self.file_path, "rb") as f:
            f.seek(0)
            block_count = (self.file_size + self.block_size - 1) // self.block_size
            with ThreadPoolExecutor(max_workers=6) as executor:
                completed_threads = []
                with tqdm(total=block_count, unit="block") as progress_bar:
                    for i in range(block_count):
                        block_data = f.read(self.block_size)  # 要求读取的字节数
                        block_size = len(block_data)  # 实际读取的字节数
                        checksum = zlib.adler32(block_data) % (10**10)
                        upload_url = f"https://internal-api-space.feishu.cn/space/api/box/stream/upload/block?upload_id={self.upload_id}&seq={i}&size={block_size}&checksum={checksum}"
                        thread = executor.submit(
                            requests.post,
                            upload_url,
                            headers=self.headers,
                            proxies=proxies,
                            data=block_data,
                        )
                        completed_threads.append(thread)
                    for thread in as_completed(completed_threads):
                        progress_bar.update(1)

其中有这样一行代码:

checksum = zlib.adler32(block_data) % (10**10)

这里adler32函数返回值是一个32位无符号整数,为什么还要取模10的10次方呢?
2^32=4294967296,是小于10^10的,这样的取模结果始终为0。

最初由 @jcfangc#5 发布

我昨天脑子肯定是短路了,取模是取余数,不是取商,对10^10取模应该就是32位函数值本身。

取模意义是什么?

    def upload_blocks(self):
        with open(self.file_path, "rb") as f:
            f.seek(0)
            block_count = (self.file_size + self.block_size - 1) // self.block_size
            with ThreadPoolExecutor(max_workers=6) as executor:
                completed_threads = []
                with tqdm(total=block_count, unit="block") as progress_bar:
                    for i in range(block_count):
                        block_data = f.read(self.block_size)  # 要求读取的字节数
                        block_size = len(block_data)  # 实际读取的字节数
                        checksum = zlib.adler32(block_data) % (10**10)
                        upload_url = f"https://internal-api-space.feishu.cn/space/api/box/stream/upload/block?upload_id={self.upload_id}&seq={i}&size={block_size}&checksum={checksum}"
                        thread = executor.submit(
                            requests.post,
                            upload_url,
                            headers=self.headers,
                            proxies=proxies,
                            data=block_data,
                        )
                        completed_threads.append(thread)
                    for thread in as_completed(completed_threads):
                        progress_bar.update(1)

其中有这样一行代码:

checksum = zlib.adler32(block_data) % (10**10)

这里adler32函数返回值是一个32位无符号整数,为什么还要取模10的10次方呢?
2^32=4294967296,是小于10^10的,这样的取模结果始终为0。

请教开发方法

hi,前两天跟据你的回复,我恶补了一下网络抓包,学跟着你的代码尝试自己写一个版本,但是我遇到了关于token的问题,源于你在FeishuUploader的构造函数中编写了这样一个请求头:

        self.headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
            "cookie": cookie,
            "bv-csrf-token": cookie[
                cookie.find("bv_csrf_token=")
                + len("bv_csrf_token=") : cookie.find(
                    ";", cookie.find("bv_csrf_token=")
                )
            ],
            "referer": "https://minutes.feishu.cn/minutes/home",
        }

让我疑惑的时这里token的选择,因为我在开发者工具中返回的cookie中还看到了很多不一样的token:_csrf_token, lgw_csrf_token, csrf_token, swp_csrf_token,你选择bv-csrf-token有什么理由吗?

希望得到你的指点!谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.