chore(giftfetch): sync NFT gift export fields
This commit is contained in:
parent
3fa0c6f1e4
commit
45a7e117ea
2 changed files with 24 additions and 6 deletions
|
|
@ -830,12 +830,13 @@ func downloadPartSize(expectedSize int64) int {
|
|||
if expectedSize <= 0 || expectedSize >= max {
|
||||
return int(max)
|
||||
}
|
||||
// Choose a valid 4 KiB-aligned limit strictly larger than the file whenever
|
||||
// possible, so downloader.Stream recognizes the first short chunk as final
|
||||
// without an extra EOF probe.
|
||||
partSize := ((expectedSize + 1 + unit - 1) / unit) * unit
|
||||
if partSize > max {
|
||||
partSize = max
|
||||
// Non-precise upload.getFile limits must use the client-compatible chunk
|
||||
// ladder (4, 8, ..., 512 KiB), whose values also divide a 1 MiB window.
|
||||
// Merely rounding to an arbitrary 4 KiB multiple (for example 48 KiB)
|
||||
// is rejected with LIMIT_INVALID by some official file DCs.
|
||||
partSize := unit
|
||||
for partSize <= expectedSize && partSize < max {
|
||||
partSize *= 2
|
||||
}
|
||||
return int(partSize)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ func TestDownloadPartSize(t *testing.T) {
|
|||
{size: 1, want: 4 << 10},
|
||||
{size: (4 << 10) - 1, want: 4 << 10},
|
||||
{size: 4 << 10, want: 8 << 10},
|
||||
{size: 48_632, want: 64 << 10},
|
||||
{size: (512 << 10) - 1, want: 512 << 10},
|
||||
{size: 512 << 10, want: 512 << 10},
|
||||
{size: 1 << 20, want: 512 << 10},
|
||||
|
|
@ -80,6 +81,22 @@ func TestDownloadPartSize(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDownloadPartSizeUsesNonPreciseChunkLadder(t *testing.T) {
|
||||
const oneMiB = 1 << 20
|
||||
for size := int64(1); size < 512<<10; size += 997 {
|
||||
partSize := downloadPartSize(size)
|
||||
if partSize < 4<<10 || partSize > 512<<10 || partSize%(4<<10) != 0 {
|
||||
t.Fatalf("downloadPartSize(%d) = %d is outside the valid 4 KiB-aligned range", size, partSize)
|
||||
}
|
||||
if oneMiB%partSize != 0 {
|
||||
t.Fatalf("downloadPartSize(%d) = %d does not divide a 1 MiB request window", size, partSize)
|
||||
}
|
||||
if int64(partSize) <= size {
|
||||
t.Fatalf("downloadPartSize(%d) = %d does not cover the known-size single chunk", size, partSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAllowedMissingThumbs(t *testing.T) {
|
||||
allowed, err := parseAllowedMissingThumbs("5417911440709285239:photo:m,42:video:v")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue