add chunk transder

This commit is contained in:
x1ulan 2025-12-24 14:04:36 +08:00
parent 07256f5dc3
commit f40f57925a
2 changed files with 15 additions and 9 deletions

View file

@ -34,7 +34,7 @@ def bitmap():
payload = 'P5\n296 152\n255\n'
payload += ''.join([chr(i) for i in bitmap_data])
print(payload)
req = requests.put('http://localhost:8080/api/tag', data=payload, headers={
req = requests.put('http://host.docker.internal:8080/api/tag', data=chunk_gen(bitmap_data), headers={
'Content-Type': 'image/x-portable-greymap'
})
return jsonify({'payload': payload, 'code': req.status_code})
@ -43,5 +43,16 @@ def bitmap():
except Exception as e:
return jsonify({"error": e}), 500
def chunk_gen(bitmap_data):
header = f'P5\n296 152\n255\n'
yield header.encode('latin-1')
chunk_size = 1024
for i in range(0, len(bitmap_data), chunk_size):
chunk = bitmap_data[i:i + chunk_size]
yield bytes(chunk)
if __name__ == '__main__':
app.run('0.0.0.0', port=80)

View file

@ -9,15 +9,10 @@ services:
container_name: backend_service
ports:
- "12001:80"
# bitmap_service:
# build: ./bitmap_service
# container_name: bitmap_service
# ports:
# - "12002:80"
bitmap_service:
build: ./trash
container_name: trash
build: ./bitmap_service
container_name: bitmap_service
ports:
- "12002:80"
extra_hosts:
- "host.docker.internal:host-gateway"
- "host.docker.internal:host-gateway"