fix: sqlite import

This commit is contained in:
Tienson Qin
2026-05-03 23:16:37 +08:00
parent c647326d86
commit e8de3cc104
4 changed files with 75 additions and 4 deletions

View File

@@ -517,10 +517,21 @@ export function base64ToUint8Array (base64String) {
export function uint8ArrayToBase64 (uint8Array) {
try {
let bytes = null
if (uint8Array instanceof Uint8Array) {
bytes = uint8Array
} else if (ArrayBuffer.isView(uint8Array)) {
bytes = new Uint8Array(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength)
} else if (uint8Array instanceof ArrayBuffer) {
bytes = new Uint8Array(uint8Array)
} else {
throw new TypeError('Expected Uint8Array, TypedArray, or ArrayBuffer')
}
let binary = ''
const len = uint8Array.byteLength
const len = bytes.byteLength
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(uint8Array[i])
binary += String.fromCharCode(bytes[i])
}
return btoa(binary)
} catch (e) {

View File

@@ -918,9 +918,9 @@
(def-thread-api :thread-api/import-db-base64
[repo base64]
(when-not (string/blank? repo)
(p/let [pool (<get-opfs-pool repo)
data (worker-util/base64string-to-unit8array base64)
(p/let [data (worker-util/base64string-to-unit8array base64)
_ (close-db! repo)
pool (<get-opfs-pool repo)
_ (<import-db pool data)
_ (start-db! repo {:import-type :sqlite-db})]
nil)))