optimize sync & add accept popup
This commit is contained in:
parent
c9f604863a
commit
f0e097fa76
10 changed files with 305 additions and 61 deletions
|
|
@ -82,14 +82,20 @@ function createPusher(api) {
|
|||
|
||||
function putFile(device, token, unitKey, rel, abs) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const route = `/plwl/unit/file?token=${encodeURIComponent(token)}&unit=${encodeURIComponent(unitKey)}&path=${encodeURIComponent(rel)}`
|
||||
// unit and path travel as headers: the receiver used to parse a fresh
|
||||
// query string per file for values that are constant per request
|
||||
const req = http.request(
|
||||
{
|
||||
host: device.address,
|
||||
port: device.port,
|
||||
path: route,
|
||||
path: `/plwl/unit/file?token=${encodeURIComponent(token)}`,
|
||||
method: 'PUT',
|
||||
headers: { 'content-type': 'application/octet-stream', 'content-length': fs.statSync(abs).size },
|
||||
headers: {
|
||||
'content-type': 'application/octet-stream',
|
||||
'content-length': fs.statSync(abs).size,
|
||||
'x-plwl-unit': unitKey,
|
||||
'x-plwl-path': rel
|
||||
},
|
||||
timeout: 0
|
||||
},
|
||||
res => {
|
||||
|
|
@ -262,18 +268,21 @@ function createPusher(api) {
|
|||
|
||||
let verified
|
||||
try {
|
||||
// longer than the receiver's incoming-request timeout: the user over
|
||||
// there gets a popup and this side waits for the click
|
||||
verified = await httpJson(device, 'POST', '/plwl/verify', {
|
||||
json: { deviceId: identity().deviceId, name: os.hostname(), code: String(code == null ? '' : code).trim().toUpperCase(), totals },
|
||||
timeout: 20000
|
||||
timeout: 90000
|
||||
})
|
||||
} catch (err) {
|
||||
return fail(String((err && err.message) || err))
|
||||
}
|
||||
if (!verified.data || !verified.data.ok) {
|
||||
const error = (verified.data && verified.data.error) || `http-${verified.status}`
|
||||
// the peer rejected the code (it was rotated there): drop the stored
|
||||
// pairing, so the user is asked for the new code instead of every later
|
||||
// sync failing against a stale one
|
||||
// the peer rotated its code: drop the stored pairing, so the next
|
||||
// attempt asks for the new one instead of failing silently. A plain
|
||||
// 'rejected' (the user over there declined the popup) keeps the pairing
|
||||
// - the code was proven correct, the popup is the consent gate.
|
||||
if (error === 'auth-failed' || error === 'bad-code') forgetDevice(device.id || deviceId)
|
||||
return fail(error)
|
||||
}
|
||||
|
|
@ -348,13 +357,11 @@ function createPusher(api) {
|
|||
// already identical (the plan reports both)
|
||||
bucket.copied += entries.length - same.size
|
||||
bucket.skipped += same.size
|
||||
summary.skipped += same.size
|
||||
const pending = []
|
||||
for (const entry of entries) {
|
||||
if (entry.type !== 'file') continue
|
||||
if (!upload.has(entry.path)) {
|
||||
summary.skipped++
|
||||
continue
|
||||
}
|
||||
if (!upload.has(entry.path)) continue // identical -> the receiver keeps its copy
|
||||
pending.push(entry)
|
||||
plannedBytes += entry.size || 0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue