• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blockexchange / blockexchange / 13110168475

03 Feb 2025 09:18AM UTC coverage: 48.213% (+0.6%) from 47.564%
13110168475

push

github

BuckarooBanzay
http/json overhaul

51 of 102 new or added lines in 14 files covered. (50.0%)

1 existing line in 1 file now uncovered.

985 of 2043 relevant lines covered (48.21%)

1734.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/worker/save_worker.lua
1
local has_monitoring = minetest.get_modpath("monitoring")
1✔
2

3
local uploaded_blocks
4

5
if has_monitoring then
1✔
6
        uploaded_blocks = monitoring.counter(
×
7
        "blockexchange_uploaded_blocks",
8
        "number of successfully uploaded mapblocks"
9
)
10
end
11

12
local function shift(ctx)
13
        ctx.current_pos, ctx.rel_pos, ctx.progress = ctx.iterator()
32✔
14

15
        -- increment stats
16
        ctx.current_part = ctx.current_part + 1
16✔
17
        ctx.progress_percent = math.floor(ctx.progress * 100 * 10) / 10
16✔
18
end
19

20
function blockexchange.save_worker(ctx)
2✔
21
        if ctx.cancel then
18✔
22
                ctx.promise:reject("canceled")
×
23
                ctx.zip:close()
×
24
                ctx.zipfile:close()
×
25
        end
26

27
        if not ctx.current_pos then
18✔
28
                -- save of individual parts finished, finalize schema and update stats
29

30
                -- create an array with mod names
31
                local mod_names = {}
2✔
32
                for k in pairs(ctx.mod_names) do
4✔
33
                        table.insert(mod_names, k)
2✔
34
                end
35

36
                if ctx.local_save then
2✔
37
                        -- local save
38
                        ctx.create_schema.total_parts = ctx.current_part
1✔
39
                        ctx.create_schema.total_size = ctx.total_size
1✔
40
                        ctx.zip:add("mods.json", minetest.write_json(mod_names))
1✔
41
                        ctx.zip:add("schema.json", minetest.write_json(ctx.create_schema))
1✔
42
                        ctx.zip:close()
1✔
43
                        ctx.zipfile:close()
1✔
44

45
                        local msg = "[blockexchange] Local save complete with " .. ctx.total_parts .. " parts"
1✔
46
                        minetest.log("action", msg)
1✔
47
                        minetest.chat_send_player(ctx.playername, msg)
1✔
48
                        ctx.promise:resolve({ total_parts = ctx.total_parts})
2✔
49
                else
50
                        -- online save
51
                        blockexchange.api.create_schemamods(ctx.token, ctx.schema.uid, mod_names):next(function()
3✔
52
                                return blockexchange.api.update_schema_stats(ctx.token, ctx.schema.uid)
1✔
53
                        end):next(function()
3✔
54
                                local msg = "[blockexchange] Save complete with " .. ctx.total_parts .. " parts"
1✔
55
                                minetest.log("action", msg)
1✔
56
                                minetest.chat_send_player(ctx.playername, msg)
1✔
57
                                ctx.promise:resolve({ total_parts = ctx.total_parts})
1✔
58
                                -- fetch updated schema
59
                                return blockexchange.api.get_schema_by_name(ctx.username, ctx.schemaname)
1✔
60
                        end):next(function(schema)
3✔
61
                                -- register for later future updates
62
                                blockexchange.register_area(ctx.pos1, ctx.pos2, ctx.playername, ctx.username, schema)
1✔
63
                        end):catch(function(err)
4✔
NEW
64
                                local msg = "[blockexchange] finalize schema failed: " .. (err or "unkown") ..
×
65
                                " retry manual on the web-ui please"
66
                                minetest.log("error", msg)
×
67
                                minetest.chat_send_player(ctx.playername, minetest.colorize("#ff0000", msg))
×
68
                                ctx.promise:resolve({ total_parts = ctx.total_parts})
×
69
                        end)
70
                end
71

72
                return
2✔
73
        end
74

75
        local start = minetest.get_us_time()
16✔
76

77
        local pos2 = vector.add(ctx.current_pos, 15)
16✔
78
        -- clip pos2 to area bounds
79
        pos2.x = math.min(pos2.x, ctx.pos2.x)
16✔
80
        pos2.y = math.min(pos2.y, ctx.pos2.y)
16✔
81
        pos2.z = math.min(pos2.z, ctx.pos2.z)
16✔
82

83
        local data, node_count, air_only = blockexchange.serialize_part(ctx.current_pos, pos2)
16✔
84

85
        -- collect mod count info
86
        blockexchange.collect_node_count(node_count, ctx.mod_names)
16✔
87

88
        local diff = minetest.get_us_time() - start
16✔
89
        local relative_pos = vector.subtract(ctx.current_pos, ctx.pos1)
16✔
90

91
        if air_only then
16✔
92
                -- don't save air-only
93
                minetest.log("action", "[blockexchange] NOT Saving part " .. minetest.pos_to_string(ctx.current_pos) ..
×
94
                " because it is air-only (processing took " .. diff .. " micros)")
×
95
                shift(ctx)
×
96
                minetest.after(blockexchange.min_delay, blockexchange.save_worker, ctx)
×
97
        else
98
                -- package data properly over the wire
99
                local schemapart = {
16✔
100
                        schema_uid = ctx.schema and ctx.schema.uid,
16✔
101
                        offset_x = relative_pos.x,
16✔
102
                        offset_y = relative_pos.y,
16✔
103
                        offset_z = relative_pos.z,
16✔
104
                        data = minetest.encode_base64(blockexchange.compress_data(data)),
32✔
105
                        metadata = minetest.encode_base64(blockexchange.compress_metadata(data))
32✔
106
                }
107

108
                ctx.total_size = ctx.total_size + #schemapart.data + #schemapart.metadata
16✔
109

110
                if ctx.local_save then
16✔
111
                        -- save locally
112
                        minetest.log("action", "[blockexchange] Saving local schemapart " .. minetest.pos_to_string(relative_pos))
16✔
113
                        local filename = "schemapart_" .. schemapart.offset_x ..
8✔
114
                                "_" .. schemapart.offset_y ..
8✔
115
                                "_" .. schemapart.offset_z ..
8✔
116
                                ".json"
8✔
117
                        ctx.zip:add(filename, minetest.write_json(schemapart))
8✔
118
                        shift(ctx)
8✔
119
                        minetest.after(blockexchange.min_delay, blockexchange.save_worker, ctx)
16✔
120
                else
121
                        -- upload part online
122
                        blockexchange.api.create_schemapart(ctx.token, schemapart):next(function()
24✔
123
                                minetest.log("action", "[blockexchange] Save of part " .. minetest.pos_to_string(ctx.current_pos) ..
16✔
124
                                " completed (processing took " .. diff .. " micros)")
8✔
125

126
                                if has_monitoring then
8✔
127
                                        uploaded_blocks.inc(1)
×
128
                                end
129

130
                                shift(ctx)
8✔
131
                                minetest.after(blockexchange.min_delay, blockexchange.save_worker, ctx)
8✔
132
                        end):catch(function(err)
32✔
NEW
133
                                local msg = "[blockexchange] create schemapart failed: " .. (err or "unkown") ..
×
134
                                " retrying..."
135
                                minetest.log("error", msg)
×
136
                                minetest.chat_send_player(ctx.playername, minetest.colorize("#ff0000", msg))
×
137
                                -- wait a couple seconds
138
                                minetest.after(5, blockexchange.save_worker, ctx)
×
139
                        end)
140
                end
141
        end
142

143
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc