- Empty path treatment.
This commit is contained in:
vorotamoroz 2022-04-16 10:11:01 +09:00
parent 1abf0feb51
commit b2ce4593b9

View File

@ -246,7 +246,7 @@ async function eachProc(syncKey: string, config: eachConf) {
const serverURI = config.server.uri; const serverURI = config.server.uri;
const serverAuth = config.server.auth; const serverAuth = config.server.auth;
const serverPath = config.server.path; const serverPath = config.server.path ?? "";
const exportPath = config.local?.path ?? ""; const exportPath = config.local?.path ?? "";
const processor = config.local?.processor ?? ""; const processor = config.local?.processor ?? "";
@ -317,7 +317,7 @@ async function eachProc(syncKey: string, config: eachConf) {
log("start vault watching"); log("start vault watching");
const storagePathRoot = path.resolve(config.local.path); const storagePathRoot = path.resolve(exportPath);
let conf: connectConfig = { let conf: connectConfig = {
syncKey: syncKey, syncKey: syncKey,
fromDB: remote, fromDB: remote,
@ -397,7 +397,7 @@ async function eachProc(syncKey: string, config: eachConf) {
}; };
// check the document is under the [vault]/[configured_dir].. // check the document is under the [vault]/[configured_dir]..
function isTargetFile(pathSrc: string): boolean { function isTargetFile(pathSrc: string): boolean {
if (pathSrc.startsWith(config.server.path)) { if (pathSrc.startsWith(serverPath)) {
return true; return true;
} else { } else {
return false; return false;
@ -405,7 +405,7 @@ async function eachProc(syncKey: string, config: eachConf) {
} }
async function pullFile(id: string, localPath: string) { async function pullFile(id: string, localPath: string) {
let fromDoc = await remote.get(id); let fromDoc = await remote.get(id);
const docName = fromDoc._id.substring(config.server.path.length); const docName = fromDoc._id.substring(serverPath.length);
let sendDoc: PouchDB.Core.ExistingDocument<PouchDB.Core.ChangesMeta> & { children?: string[]; type?: string; mtime?: number } = { ...fromDoc, _id: docName.startsWith("_") ? "/" + docName : docName }; let sendDoc: PouchDB.Core.ExistingDocument<PouchDB.Core.ChangesMeta> & { children?: string[]; type?: string; mtime?: number } = { ...fromDoc, _id: docName.startsWith("_") ? "/" + docName : docName };
if (await exportDoc(sendDoc, docName, serverAuth.passphrase, remote, exportPath)) { if (await exportDoc(sendDoc, docName, serverAuth.passphrase, remote, exportPath)) {
log(`Pull:${localPath}`); log(`Pull:${localPath}`);
@ -426,7 +426,7 @@ async function eachProc(syncKey: string, config: eachConf) {
continue; continue;
} }
const localPath = fn.substring(config.server.path.length); const localPath = fn.substring(serverPath.length);
const storageNewFilePath = vaultPathToStroageABSPath(localPath); const storageNewFilePath = vaultPathToStroageABSPath(localPath);
// log(`Checking initial file:${localPath}`); // log(`Checking initial file:${localPath}`);
// log(`--> file:${storageNewFilePath}`); // log(`--> file:${storageNewFilePath}`);
@ -461,7 +461,7 @@ async function eachProc(syncKey: string, config: eachConf) {
} }
} }
const watcher = chokidar.watch(config.local.path, { const watcher = chokidar.watch(exportPath, {
ignoreInitial: !config.local.initialScan && !config.sync_on_connect, ignoreInitial: !config.local.initialScan && !config.sync_on_connect,
awaitWriteFinish: { awaitWriteFinish: {
stabilityThreshold: 500, stabilityThreshold: 500,
@ -567,13 +567,13 @@ async function exportDoc(sendDoc: TransferEntry, docName: string, passphrase: st
passphrase == "" passphrase == ""
? children ? children
: ( : (
await Promise.allSettled( await Promise.allSettled(
children.map(async (e: any) => { children.map(async (e: any) => {
e.data = await decrypt(e.data, passphrase); e.data = await decrypt(e.data, passphrase);
return e; return e;
}) })
) )
).map((e) => (e.status == "fulfilled" ? e.value : null)); ).map((e) => (e.status == "fulfilled" ? e.value : null));
const dirName = path.dirname(writePath); const dirName = path.dirname(writePath);
log(`doc:${docName}: Exporting to ${writePath}`); log(`doc:${docName}: Exporting to ${writePath}`);
await fs.mkdir(dirName, { recursive: true }); await fs.mkdir(dirName, { recursive: true });
@ -651,4 +651,4 @@ async function main() {
} }
} }
main().then((_) => {}); main().then((_) => { });