-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
Copy pathwebdav.ts
72 lines (56 loc) · 1.57 KB
/
webdav.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import BackendUI from "./backend.js";
import WebDAV from "../../backend/webdav.js";
import * as app from "../../my-mind.js";
import { repo as formatRepo } from "../../format/format.js";
interface State {
url: string;
}
export default class WebDAVUI extends BackendUI<WebDAV> {
protected current = "";
constructor() {
super(new WebDAV(), "Generic WebDAV");
this.url.value = localStorage.getItem(`${this.prefix}.url`) || "";
}
get url() { return this.node.querySelector<HTMLInputElement>(".url")!; }
getState(): State {
let data = { url: this.current };
return data;
}
setState(data: State) {
this.load(data.url);
}
async save() {
app.setThrobber(true);
var map = app.currentMap;
var url = this.url.value;
localStorage.setItem(`${this.prefix}.url`, url);
if (url.match(/\.mymind$/)) { // complete file name
} else { // just a path
if (url.charAt(url.length-1) != "/") { url += "/"; }
url += `${map.name}.${formatRepo.get("native")!.extension}`;
}
this.current = url;
let json = map.toJSON();
let data = formatRepo.get("native")!.to(json);
try {
await this.backend.save(data, url);
this.saveDone();
} catch (e) {
this.error(e);
}
}
async load(url = this.url.value) {
this.current = url;
app.setThrobber(true);
var lastIndex = url.lastIndexOf("/");
this.url.value = url.substring(0, lastIndex);
localStorage.setItem(`${this.prefix}.url`, this.url.value);
try {
let data = await this.backend.load(url);
let json = formatRepo.get("native")!.from(data);
this.loadDone(json);
} catch (e) {
this.error(e);
}
}
}