braid-text 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +55 -50
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -91,7 +91,7 @@ braid_text.serve = async (req, res, options = {}) => {
|
|
|
91
91
|
|
|
92
92
|
return my_end(200, buffer)
|
|
93
93
|
} else {
|
|
94
|
-
res.setHeader("Editable", "true")
|
|
94
|
+
if (!res.hasHeader("editable")) res.setHeader("Editable", "true")
|
|
95
95
|
res.setHeader("Merge-Type", merge_type)
|
|
96
96
|
if (req.method == "HEAD") return my_end(200)
|
|
97
97
|
|
|
@@ -695,62 +695,67 @@ async function file_sync(key, process_delta, get_init) {
|
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
+
let chain = Promise.resolve()
|
|
698
699
|
return {
|
|
699
700
|
change: async (bytes) => {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
console.log(`starting new db..`)
|
|
714
|
-
|
|
715
|
-
currentNumber++
|
|
716
|
-
const init = get_init()
|
|
717
|
-
const buffer = Buffer.allocUnsafe(4)
|
|
718
|
-
buffer.writeUInt32LE(init.length, 0)
|
|
719
|
-
|
|
720
|
-
const newFilename = `${braid_text.db_folder}/${encoded}.${currentNumber}`
|
|
721
|
-
await fs.promises.writeFile(newFilename, buffer)
|
|
722
|
-
await fs.promises.appendFile(newFilename, init)
|
|
723
|
-
|
|
724
|
-
console.log("wrote to : " + newFilename)
|
|
725
|
-
|
|
726
|
-
currentSize = 4 + init.length
|
|
727
|
-
threshold = currentSize * 10
|
|
701
|
+
await (chain = chain.then(async () => {
|
|
702
|
+
currentSize += bytes.length + 4 // we account for the extra 4 bytes for uint32
|
|
703
|
+
const filename = `${braid_text.db_folder}/${encoded}.${currentNumber}`
|
|
704
|
+
if (currentSize < threshold) {
|
|
705
|
+
console.log(`appending to db..`)
|
|
706
|
+
|
|
707
|
+
let buffer = Buffer.allocUnsafe(4)
|
|
708
|
+
buffer.writeUInt32LE(bytes.length, 0)
|
|
709
|
+
await fs.promises.appendFile(filename, buffer)
|
|
710
|
+
await fs.promises.appendFile(filename, bytes)
|
|
711
|
+
|
|
712
|
+
console.log("wrote to : " + filename)
|
|
713
|
+
} else {
|
|
728
714
|
try {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
715
|
+
console.log(`starting new db..`)
|
|
716
|
+
|
|
717
|
+
currentNumber++
|
|
718
|
+
const init = get_init()
|
|
719
|
+
const buffer = Buffer.allocUnsafe(4)
|
|
720
|
+
buffer.writeUInt32LE(init.length, 0)
|
|
721
|
+
|
|
722
|
+
const newFilename = `${braid_text.db_folder}/${encoded}.${currentNumber}`
|
|
723
|
+
await fs.promises.writeFile(newFilename, buffer)
|
|
724
|
+
await fs.promises.appendFile(newFilename, init)
|
|
725
|
+
|
|
726
|
+
console.log("wrote to : " + newFilename)
|
|
727
|
+
|
|
728
|
+
currentSize = 4 + init.length
|
|
729
|
+
threshold = currentSize * 10
|
|
730
|
+
try {
|
|
731
|
+
await fs.promises.unlink(filename)
|
|
732
|
+
} catch (e) { }
|
|
733
|
+
} catch (e) {
|
|
734
|
+
console.log(`e = ${e.stack}`)
|
|
735
|
+
}
|
|
733
736
|
}
|
|
734
|
-
}
|
|
737
|
+
}))
|
|
735
738
|
},
|
|
736
739
|
delete_me: async () => {
|
|
737
|
-
await
|
|
738
|
-
(
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
740
|
+
await (chain = chain.then(async () => {
|
|
741
|
+
await Promise.all(
|
|
742
|
+
(
|
|
743
|
+
await get_files_for_key(key)
|
|
744
|
+
).map((file) => {
|
|
745
|
+
return new Promise((resolve, reject) => {
|
|
746
|
+
fs.unlink(file, (err) => {
|
|
747
|
+
if (err) {
|
|
748
|
+
console.error(`Error deleting file: ${file}`)
|
|
749
|
+
reject(err)
|
|
750
|
+
} else {
|
|
751
|
+
console.log(`Deleted file: ${file}`)
|
|
752
|
+
resolve()
|
|
753
|
+
}
|
|
754
|
+
})
|
|
750
755
|
})
|
|
751
756
|
})
|
|
752
|
-
|
|
753
|
-
)
|
|
757
|
+
)
|
|
758
|
+
}))
|
|
754
759
|
},
|
|
755
760
|
}
|
|
756
761
|
}
|
|
@@ -1469,7 +1474,7 @@ function is_valid_actor(x) {
|
|
|
1469
1474
|
try {
|
|
1470
1475
|
validate_actor(x)
|
|
1471
1476
|
return true
|
|
1472
|
-
} catch (e) {}
|
|
1477
|
+
} catch (e) { }
|
|
1473
1478
|
}
|
|
1474
1479
|
|
|
1475
1480
|
function decode_version(v) {
|