Skip to content

Commit

Permalink
push asyncly
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Jul 13, 2022
1 parent 67ff05c commit 50ef505
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "easynotes",
"publisher": "moqsien",
"description": "store notes easily",
"version": "0.0.1",
"version": "0.0.2",
"repository": {
"type": "git",
"url": "https://github.com/moqsien/easynotes.git"
Expand Down
6 changes: 4 additions & 2 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ export class SyncFiles{

}

public async createRootDir() :Promise<void> {
public async createRootDir() :Promise<boolean> {
if (!(await this.client.exists(this.remoteRoot))) {
await this.client.createDirectory(this.remoteRoot);
}
return true;
};
return false;
};

public async isVersionExists(): Promise<void> {
Expand Down
24 changes: 16 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from 'vscode';
import { SyncFiles } from './tools';
import fs = require("fs");
import path = require("path");
import { resolve } from 'path';

export class Config implements ToolConfig {
public webdavUrl: string;
Expand Down Expand Up @@ -65,20 +66,27 @@ export function loadConfigFile(workspaceFolders: any) :Config {
});
};

function pushNoteFiles(conf: ToolConfig) {
function sleep(ms: number) {
return new Promise(resolve=>setTimeout(resolve, ms));
};

async function pushNoteFiles(conf: ToolConfig) {
let cnf = new SyncFiles(conf);
cnf.createRootDir();
cnf.isVersionExists();
let flag: boolean = await cnf.createRootDir();
if (flag) {
await sleep(2000);
};
await cnf.isVersionExists();
cnf.createVersion(true);
cnf.pushWalkDirs(conf.localRoot);
cnf.deleteRemoteFiles(conf.remoteRoot);
await cnf.pushWalkDirs(conf.localRoot);
await cnf.deleteRemoteFiles(conf.remoteRoot);
vscode.window.showInformationMessage("push file completed!");
};

function pullhNoteFiles(conf: ToolConfig) {
async function pullhNoteFiles(conf: ToolConfig) {
let cnf = new SyncFiles(conf);
cnf.pullWalkDirs(conf.remoteRoot);
cnf.deleteLocalFiles(conf.localRoot);
await cnf.pullWalkDirs(conf.remoteRoot);
await cnf.deleteLocalFiles(conf.localRoot);
vscode.window.showInformationMessage("pull file completed!");
};

Expand Down

0 comments on commit 50ef505

Please sign in to comment.