forked from tsai/budibase
8 changed files with 710 additions and 435 deletions
@ -0,0 +1,38 @@ |
|||||
|
const PouchDB = require("pouchdb") |
||||
|
const { checkSlashesInUrl } = require("../utils") |
||||
|
const fetch = require("node-fetch") |
||||
|
|
||||
|
/** |
||||
|
* Fully qualified URL including username and password, or nothing for local |
||||
|
*/ |
||||
|
exports.getPouch = (url = undefined) => { |
||||
|
let POUCH_DB_DEFAULTS = {} |
||||
|
if (!url) { |
||||
|
POUCH_DB_DEFAULTS = { |
||||
|
prefix: undefined, |
||||
|
adapter: "leveldb", |
||||
|
} |
||||
|
} else { |
||||
|
POUCH_DB_DEFAULTS = { |
||||
|
prefix: url, |
||||
|
} |
||||
|
} |
||||
|
const replicationStream = require("pouchdb-replication-stream") |
||||
|
PouchDB.plugin(replicationStream.plugin) |
||||
|
PouchDB.adapter("writableStream", replicationStream.adapters.writableStream) |
||||
|
return PouchDB.defaults(POUCH_DB_DEFAULTS) |
||||
|
} |
||||
|
|
||||
|
exports.getAllDbs = async url => { |
||||
|
const response = await fetch( |
||||
|
checkSlashesInUrl(encodeURI(`${url}/_all_dbs`)), |
||||
|
{ |
||||
|
method: "GET", |
||||
|
} |
||||
|
) |
||||
|
if (response.status === 200) { |
||||
|
return await response.json() |
||||
|
} else { |
||||
|
throw "Cannot connect to CouchDB instance" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
const os = require("os") |
||||
|
const { join } = require("path") |
||||
|
const fs = require("fs") |
||||
|
const PREBUILDS = "prebuilds" |
||||
|
const ARCH = `${os.platform()}-${os.arch()}` |
||||
|
const PREBUILD_DIR = join(process.execPath, "..", PREBUILDS, ARCH) |
||||
|
|
||||
|
checkForBinaries() |
||||
|
|
||||
|
function checkForBinaries() { |
||||
|
if (fs.existsSync(PREBUILD_DIR)) { |
||||
|
return |
||||
|
} |
||||
|
const readDir = join(__filename, "..", "..", PREBUILDS, ARCH) |
||||
|
const natives = fs.readdirSync(readDir) |
||||
|
if (fs.existsSync(readDir)) { |
||||
|
fs.mkdirSync(PREBUILD_DIR, { recursive: true }) |
||||
|
for (let native of natives) { |
||||
|
const filename = `${native.split(".fake")[0]}.node` |
||||
|
fs.cpSync(join(readDir, native), join(PREBUILD_DIR, filename)) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
process.on("exit", () => { |
||||
|
if (fs.existsSync(PREBUILD_DIR)) { |
||||
|
fs.rmSync(PREBUILD_DIR, { recursive: true }) |
||||
|
} |
||||
|
}) |
||||
File diff suppressed because it is too large
Loading…
Reference in new issue