@xwiki/cristal-electron-storage 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -11
- package/dist/default/components/FileSystemConfig.d.ts +0 -8
- package/dist/default/components/fileSystemStorage.d.ts +0 -25
- package/dist/default/componentsInit.d.ts +0 -9
- package/dist/default/electron/main/index.d.ts +0 -20
- package/dist/default/electron/preload/apiTypes.d.ts +0 -42
- package/dist/default/electron/preload/index.d.ts +0 -20
- package/dist/default/index.d.cts +0 -2
- package/dist/default/index.d.ts +0 -2
- package/dist/default/index.es.js +0 -110
- package/dist/default/index.es.js.map +0 -1
- package/dist/default/index.umd.js +0 -2
- package/dist/default/index.umd.js.map +0 -1
- package/dist/main/index.d.cts +0 -20
- package/dist/main/index.d.ts +0 -20
- package/dist/main/index.es.js +0 -247
- package/dist/main/index.es.js.map +0 -1
- package/dist/main/index.umd.js +0 -10
- package/dist/main/index.umd.js.map +0 -1
- package/dist/preload/apiTypes.d.ts +0 -42
- package/dist/preload/index.d.cts +0 -20
- package/dist/preload/index.d.ts +0 -20
- package/dist/preload/index.es.js +0 -50
- package/dist/preload/index.es.js.map +0 -1
- package/dist/preload/index.umd.js +0 -2
- package/dist/preload/index.umd.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xwiki/cristal-electron-storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"license": "LGPL 2.1",
|
|
5
5
|
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
6
|
"homepage": "https://cristal.xwiki.org/",
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://jira.xwiki.org/projects/CRISTAL/"
|
|
14
14
|
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=24.0.0"
|
|
17
|
+
},
|
|
15
18
|
"type": "module",
|
|
16
19
|
"exports": {
|
|
17
20
|
".": {
|
|
@@ -48,15 +51,15 @@
|
|
|
48
51
|
"main": "./dist/main/index.es.js",
|
|
49
52
|
"types": "./dist/main/index.d.ts",
|
|
50
53
|
"dependencies": {
|
|
51
|
-
"@xwiki/platform-api": "18.
|
|
52
|
-
"@xwiki/platform-backend-api": "18.
|
|
53
|
-
"@xwiki/platform-link-suggest-api": "18.
|
|
54
|
-
"@xwiki/platform-model-api": "18.
|
|
54
|
+
"@xwiki/platform-api": "18.4.0",
|
|
55
|
+
"@xwiki/platform-backend-api": "18.4.0",
|
|
56
|
+
"@xwiki/platform-link-suggest-api": "18.4.0",
|
|
57
|
+
"@xwiki/platform-model-api": "18.4.0",
|
|
55
58
|
"mime": "4.1.0",
|
|
56
|
-
"@xwiki/cristal-
|
|
57
|
-
"@xwiki/cristal-model-remote-url-filesystem-api": "1.
|
|
58
|
-
"@xwiki/cristal-
|
|
59
|
-
"@xwiki/cristal-
|
|
59
|
+
"@xwiki/cristal-electron-state": "1.4.0",
|
|
60
|
+
"@xwiki/cristal-model-remote-url-filesystem-api": "1.4.0",
|
|
61
|
+
"@xwiki/cristal-page-default": "1.4.0",
|
|
62
|
+
"@xwiki/cristal-utils-inversify": "1.4.0"
|
|
60
63
|
},
|
|
61
64
|
"peerDependencies": {
|
|
62
65
|
"electron": "41.1.0",
|
|
@@ -64,13 +67,13 @@
|
|
|
64
67
|
"reflect-metadata": "0.x"
|
|
65
68
|
},
|
|
66
69
|
"devDependencies": {
|
|
67
|
-
"@types/node": "24.12.
|
|
70
|
+
"@types/node": "24.12.4",
|
|
68
71
|
"inversify": "8.1.0",
|
|
69
72
|
"reflect-metadata": "0.2.2",
|
|
70
73
|
"typescript": "5.9.3",
|
|
71
74
|
"vite": "7.3.2",
|
|
72
75
|
"vite-plugin-node": "7.0.0",
|
|
73
|
-
"@xwiki/cristal-dev-config": "1.
|
|
76
|
+
"@xwiki/cristal-dev-config": "1.4.0"
|
|
74
77
|
},
|
|
75
78
|
"scripts": {
|
|
76
79
|
"build": "vite build && vite build -c vite.preload.config.ts && vite build -c vite.main.config.ts",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DefaultWikiConfig, CristalApp, Logger, Storage } from '@xwiki/platform-api';
|
|
2
|
-
export declare class FileSystemConfig extends DefaultWikiConfig {
|
|
3
|
-
storage: Storage;
|
|
4
|
-
cristal: CristalApp;
|
|
5
|
-
constructor(logger: Logger, storage: Storage, cristal: CristalApp);
|
|
6
|
-
getType(): string;
|
|
7
|
-
initialize(): void;
|
|
8
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AbstractStorage } from '@xwiki/platform-backend-api';
|
|
2
|
-
import { AttachmentsData, Logger, PageAttachment, PageData } from '@xwiki/platform-api';
|
|
3
|
-
export default class FileSystemStorage extends AbstractStorage {
|
|
4
|
-
constructor(logger: Logger);
|
|
5
|
-
getEditField(): Promise<string>;
|
|
6
|
-
getImageURL(): string;
|
|
7
|
-
getPageContent(page: string): Promise<PageData>;
|
|
8
|
-
getAttachments(page: string): Promise<AttachmentsData | undefined>;
|
|
9
|
-
getAttachment(page: string, name: string): Promise<PageAttachment | undefined>;
|
|
10
|
-
getPageFromViewURL(): string | null;
|
|
11
|
-
getPageRestURL(): string;
|
|
12
|
-
getPanelContent(): Promise<PageData>;
|
|
13
|
-
isStorageReady(): Promise<boolean>;
|
|
14
|
-
save(page: string, title: string, content: string): Promise<void>;
|
|
15
|
-
saveAttachments(page: string, files: File[]): Promise<undefined | (undefined | string)[]>;
|
|
16
|
-
delete(page: string): Promise<{
|
|
17
|
-
success: boolean;
|
|
18
|
-
error?: string;
|
|
19
|
-
}>;
|
|
20
|
-
move(page: string, newPage: string, preserveChildren: boolean): Promise<{
|
|
21
|
-
success: boolean;
|
|
22
|
-
error?: string;
|
|
23
|
-
}>;
|
|
24
|
-
private saveAttachment;
|
|
25
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See the LICENSE file distributed with this work for additional
|
|
3
|
-
* information regarding copyright ownership.
|
|
4
|
-
*
|
|
5
|
-
* This is free software; you can redistribute it and/or modify it
|
|
6
|
-
* under the terms of the GNU Lesser General Public License as
|
|
7
|
-
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
-
* the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This software is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this software; if not, write to the Free
|
|
17
|
-
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
-
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
-
*/
|
|
20
|
-
export default function load(): Promise<void>;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { LinkType } from '@xwiki/platform-link-suggest-api';
|
|
2
|
-
import { EntityType } from '@xwiki/platform-model-api';
|
|
3
|
-
import { PageAttachment, PageData } from '@xwiki/platform-api';
|
|
4
|
-
export interface APITypes {
|
|
5
|
-
initRootDirectory(): void;
|
|
6
|
-
resolvePath(page: string): Promise<string>;
|
|
7
|
-
resolveAttachmentsPath(page: string): Promise<string>;
|
|
8
|
-
resolveAttachmentPath(page: string, filename: string): Promise<string>;
|
|
9
|
-
readPage(path: string): Promise<PageData>;
|
|
10
|
-
readAttachments(path: string): Promise<PageAttachment[]>;
|
|
11
|
-
readAttachment(path: string): Promise<PageAttachment>;
|
|
12
|
-
savePage(path: string, content: string, title: string): Promise<PageData>;
|
|
13
|
-
saveAttachment(path: string, file: File): Promise<PageData>;
|
|
14
|
-
listChildren(page: string): Promise<Array<string>>;
|
|
15
|
-
deletePage(reference: string): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param query - search query
|
|
19
|
-
* @param type - the type of attach
|
|
20
|
-
* @param mimetype - the expected mimetype, only applied for attachments
|
|
21
|
-
* @since 0.13
|
|
22
|
-
* @beta
|
|
23
|
-
*/
|
|
24
|
-
search(query: string, type?: LinkType, mimetype?: string): Promise<({
|
|
25
|
-
type: EntityType.ATTACHMENT;
|
|
26
|
-
value: PageAttachment;
|
|
27
|
-
} | {
|
|
28
|
-
type: EntityType.DOCUMENT;
|
|
29
|
-
value: PageData;
|
|
30
|
-
})[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Move a page.
|
|
33
|
-
*
|
|
34
|
-
* @param reference - the reference of the page to move
|
|
35
|
-
* @param newReference - the new reference of the page
|
|
36
|
-
* @param preserveChildren - whether to move children
|
|
37
|
-
*
|
|
38
|
-
* @since 0.20
|
|
39
|
-
* @beta
|
|
40
|
-
*/
|
|
41
|
-
movePage(reference: string, newReference: string, preserveChildren: boolean): Promise<void>;
|
|
42
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See the LICENSE file distributed with this work for additional
|
|
3
|
-
* information regarding copyright ownership.
|
|
4
|
-
*
|
|
5
|
-
* This is free software; you can redistribute it and/or modify it
|
|
6
|
-
* under the terms of the GNU Lesser General Public License as
|
|
7
|
-
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
-
* the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This software is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this software; if not, write to the Free
|
|
17
|
-
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
-
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
-
*/
|
|
20
|
-
export {};
|
package/dist/default/index.d.cts
DELETED
package/dist/default/index.d.ts
DELETED
package/dist/default/index.es.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { DefaultWikiConfig as h, DefaultPageData as u } from "@xwiki/platform-api";
|
|
2
|
-
import { injectable as c, inject as g, named as S } from "inversify";
|
|
3
|
-
import { AbstractStorage as y } from "@xwiki/platform-backend-api";
|
|
4
|
-
import { whenNamedOrDefault as d } from "@xwiki/cristal-utils-inversify";
|
|
5
|
-
var f = Object.getOwnPropertyDescriptor, p = (t, e, a, r) => {
|
|
6
|
-
for (var s = r > 1 ? void 0 : r ? f(e, a) : e, o = t.length - 1, n; o >= 0; o--)
|
|
7
|
-
(n = t[o]) && (s = n(s) || s);
|
|
8
|
-
return s;
|
|
9
|
-
}, i = (t, e) => (a, r) => e(a, r, t);
|
|
10
|
-
let l = class extends h {
|
|
11
|
-
storage;
|
|
12
|
-
cristal;
|
|
13
|
-
constructor(t, e, a) {
|
|
14
|
-
super(t), this.storage = e, this.cristal = a, this.storage.setWikiConfig(this), this.homePage === "" && (this.homePage = "index.md");
|
|
15
|
-
}
|
|
16
|
-
getType() {
|
|
17
|
-
return "FileSystem";
|
|
18
|
-
}
|
|
19
|
-
initialize() {
|
|
20
|
-
super.initialize(), fileSystemStorage.initRootDirectory();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
l = p([
|
|
24
|
-
c(),
|
|
25
|
-
i(0, g("Logger")),
|
|
26
|
-
i(1, g("Storage")),
|
|
27
|
-
i(1, S("FileSystem")),
|
|
28
|
-
i(2, g("CristalApp"))
|
|
29
|
-
], l);
|
|
30
|
-
var v = Object.getOwnPropertyDescriptor, P = (t, e, a, r) => {
|
|
31
|
-
for (var s = r > 1 ? void 0 : r ? v(e, a) : e, o = t.length - 1, n; o >= 0; o--)
|
|
32
|
-
(n = t[o]) && (s = n(s) || s);
|
|
33
|
-
return s;
|
|
34
|
-
}, w = (t, e) => (a, r) => e(a, r, t);
|
|
35
|
-
let m = class extends y {
|
|
36
|
-
constructor(t) {
|
|
37
|
-
super(t, "storage.components.fileSystemStorage");
|
|
38
|
-
}
|
|
39
|
-
getEditField() {
|
|
40
|
-
return Promise.resolve("");
|
|
41
|
-
}
|
|
42
|
-
getImageURL() {
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
async getPageContent(t) {
|
|
46
|
-
const e = decodeURI(t), a = await fileSystemStorage.resolvePath(e), r = await fileSystemStorage.readPage(a || "");
|
|
47
|
-
return r && (r.id = e, r.headline = r.name, r.headlineRaw = r.name), r;
|
|
48
|
-
}
|
|
49
|
-
async getAttachments(t) {
|
|
50
|
-
const e = await fileSystemStorage.resolveAttachmentsPath(t);
|
|
51
|
-
return {
|
|
52
|
-
attachments: await fileSystemStorage.readAttachments(e)
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
async getAttachment(t, e) {
|
|
56
|
-
const a = await fileSystemStorage.resolveAttachmentPath(t, e);
|
|
57
|
-
return fileSystemStorage.readAttachment(a);
|
|
58
|
-
}
|
|
59
|
-
getPageFromViewURL() {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
getPageRestURL() {
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
getPanelContent() {
|
|
66
|
-
return Promise.resolve(new u());
|
|
67
|
-
}
|
|
68
|
-
isStorageReady() {
|
|
69
|
-
return Promise.resolve(!0);
|
|
70
|
-
}
|
|
71
|
-
async save(t, e, a) {
|
|
72
|
-
const r = await fileSystemStorage.resolvePath(t);
|
|
73
|
-
await fileSystemStorage.savePage(r, a, e);
|
|
74
|
-
}
|
|
75
|
-
async saveAttachments(t, e) {
|
|
76
|
-
await Promise.all(e.map((a) => this.saveAttachment(t, a)));
|
|
77
|
-
}
|
|
78
|
-
async delete(t) {
|
|
79
|
-
try {
|
|
80
|
-
return await fileSystemStorage.deletePage(t), { success: !0 };
|
|
81
|
-
} catch (e) {
|
|
82
|
-
return { success: !1, error: e.message };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async move(t, e, a) {
|
|
86
|
-
try {
|
|
87
|
-
return await fileSystemStorage.movePage(t, e, a), { success: !0 };
|
|
88
|
-
} catch (r) {
|
|
89
|
-
return { success: !1, error: r.message };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async saveAttachment(t, e) {
|
|
93
|
-
const a = await fileSystemStorage.resolveAttachmentPath(t, e.name);
|
|
94
|
-
await fileSystemStorage.saveAttachment(a, e);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
m = P([
|
|
98
|
-
c(),
|
|
99
|
-
w(0, g("Logger"))
|
|
100
|
-
], m);
|
|
101
|
-
class b {
|
|
102
|
-
logger;
|
|
103
|
-
constructor(e) {
|
|
104
|
-
this.logger = e.get("Logger"), this.logger.setModule("electron.storage.components.componentsInit"), this.logger?.debug("Init Sample Module components begin"), e.bind("WikiConfig").to(l).when(d("FileSystem")), e.bind("Storage").to(m).whenNamed("FileSystem"), this.logger?.debug("Init Sample Module components end");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export {
|
|
108
|
-
b as ComponentInit
|
|
109
|
-
};
|
|
110
|
-
//# sourceMappingURL=index.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../../src/components/FileSystemConfig.ts","../../src/components/fileSystemStorage.ts","../../src/componentsInit.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { DefaultWikiConfig } from \"@xwiki/platform-api\";\nimport { inject, injectable, named } from \"inversify\";\nimport type { APITypes } from \"../electron/preload/apiTypes\";\nimport type { CristalApp, Logger, Storage } from \"@xwiki/platform-api\";\n\ndeclare const fileSystemStorage: APITypes;\n\n@injectable()\nexport class FileSystemConfig extends DefaultWikiConfig {\n override storage: Storage;\n override cristal: CristalApp;\n constructor(\n @inject(\"Logger\") logger: Logger,\n @inject(\"Storage\") @named(\"FileSystem\") storage: Storage,\n @inject(\"CristalApp\") cristal: CristalApp,\n ) {\n super(logger);\n this.storage = storage;\n this.cristal = cristal;\n this.storage.setWikiConfig(this);\n if (this.homePage === \"\") {\n this.homePage = \"index.md\";\n }\n }\n\n override getType(): string {\n return \"FileSystem\";\n }\n\n override initialize(): void {\n super.initialize();\n // The initialization for the root directory needs to be done after a\n // configuration change, but before any storage operation.\n fileSystemStorage.initRootDirectory();\n }\n}\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { DefaultPageData } from \"@xwiki/platform-api\";\nimport { AbstractStorage } from \"@xwiki/platform-backend-api\";\nimport { inject, injectable } from \"inversify\";\nimport type { APITypes } from \"../electron/preload/apiTypes\";\nimport type {\n AttachmentsData,\n Logger,\n PageAttachment,\n PageData,\n} from \"@xwiki/platform-api\";\n\ndeclare const fileSystemStorage: APITypes;\n\n@injectable()\nexport default class FileSystemStorage extends AbstractStorage {\n constructor(@inject(\"Logger\") logger: Logger) {\n super(logger, \"storage.components.fileSystemStorage\");\n }\n\n getEditField(): Promise<string> {\n return Promise.resolve(\"\");\n }\n\n getImageURL(): string {\n return \"\";\n }\n\n async getPageContent(page: string): Promise<PageData> {\n const decodedPage = decodeURI(page);\n const path = await fileSystemStorage.resolvePath(decodedPage);\n const pageData = await fileSystemStorage.readPage(path || \"\");\n if (pageData) {\n pageData.id = decodedPage;\n pageData.headline = pageData.name;\n pageData.headlineRaw = pageData.name;\n }\n return pageData;\n }\n\n async getAttachments(page: string): Promise<AttachmentsData | undefined> {\n const path = await fileSystemStorage.resolveAttachmentsPath(page);\n return {\n attachments: await fileSystemStorage.readAttachments(path),\n };\n }\n\n async getAttachment(\n page: string,\n name: string,\n ): Promise<PageAttachment | undefined> {\n const path = await fileSystemStorage.resolveAttachmentPath(page, name);\n return fileSystemStorage.readAttachment(path);\n }\n\n getPageFromViewURL(): string | null {\n return null;\n }\n\n getPageRestURL(): string {\n return \"\";\n }\n\n getPanelContent(): Promise<PageData> {\n return Promise.resolve(new DefaultPageData());\n }\n\n isStorageReady(): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n async save(page: string, title: string, content: string): Promise<void> {\n const path = await fileSystemStorage.resolvePath(page);\n await fileSystemStorage.savePage(path, content, title);\n }\n\n async saveAttachments(\n page: string,\n files: File[],\n ): Promise<undefined | (undefined | string)[]> {\n await Promise.all(files.map((file) => this.saveAttachment(page, file)));\n return undefined;\n }\n\n async delete(page: string): Promise<{ success: boolean; error?: string }> {\n try {\n await fileSystemStorage.deletePage(page);\n return { success: true };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async move(\n page: string,\n newPage: string,\n preserveChildren: boolean,\n ): Promise<{ success: boolean; error?: string }> {\n try {\n await fileSystemStorage.movePage(page, newPage, preserveChildren);\n return { success: true };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n private async saveAttachment(page: string, file: File): Promise<unknown> {\n const path = await fileSystemStorage.resolveAttachmentPath(page, file.name);\n await fileSystemStorage.saveAttachment(path, file);\n return;\n }\n}\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { FileSystemConfig } from \"./components/FileSystemConfig\";\nimport FileSystemStorage from \"./components/fileSystemStorage\";\nimport { whenNamedOrDefault } from \"@xwiki/cristal-utils-inversify\";\nimport type { Logger, Storage, WikiConfig } from \"@xwiki/platform-api\";\nimport type { Container } from \"inversify\";\n\n/**\n * @beta\n */\nexport default class ComponentInit {\n logger: Logger;\n\n constructor(container: Container) {\n this.logger = container.get<Logger>(\"Logger\");\n this.logger.setModule(\"electron.storage.components.componentsInit\");\n\n this.logger?.debug(\"Init Sample Module components begin\");\n container\n .bind<WikiConfig>(\"WikiConfig\")\n .to(FileSystemConfig)\n .when(whenNamedOrDefault(\"FileSystem\"));\n container\n .bind<Storage>(\"Storage\")\n .to(FileSystemStorage)\n .whenNamed(\"FileSystem\");\n this.logger?.debug(\"Init Sample Module components end\");\n }\n}\n"],"names":["FileSystemConfig","DefaultWikiConfig","logger","storage","cristal","__decorateClass","injectable","__decorateParam","FileSystemStorage","AbstractStorage","page","decodedPage","path","pageData","name","DefaultPageData","title","content","files","file","error","newPage","preserveChildren","ComponentInit","container","whenNamedOrDefault"],"mappings":";;;;;;;;;AA4BO,IAAMA,IAAN,cAA+BC,EAAkB;AAAA,EAC7C;AAAA,EACA;AAAA,EACT,YACoBC,GACsBC,GAClBC,GACtB;AACA,UAAMF,CAAM,GACZ,KAAK,UAAUC,GACf,KAAK,UAAUC,GACf,KAAK,QAAQ,cAAc,IAAI,GAC3B,KAAK,aAAa,OACpB,KAAK,WAAW;AAAA,EAEpB;AAAA,EAES,UAAkB;AACzB,WAAO;AAAA,EACT;AAAA,EAES,aAAmB;AAC1B,UAAM,WAAA,GAGN,kBAAkB,kBAAA;AAAA,EACpB;AACF;AA3BaJ,IAANK,EAAA;AAAA,EADNC,EAAA;AAAA,EAKIC,OAAO,QAAQ,CAAA;AAAA,EACfA,OAAO,SAAS,CAAA;AAAA,EAAGA,OAAM,YAAY,CAAA;AAAA,EACrCA,OAAO,YAAY,CAAA;AAAA,GANXP,CAAA;;;;;;ACMb,IAAqBQ,IAArB,cAA+CC,EAAgB;AAAA,EAC7D,YAA8BP,GAAgB;AAC5C,UAAMA,GAAQ,sCAAsC;AAAA,EACtD;AAAA,EAEA,eAAgC;AAC9B,WAAO,QAAQ,QAAQ,EAAE;AAAA,EAC3B;AAAA,EAEA,cAAsB;AACpB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,eAAeQ,GAAiC;AACpD,UAAMC,IAAc,UAAUD,CAAI,GAC5BE,IAAO,MAAM,kBAAkB,YAAYD,CAAW,GACtDE,IAAW,MAAM,kBAAkB,SAASD,KAAQ,EAAE;AAC5D,WAAIC,MACFA,EAAS,KAAKF,GACdE,EAAS,WAAWA,EAAS,MAC7BA,EAAS,cAAcA,EAAS,OAE3BA;AAAA,EACT;AAAA,EAEA,MAAM,eAAeH,GAAoD;AACvE,UAAME,IAAO,MAAM,kBAAkB,uBAAuBF,CAAI;AAChE,WAAO;AAAA,MAC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AMS,EAAK,IAAI;AAC1E,UAAM,kBAAkB,eAAeP,GAAMO,CAAI;AAAA,EAEnD;AACF;AAhGqBX,IAArBH,EAAA;AAAA,EADCC,EAAA;AAAA,EAEcC,OAAO,QAAQ,CAAA;AAAA,GADTC,CAAA;ACLrB,MAAqBe,EAAc;AAAA,EACjC;AAAA,EAEA,YAAYC,GAAsB;AAChC,SAAK,SAASA,EAAU,IAAY,QAAQ,GAC5C,KAAK,OAAO,UAAU,4CAA4C,GAElE,KAAK,QAAQ,MAAM,qCAAqC,GACxDA,EACG,KAAiB,YAAY,EAC7B,GAAGxB,CAAgB,EACnB,KAAKyB,EAAmB,YAAY,CAAC,GACxCD,EACG,KAAc,SAAS,EACvB,GAAGhB,CAAiB,EACpB,UAAU,YAAY,GACzB,KAAK,QAAQ,MAAM,mCAAmC;AAAA,EACxD;AACF;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@xwiki/platform-api"),require("inversify"),require("@xwiki/platform-backend-api"),require("@xwiki/cristal-utils-inversify")):typeof define=="function"&&define.amd?define(["exports","@xwiki/platform-api","inversify","@xwiki/platform-backend-api","@xwiki/cristal-utils-inversify"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.cristal_storage={},s.platformApi,s.inversify,s.platformBackendApi,s.cristalUtilsInversify))})(this,(function(s,c,n,h,d){"use strict";var f=Object.getOwnPropertyDescriptor,p=(t,e,a,r)=>{for(var i=r>1?void 0:r?f(e,a):e,o=t.length-1,l;o>=0;o--)(l=t[o])&&(i=l(i)||i);return i},g=(t,e)=>(a,r)=>e(a,r,t);let m=class extends c.DefaultWikiConfig{storage;cristal;constructor(t,e,a){super(t),this.storage=e,this.cristal=a,this.storage.setWikiConfig(this),this.homePage===""&&(this.homePage="index.md")}getType(){return"FileSystem"}initialize(){super.initialize(),fileSystemStorage.initRootDirectory()}};m=p([n.injectable(),g(0,n.inject("Logger")),g(1,n.inject("Storage")),g(1,n.named("FileSystem")),g(2,n.inject("CristalApp"))],m);var S=Object.getOwnPropertyDescriptor,y=(t,e,a,r)=>{for(var i=r>1?void 0:r?S(e,a):e,o=t.length-1,l;o>=0;o--)(l=t[o])&&(i=l(i)||i);return i},v=(t,e)=>(a,r)=>e(a,r,t);let u=class extends h.AbstractStorage{constructor(t){super(t,"storage.components.fileSystemStorage")}getEditField(){return Promise.resolve("")}getImageURL(){return""}async getPageContent(t){const e=decodeURI(t),a=await fileSystemStorage.resolvePath(e),r=await fileSystemStorage.readPage(a||"");return r&&(r.id=e,r.headline=r.name,r.headlineRaw=r.name),r}async getAttachments(t){const e=await fileSystemStorage.resolveAttachmentsPath(t);return{attachments:await fileSystemStorage.readAttachments(e)}}async getAttachment(t,e){const a=await fileSystemStorage.resolveAttachmentPath(t,e);return fileSystemStorage.readAttachment(a)}getPageFromViewURL(){return null}getPageRestURL(){return""}getPanelContent(){return Promise.resolve(new c.DefaultPageData)}isStorageReady(){return Promise.resolve(!0)}async save(t,e,a){const r=await fileSystemStorage.resolvePath(t);await fileSystemStorage.savePage(r,a,e)}async saveAttachments(t,e){await Promise.all(e.map(a=>this.saveAttachment(t,a)))}async delete(t){try{return await fileSystemStorage.deletePage(t),{success:!0}}catch(e){return{success:!1,error:e.message}}}async move(t,e,a){try{return await fileSystemStorage.movePage(t,e,a),{success:!0}}catch(r){return{success:!1,error:r.message}}}async saveAttachment(t,e){const a=await fileSystemStorage.resolveAttachmentPath(t,e.name);await fileSystemStorage.saveAttachment(a,e)}};u=y([n.injectable(),v(0,n.inject("Logger"))],u);class w{logger;constructor(e){this.logger=e.get("Logger"),this.logger.setModule("electron.storage.components.componentsInit"),this.logger?.debug("Init Sample Module components begin"),e.bind("WikiConfig").to(m).when(d.whenNamedOrDefault("FileSystem")),e.bind("Storage").to(u).whenNamed("FileSystem"),this.logger?.debug("Init Sample Module components end")}}s.ComponentInit=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
|
2
|
-
//# sourceMappingURL=index.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../../src/components/FileSystemConfig.ts","../../src/components/fileSystemStorage.ts","../../src/componentsInit.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { DefaultWikiConfig } from \"@xwiki/platform-api\";\nimport { inject, injectable, named } from \"inversify\";\nimport type { APITypes } from \"../electron/preload/apiTypes\";\nimport type { CristalApp, Logger, Storage } from \"@xwiki/platform-api\";\n\ndeclare const fileSystemStorage: APITypes;\n\n@injectable()\nexport class FileSystemConfig extends DefaultWikiConfig {\n override storage: Storage;\n override cristal: CristalApp;\n constructor(\n @inject(\"Logger\") logger: Logger,\n @inject(\"Storage\") @named(\"FileSystem\") storage: Storage,\n @inject(\"CristalApp\") cristal: CristalApp,\n ) {\n super(logger);\n this.storage = storage;\n this.cristal = cristal;\n this.storage.setWikiConfig(this);\n if (this.homePage === \"\") {\n this.homePage = \"index.md\";\n }\n }\n\n override getType(): string {\n return \"FileSystem\";\n }\n\n override initialize(): void {\n super.initialize();\n // The initialization for the root directory needs to be done after a\n // configuration change, but before any storage operation.\n fileSystemStorage.initRootDirectory();\n }\n}\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { DefaultPageData } from \"@xwiki/platform-api\";\nimport { AbstractStorage } from \"@xwiki/platform-backend-api\";\nimport { inject, injectable } from \"inversify\";\nimport type { APITypes } from \"../electron/preload/apiTypes\";\nimport type {\n AttachmentsData,\n Logger,\n PageAttachment,\n PageData,\n} from \"@xwiki/platform-api\";\n\ndeclare const fileSystemStorage: APITypes;\n\n@injectable()\nexport default class FileSystemStorage extends AbstractStorage {\n constructor(@inject(\"Logger\") logger: Logger) {\n super(logger, \"storage.components.fileSystemStorage\");\n }\n\n getEditField(): Promise<string> {\n return Promise.resolve(\"\");\n }\n\n getImageURL(): string {\n return \"\";\n }\n\n async getPageContent(page: string): Promise<PageData> {\n const decodedPage = decodeURI(page);\n const path = await fileSystemStorage.resolvePath(decodedPage);\n const pageData = await fileSystemStorage.readPage(path || \"\");\n if (pageData) {\n pageData.id = decodedPage;\n pageData.headline = pageData.name;\n pageData.headlineRaw = pageData.name;\n }\n return pageData;\n }\n\n async getAttachments(page: string): Promise<AttachmentsData | undefined> {\n const path = await fileSystemStorage.resolveAttachmentsPath(page);\n return {\n attachments: await fileSystemStorage.readAttachments(path),\n };\n }\n\n async getAttachment(\n page: string,\n name: string,\n ): Promise<PageAttachment | undefined> {\n const path = await fileSystemStorage.resolveAttachmentPath(page, name);\n return fileSystemStorage.readAttachment(path);\n }\n\n getPageFromViewURL(): string | null {\n return null;\n }\n\n getPageRestURL(): string {\n return \"\";\n }\n\n getPanelContent(): Promise<PageData> {\n return Promise.resolve(new DefaultPageData());\n }\n\n isStorageReady(): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n async save(page: string, title: string, content: string): Promise<void> {\n const path = await fileSystemStorage.resolvePath(page);\n await fileSystemStorage.savePage(path, content, title);\n }\n\n async saveAttachments(\n page: string,\n files: File[],\n ): Promise<undefined | (undefined | string)[]> {\n await Promise.all(files.map((file) => this.saveAttachment(page, file)));\n return undefined;\n }\n\n async delete(page: string): Promise<{ success: boolean; error?: string }> {\n try {\n await fileSystemStorage.deletePage(page);\n return { success: true };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async move(\n page: string,\n newPage: string,\n preserveChildren: boolean,\n ): Promise<{ success: boolean; error?: string }> {\n try {\n await fileSystemStorage.movePage(page, newPage, preserveChildren);\n return { success: true };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n private async saveAttachment(page: string, file: File): Promise<unknown> {\n const path = await fileSystemStorage.resolveAttachmentPath(page, file.name);\n await fileSystemStorage.saveAttachment(path, file);\n return;\n }\n}\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { FileSystemConfig } from \"./components/FileSystemConfig\";\nimport FileSystemStorage from \"./components/fileSystemStorage\";\nimport { whenNamedOrDefault } from \"@xwiki/cristal-utils-inversify\";\nimport type { Logger, Storage, WikiConfig } from \"@xwiki/platform-api\";\nimport type { Container } from \"inversify\";\n\n/**\n * @beta\n */\nexport default class ComponentInit {\n logger: Logger;\n\n constructor(container: Container) {\n this.logger = container.get<Logger>(\"Logger\");\n this.logger.setModule(\"electron.storage.components.componentsInit\");\n\n this.logger?.debug(\"Init Sample Module components begin\");\n container\n .bind<WikiConfig>(\"WikiConfig\")\n .to(FileSystemConfig)\n .when(whenNamedOrDefault(\"FileSystem\"));\n container\n .bind<Storage>(\"Storage\")\n .to(FileSystemStorage)\n .whenNamed(\"FileSystem\");\n this.logger?.debug(\"Init Sample Module components end\");\n }\n}\n"],"names":["FileSystemConfig","DefaultWikiConfig","logger","storage","cristal","__decorateClass","injectable","__decorateParam","FileSystemStorage","AbstractStorage","page","decodedPage","path","pageData","name","DefaultPageData","title","content","files","file","error","newPage","preserveChildren","ComponentInit","container","whenNamedOrDefault"],"mappings":"ksBA4BO,IAAMA,EAAN,cAA+BC,EAAAA,iBAAkB,CAC7C,QACA,QACT,YACoBC,EACsBC,EAClBC,EACtB,CACA,MAAMF,CAAM,EACZ,KAAK,QAAUC,EACf,KAAK,QAAUC,EACf,KAAK,QAAQ,cAAc,IAAI,EAC3B,KAAK,WAAa,KACpB,KAAK,SAAW,WAEpB,CAES,SAAkB,CACzB,MAAO,YACT,CAES,YAAmB,CAC1B,MAAM,WAAA,EAGN,kBAAkB,kBAAA,CACpB,CACF,EA3BaJ,EAANK,EAAA,CADNC,aAAA,EAKIC,aAAO,QAAQ,CAAA,EACfA,aAAO,SAAS,CAAA,EAAGA,YAAM,YAAY,CAAA,EACrCA,aAAO,YAAY,CAAA,CAAA,EANXP,CAAA,uKCMb,IAAqBQ,EAArB,cAA+CC,EAAAA,eAAgB,CAC7D,YAA8BP,EAAgB,CAC5C,MAAMA,EAAQ,sCAAsC,CACtD,CAEA,cAAgC,CAC9B,OAAO,QAAQ,QAAQ,EAAE,CAC3B,CAEA,aAAsB,CACpB,MAAO,EACT,CAEA,MAAM,eAAeQ,EAAiC,CACpD,MAAMC,EAAc,U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CACd,MAAO,CAAE,QAAS,GAAO,MAAQA,EAAgB,OAAA,CACnD,CACF,CAEA,MAAc,eAAeV,EAAcS,EAA8B,CACvE,MAAMP,EAAO,MAAM,kBAAkB,sBAAsBF,EAAMS,EAAK,IAAI,EAC1E,MAAM,kBAAkB,eAAeP,EAAMO,CAAI,CAEnD,CACF,EAhGqBX,EAArBH,EAAA,CADCC,aAAA,EAEcC,aAAO,QAAQ,CAAA,CAAA,EADTC,CAAA,ECLrB,MAAqBe,CAAc,CACjC,OAEA,YAAYC,EAAsB,CAChC,KAAK,OAASA,EAAU,IAAY,QAAQ,EAC5C,KAAK,OAAO,UAAU,4CAA4C,EAElE,KAAK,QAAQ,MAAM,qCAAqC,EACxDA,EACG,KAAiB,YAAY,EAC7B,GAAGxB,CAAgB,EACnB,KAAKyB,qBAAmB,YAAY,CAAC,EACxCD,EACG,KAAc,SAAS,EACvB,GAAGhB,CAAiB,EACpB,UAAU,YAAY,EACzB,KAAK,QAAQ,MAAM,mCAAmC,CACxD,CACF"}
|
package/dist/main/index.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See the LICENSE file distributed with this work for additional
|
|
3
|
-
* information regarding copyright ownership.
|
|
4
|
-
*
|
|
5
|
-
* This is free software; you can redistribute it and/or modify it
|
|
6
|
-
* under the terms of the GNU Lesser General Public License as
|
|
7
|
-
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
-
* the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This software is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this software; if not, write to the Free
|
|
17
|
-
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
-
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
-
*/
|
|
20
|
-
export default function load(): Promise<void>;
|
package/dist/main/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See the LICENSE file distributed with this work for additional
|
|
3
|
-
* information regarding copyright ownership.
|
|
4
|
-
*
|
|
5
|
-
* This is free software; you can redistribute it and/or modify it
|
|
6
|
-
* under the terms of the GNU Lesser General Public License as
|
|
7
|
-
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
-
* the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This software is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this software; if not, write to the Free
|
|
17
|
-
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
-
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
-
*/
|
|
20
|
-
export default function load(): Promise<void>;
|
package/dist/main/index.es.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { getStorageRoot as W } from "@xwiki/cristal-electron-state";
|
|
2
|
-
import { protocol as A } from "@xwiki/cristal-model-remote-url-filesystem-api";
|
|
3
|
-
import { DefaultPageReader as M, DefaultPageWriter as b } from "@xwiki/cristal-page-default";
|
|
4
|
-
import { LinkType as D } from "@xwiki/platform-link-suggest-api";
|
|
5
|
-
import { EntityType as S } from "@xwiki/platform-model-api";
|
|
6
|
-
import { app as j, ipcMain as l, protocol as L, net as O, shell as T } from "electron";
|
|
7
|
-
import x from "mime";
|
|
8
|
-
import o from "node:fs";
|
|
9
|
-
import { readdir as _ } from "node:fs/promises";
|
|
10
|
-
import U from "node:os";
|
|
11
|
-
import { join as u, relative as p, dirname as d, basename as h } from "node:path";
|
|
12
|
-
const z = ".cristal", G = u(j.getPath("home"), z);
|
|
13
|
-
function m() {
|
|
14
|
-
return W() ?? G;
|
|
15
|
-
}
|
|
16
|
-
function f(t, ...e) {
|
|
17
|
-
return u(m(), t, ...e);
|
|
18
|
-
}
|
|
19
|
-
function R(t) {
|
|
20
|
-
return f(`${t}.md`);
|
|
21
|
-
}
|
|
22
|
-
function Y(t) {
|
|
23
|
-
const e = t.split("/");
|
|
24
|
-
return e.length == 1 ? `.${t}` : `${e.slice(0, e.length - 1).join("/")}/.${e[e.length - 1]}`;
|
|
25
|
-
}
|
|
26
|
-
function g(t) {
|
|
27
|
-
return f(Y(t));
|
|
28
|
-
}
|
|
29
|
-
function H(t) {
|
|
30
|
-
return u(g(t), "attachments");
|
|
31
|
-
}
|
|
32
|
-
function q(t, e) {
|
|
33
|
-
return u(H(t), e);
|
|
34
|
-
}
|
|
35
|
-
async function w(t) {
|
|
36
|
-
let e;
|
|
37
|
-
try {
|
|
38
|
-
e = await o.promises.lstat(t);
|
|
39
|
-
} catch (n) {
|
|
40
|
-
console.debug(n);
|
|
41
|
-
}
|
|
42
|
-
return e?.isFile();
|
|
43
|
-
}
|
|
44
|
-
function B(t, e) {
|
|
45
|
-
const n = x.getType(t);
|
|
46
|
-
if (!n)
|
|
47
|
-
return !1;
|
|
48
|
-
const [a, i] = n.split("/"), [s, c] = e.split("/");
|
|
49
|
-
return (s == "*" || s == a) && (c == "*" || c == i);
|
|
50
|
-
}
|
|
51
|
-
async function $(t, e) {
|
|
52
|
-
if (!await w(t))
|
|
53
|
-
return !1;
|
|
54
|
-
const n = h(d(t)) == "attachments";
|
|
55
|
-
return n && e ? B(t, e) : n;
|
|
56
|
-
}
|
|
57
|
-
async function v(t) {
|
|
58
|
-
if (!await w(t))
|
|
59
|
-
return !1;
|
|
60
|
-
const e = m(), n = p(e, t), a = d(n), i = d(a), s = h(a), c = h(i);
|
|
61
|
-
return s != "attachments" && (!c.startsWith(".") || s === "." || c === ".");
|
|
62
|
-
}
|
|
63
|
-
async function P(t) {
|
|
64
|
-
let e;
|
|
65
|
-
try {
|
|
66
|
-
e = await o.promises.lstat(t);
|
|
67
|
-
} catch (n) {
|
|
68
|
-
console.debug(n);
|
|
69
|
-
}
|
|
70
|
-
return e?.isDirectory();
|
|
71
|
-
}
|
|
72
|
-
async function J(t) {
|
|
73
|
-
return (await o.promises.readdir(t)).length == 0;
|
|
74
|
-
}
|
|
75
|
-
async function k(t) {
|
|
76
|
-
try {
|
|
77
|
-
await o.promises.lstat(t);
|
|
78
|
-
} catch {
|
|
79
|
-
return !1;
|
|
80
|
-
}
|
|
81
|
-
return !0;
|
|
82
|
-
}
|
|
83
|
-
async function E(t) {
|
|
84
|
-
const e = m();
|
|
85
|
-
if (!await y(e, t))
|
|
86
|
-
throw new Error(`[${t}] is not in in [${e}]`);
|
|
87
|
-
if (await w(t)) {
|
|
88
|
-
const n = await o.promises.readFile(t), a = await o.promises.stat(t), i = n.toString("utf8"), s = new M().readPage(i), c = p(e, t).replace(/.md$/, "");
|
|
89
|
-
return {
|
|
90
|
-
type: S.DOCUMENT,
|
|
91
|
-
value: {
|
|
92
|
-
...s,
|
|
93
|
-
source: s.content,
|
|
94
|
-
syntax: "markdown/1.2",
|
|
95
|
-
lastAuthor: { name: U.userInfo().username },
|
|
96
|
-
lastModificationDate: new Date(a.mtimeMs),
|
|
97
|
-
id: c,
|
|
98
|
-
canEdit: !0
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
} else
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
async function K(t) {
|
|
105
|
-
const e = m();
|
|
106
|
-
if (!await y(e, t))
|
|
107
|
-
throw new Error(`[${t}] is not in in [${e}]`);
|
|
108
|
-
if (await P(t)) {
|
|
109
|
-
const n = await o.promises.readdir(t);
|
|
110
|
-
return (await Promise.all(
|
|
111
|
-
n.map((a) => F(u(t, a)))
|
|
112
|
-
)).filter((a) => a !== void 0).map((a) => a.value);
|
|
113
|
-
} else
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
async function F(t) {
|
|
117
|
-
const e = m();
|
|
118
|
-
if (!await y(e, t))
|
|
119
|
-
throw new Error(`[${t}] is not in in [${e}]`);
|
|
120
|
-
if (await w(t)) {
|
|
121
|
-
const n = await o.promises.stat(t), a = x.getType(t) ?? "", i = d(d(t)), s = h(i), c = d(i), r = h(t);
|
|
122
|
-
return {
|
|
123
|
-
type: S.ATTACHMENT,
|
|
124
|
-
value: {
|
|
125
|
-
id: r,
|
|
126
|
-
mimetype: a,
|
|
127
|
-
reference: p(
|
|
128
|
-
e,
|
|
129
|
-
u(c, s, "attachments", r)
|
|
130
|
-
),
|
|
131
|
-
href: `${A}://${p(
|
|
132
|
-
e,
|
|
133
|
-
u(c, s, "attachments", r)
|
|
134
|
-
)}`,
|
|
135
|
-
date: n.mtime,
|
|
136
|
-
size: n.size,
|
|
137
|
-
author: void 0
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
} else
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
async function y(t, e) {
|
|
144
|
-
const n = p(t, e);
|
|
145
|
-
return !n.startsWith("../") && n !== "..";
|
|
146
|
-
}
|
|
147
|
-
async function I(t, e, n) {
|
|
148
|
-
const a = m();
|
|
149
|
-
if (!await y(a, t))
|
|
150
|
-
throw new Error(`[${t}] is not in in [${a}]`);
|
|
151
|
-
let i;
|
|
152
|
-
if (await k(t) && await w(t)) {
|
|
153
|
-
const r = await o.promises.readFile(t), N = new TextDecoder("utf-8");
|
|
154
|
-
i = new M().readPage(N.decode(r)), i.content = e, i.name = n;
|
|
155
|
-
} else
|
|
156
|
-
i = {
|
|
157
|
-
name: n,
|
|
158
|
-
content: e
|
|
159
|
-
};
|
|
160
|
-
const s = new b().writePage(i), c = d(t);
|
|
161
|
-
return await o.promises.mkdir(c, { recursive: !0 }), await o.promises.writeFile(t, s, { flag: "w+" }), (await E(t))?.value;
|
|
162
|
-
}
|
|
163
|
-
async function Q(t, e) {
|
|
164
|
-
const n = m();
|
|
165
|
-
if (!await y(n, t))
|
|
166
|
-
throw new Error(`[${t}] is not in in [${n}]`);
|
|
167
|
-
const a = d(t);
|
|
168
|
-
await o.promises.mkdir(a, { recursive: !0 }), await o.promises.copyFile(e, t);
|
|
169
|
-
}
|
|
170
|
-
function V(t) {
|
|
171
|
-
return t.includes(".") ? t.slice(0, t.lastIndexOf(".")) : t;
|
|
172
|
-
}
|
|
173
|
-
async function X(t, e) {
|
|
174
|
-
const n = await o.promises.readdir(t);
|
|
175
|
-
for (const a of n) {
|
|
176
|
-
if (a.startsWith("."))
|
|
177
|
-
continue;
|
|
178
|
-
const i = u(t, a);
|
|
179
|
-
await w(i) ? e.add(V(a)) : await P(i) && e.add(a);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
async function Z(t) {
|
|
183
|
-
const e = f(t), n = /* @__PURE__ */ new Set();
|
|
184
|
-
return await P(e) && await X(e, n), Array.from(n);
|
|
185
|
-
}
|
|
186
|
-
async function tt(t) {
|
|
187
|
-
const e = [], n = `${f(t)}.md`;
|
|
188
|
-
await w(n) && e.push(T.trashItem(n));
|
|
189
|
-
const a = g(t);
|
|
190
|
-
await P(a) && e.push(T.trashItem(a)), await Promise.all(e);
|
|
191
|
-
}
|
|
192
|
-
async function C(t, e) {
|
|
193
|
-
const n = await Promise.all(t.map(e));
|
|
194
|
-
return t.filter((a, i) => n[i]);
|
|
195
|
-
}
|
|
196
|
-
async function et(t, e, n) {
|
|
197
|
-
const a = m(), i = (await _(a, { recursive: !0 })).map(
|
|
198
|
-
(r) => u(a, r)
|
|
199
|
-
), s = await C(i, async (r) => e == D.ATTACHMENT ? $(r, n) : e == D.PAGE ? v(r) : await $(r, n) || await v(r)), c = await C(s, async (r) => await $(r) ? h(r).includes(t) : await v(r) ? h(d(r)).includes(t) : !1);
|
|
200
|
-
return (await Promise.all(
|
|
201
|
-
c.map(async (r) => await v(r) ? E(r) : F(r))
|
|
202
|
-
)).filter((r) => r !== void 0);
|
|
203
|
-
}
|
|
204
|
-
async function nt() {
|
|
205
|
-
await I(
|
|
206
|
-
u(m(), "index.md"),
|
|
207
|
-
`# Welcome
|
|
208
|
-
|
|
209
|
-
This is a new **Cristal** wiki.
|
|
210
|
-
|
|
211
|
-
You can use it to take your *own* notes.
|
|
212
|
-
|
|
213
|
-
You can also create new [pages](index/newpage).
|
|
214
|
-
|
|
215
|
-
Enjoy!`,
|
|
216
|
-
""
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
async function at(t, e, n) {
|
|
220
|
-
const a = `${f(t)}`, i = `${f(e)}`;
|
|
221
|
-
await P(a) && n.push(o.promises.rename(a, i));
|
|
222
|
-
}
|
|
223
|
-
async function rt(t, e, n) {
|
|
224
|
-
const a = `${f(t)}.md`, i = g(t), s = `${f(e)}.md`, c = g(e), r = [];
|
|
225
|
-
await w(a) && r.push(o.promises.rename(a, s)), await P(i) && r.push(o.promises.rename(i, c)), n && await at(t, e, r), await Promise.all(r);
|
|
226
|
-
}
|
|
227
|
-
async function Pt() {
|
|
228
|
-
l.on("initRootDirectory", async () => {
|
|
229
|
-
const t = m();
|
|
230
|
-
(!await k(t) || await P(t) && await J(t)) && await nt();
|
|
231
|
-
}), L.handle(A, async (t) => {
|
|
232
|
-
const e = m(), n = u(
|
|
233
|
-
e,
|
|
234
|
-
t.url.substring(`${A}://`.length)
|
|
235
|
-
);
|
|
236
|
-
if (!await y(e, n))
|
|
237
|
-
throw new Error(`[${n}] is not in in [${e}]`);
|
|
238
|
-
return O.fetch(`file://${decodeURIComponent(n)}`);
|
|
239
|
-
}), l.handle("resolvePath", (t, { page: e }) => R(e)), l.handle("resolveAttachmentsPath", (t, { page: e }) => H(e)), l.handle("readPage", async (t, { path: e }) => (await E(e))?.value), l.handle("readAttachments", (t, { path: e }) => K(e)), l.handle("readAttachment", async (t, { path: e }) => (await F(e))?.value), l.handle("savePage", (t, { path: e, content: n, title: a }) => I(e, n, a)), l.handle("resolveAttachmentPath", (t, { page: e, filename: n }) => q(e, n)), l.handle("saveAttachment", (t, { path: e, filePath: n }) => Q(e, n)), l.handle("listChildren", (t, { page: e }) => Z(e)), l.handle("deletePage", (t, { path: e }) => tt(e)), l.handle("search", (t, { query: e, type: n, mimetype: a }) => et(e, n, a)), l.handle(
|
|
240
|
-
"movePage",
|
|
241
|
-
(t, { reference: e, newReference: n, preserveChildren: a }) => rt(e, n, a)
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
export {
|
|
245
|
-
Pt as default
|
|
246
|
-
};
|
|
247
|
-
//# sourceMappingURL=index.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../../src/electron/main/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { getStorageRoot } from \"@xwiki/cristal-electron-state\";\nimport { protocol as cristalFSProtocol } from \"@xwiki/cristal-model-remote-url-filesystem-api\";\nimport {\n DefaultPageReader,\n DefaultPageWriter,\n} from \"@xwiki/cristal-page-default\";\nimport { LinkType } from \"@xwiki/platform-link-suggest-api\";\nimport { EntityType } from \"@xwiki/platform-model-api\";\nimport { app, ipcMain, net, protocol, shell } from \"electron\";\nimport mime from \"mime\";\nimport fs from \"node:fs\";\nimport { readdir } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport { basename, dirname, join, relative } from \"node:path\";\nimport type { PageAttachment, PageData } from \"@xwiki/platform-api\";\n\nconst HOME_PATH = \".cristal\";\nconst HOME_PATH_FULL = join(app.getPath(\"home\"), HOME_PATH);\n\nfunction getHomePathFull(): string {\n // If no custom storage root was provided in the current configuration, we\n // fallback to the folder `${HOME}/.cristal`.\n return getStorageRoot() ?? HOME_PATH_FULL;\n}\n\nfunction resolvePath(page: string, ...lastSegments: string[]) {\n return join(getHomePathFull(), page, ...lastSegments);\n}\n\nfunction resolvePagePath(page: string): string {\n return resolvePath(`${page}.md`);\n}\n\nfunction makeLastSegmentHidden(page: string) {\n const segments = page.split(\"/\");\n // Add a dot after the last segment of the page path\n if (segments.length == 1) {\n return `.${page}`;\n } else {\n const joined = segments.slice(0, segments.length - 1).join(\"/\");\n return `${joined}/.${segments[segments.length - 1]}`;\n }\n}\n\nfunction resolveMetaDirectoryPath(page: string) {\n return resolvePath(makeLastSegmentHidden(page));\n}\n\nfunction resolveAttachmentsPath(page: string): string {\n return join(resolveMetaDirectoryPath(page), \"attachments\");\n}\n\nfunction resolveAttachmentPath(page: string, filename: string): string {\n return join(resolveAttachmentsPath(page), filename);\n}\n\nasync function isFile(path: string) {\n let stat = undefined;\n try {\n stat = await fs.promises.lstat(path);\n } catch (e) {\n console.debug(e);\n }\n return stat?.isFile();\n}\n\nfunction hasMimetype(path: string, mimetype: string) {\n const mimetypeFile = mime.getType(path);\n if (!mimetypeFile) {\n return false;\n }\n\n const [p1, p2] = mimetypeFile.split(\"/\");\n const [q1, q2] = mimetype.split(\"/\");\n return (q1 == \"*\" || q1 == p1) && (q2 == \"*\" || q2 == p2);\n}\n\nasync function isAttachment(path: string, mimetype?: string) {\n if (!(await isFile(path))) {\n return false;\n }\n\n const isInAttachmentsDirectory = basename(dirname(path)) == \"attachments\";\n if (isInAttachmentsDirectory && mimetype) {\n return hasMimetype(path, mimetype);\n }\n return isInAttachmentsDirectory;\n}\n\nasync function isPage(pathFull: string) {\n if (!(await isFile(pathFull))) {\n return false;\n }\n\n const homePathFull = getHomePathFull();\n const path = relative(homePathFull, pathFull);\n\n const parentPath = dirname(path);\n const grandParentPath = dirname(parentPath);\n const parentName = basename(parentPath);\n const grandParentName = basename(grandParentPath);\n\n return (\n parentName != \"attachments\" &&\n (!grandParentName.startsWith(\".\") ||\n parentName === \".\" ||\n grandParentName === \".\")\n );\n}\n\nasync function isDirectory(path: string) {\n let stat = undefined;\n try {\n stat = await fs.promises.lstat(path);\n } catch (e) {\n console.debug(e);\n }\n return stat?.isDirectory();\n}\n\nasync function isEmpty(path: string) {\n const readdir = await fs.promises.readdir(path);\n return readdir.length == 0;\n}\n\nasync function pathExists(path: string) {\n try {\n await fs.promises.lstat(path);\n } catch {\n return false;\n }\n return true;\n}\n\n// eslint-disable-next-line max-statements\nasync function readPage(\n path: string,\n): Promise<{ type: EntityType.DOCUMENT; value: PageData } | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n if (await isFile(path)) {\n const pageContent = await fs.promises.readFile(path);\n const pageStats = await fs.promises.stat(path);\n const content = pageContent.toString(\"utf8\");\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const data = new DefaultPageReader().readPage(content) as any;\n\n const id = relative(homePathFull, path).replace(/.md$/, \"\");\n return {\n type: EntityType.DOCUMENT,\n value: {\n ...data,\n source: data.content,\n syntax: \"markdown/1.2\",\n lastAuthor: { name: os.userInfo().username },\n lastModificationDate: new Date(pageStats.mtimeMs),\n id: id,\n canEdit: true,\n },\n };\n } else {\n return undefined;\n }\n}\n\nasync function readAttachments(\n path: string,\n): Promise<PageAttachment[] | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n if (await isDirectory(path)) {\n const attachments = await fs.promises.readdir(path);\n return (\n await Promise.all(\n attachments.map((attachment) => readAttachment(join(path, attachment))),\n )\n )\n .filter((it) => it !== undefined)\n .map((it) => it.value);\n } else {\n return undefined;\n }\n}\n\n// eslint-disable-next-line max-statements\nasync function readAttachment(\n path: string,\n): Promise<{ type: EntityType.ATTACHMENT; value: PageAttachment } | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n\n if (await isFile(path)) {\n const stats = await fs.promises.stat(path);\n const mimetype = mime.getType(path) ?? \"\";\n const grandParentPath = dirname(dirname(path)); // .something\n const grandParentName = basename(grandParentPath);\n const grandGrandParentPath = dirname(grandParentPath); // space\n\n const id = basename(path);\n return {\n type: EntityType.ATTACHMENT,\n value: {\n id: id,\n mimetype,\n reference: relative(\n homePathFull,\n join(grandGrandParentPath, grandParentName, \"attachments\", id),\n ),\n href: `${cristalFSProtocol}://${relative(\n homePathFull,\n join(grandGrandParentPath, grandParentName, \"attachments\", id),\n )}`,\n date: stats.mtime,\n size: stats.size,\n author: undefined,\n },\n };\n } else {\n return undefined;\n }\n}\n\nasync function isWithin(root: string, path: string) {\n const rel = relative(root, path);\n return !rel.startsWith(\"../\") && rel !== \"..\";\n}\n\n/**\n * Note: currently this is more a method to update the content of a page than\n * an actual page save.\n *\n * @param path - the path of the page on the file system\n * @param content - the content of the page\n * @param title - the title of the page\n * @since 0.8\n * @beta\n */\n// TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n// eslint-disable-next-line max-statements\nasync function savePage(\n path: string,\n content: string,\n title: string,\n): Promise<PageData | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n let page: { content: string; [key: string]: unknown };\n if ((await pathExists(path)) && (await isFile(path))) {\n const fileContent = await fs.promises.readFile(path);\n const textDecoder = new TextDecoder(\"utf-8\");\n page = new DefaultPageReader().readPage(textDecoder.decode(fileContent));\n page.content = content;\n page.name = title;\n } else {\n page = {\n name: title,\n content: content,\n };\n }\n\n const newContent = new DefaultPageWriter().writePage(page);\n const parentDirectory = dirname(path);\n // Create the parent directories in case they do not exist.\n await fs.promises.mkdir(parentDirectory, { recursive: true });\n // Set the flag to w+ so that the file is created if it does not already\n // exist, or fully replaced when it does.\n await fs.promises.writeFile(path, newContent, { flag: \"w+\" });\n return (await readPage(path))?.value;\n}\n\nasync function saveAttachment(path: string, filePath: string) {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n const parentDirectory = dirname(path);\n\n // Create the parent directories in case they do not exist.\n await fs.promises.mkdir(parentDirectory, { recursive: true });\n await fs.promises.copyFile(filePath, path);\n}\n\nfunction removeExtension(file: string): string {\n if (!file.includes(\".\")) {\n return file;\n }\n return file.slice(0, file.lastIndexOf(\".\"));\n}\n\nasync function listSingleChild(folderPath: string, children: Set<string>) {\n const files = await fs.promises.readdir(folderPath);\n\n for (const file of files) {\n // Ignore all hidden files.\n if (file.startsWith(\".\")) {\n continue;\n }\n const path = join(folderPath, file);\n if (await isFile(path)) {\n children.add(removeExtension(file));\n } else if (await isDirectory(path)) {\n children.add(file);\n }\n }\n}\n\n/**\n * Get the ids of the children pages for a given page.\n *\n * @param page - the id of the page\n * @returns a list of page ids\n * @since 0.10\n * @beta\n */\nasync function listChildren(page: string): Promise<Array<string>> {\n const folderPath = resolvePath(page);\n\n const children = new Set<string>();\n if (await isDirectory(folderPath)) {\n await listSingleChild(folderPath, children);\n }\n\n return Array.from(children);\n}\n\n/**\n * Delete a page and its attachments.\n *\n * @param reference - the reference of the page to delete\n * @since 0.19\n * @beta\n */\nasync function deletePage(reference: string): Promise<void> {\n // Remove the page and its attachments\n const values = [];\n\n const path = `${resolvePath(reference)}.md`;\n if (await isFile(path)) {\n values.push(shell.trashItem(path));\n }\n const metaDirectoryPath = resolveMetaDirectoryPath(reference);\n if (await isDirectory(metaDirectoryPath)) {\n values.push(shell.trashItem(metaDirectoryPath));\n }\n\n await Promise.all(values);\n}\n\nasync function asyncFilter<T>(arr: T[], predicate: (i: T) => Promise<boolean>) {\n // First compute the async result for each element\n const results = await Promise.all(arr.map(predicate));\n\n // The filter out on the async results, retrieving the async results by index\n return arr.filter((_v, index) => results[index]);\n}\n\nasync function search(\n query: string,\n type?: LinkType,\n mimetype?: string,\n): Promise<\n (\n | { type: EntityType.ATTACHMENT; value: PageAttachment }\n | { type: EntityType.DOCUMENT; value: PageData }\n )[]\n> {\n const homePathFull = getHomePathFull();\n const attachments = (await readdir(homePathFull, { recursive: true })).map(\n (it) => join(homePathFull, it),\n );\n const allEntities = await asyncFilter(attachments, async (path: string) => {\n if (type == LinkType.ATTACHMENT) {\n return isAttachment(path, mimetype);\n } else if (type == LinkType.PAGE) {\n return isPage(path);\n } else {\n return (await isAttachment(path, mimetype)) || (await isPage(path)); // TODO: filter out\n }\n });\n\n const searchedEntities = await asyncFilter(allEntities, async (it) => {\n if (await isAttachment(it)) {\n return basename(it).includes(query);\n } else if (await isPage(it)) {\n return basename(dirname(it)).includes(query);\n } else {\n return false;\n }\n });\n return (\n await Promise.all(\n searchedEntities.map(async (it) => {\n if (await isPage(it)) {\n return readPage(it);\n } else {\n return readAttachment(it);\n }\n }),\n )\n ).filter((it) => it !== undefined);\n}\n\n/**\n * Initialize the wiki with a minimal content.\n *\n * @since 0.14\n * @beta\n */\nasync function createMinimalContent() {\n await savePage(\n join(getHomePathFull(), \"index.md\"),\n \"# Welcome\\n\" +\n \"\\n\" +\n \"This is a new **Cristal** wiki.\\n\" +\n \"\\n\" +\n \"You can use it to take your *own* notes.\\n\" +\n \"\\n\" +\n \"You can also create new [pages](index/newpage).\\n\" +\n \"\\n\" +\n \"Enjoy!\",\n \"\",\n );\n}\n\nasync function movePageSubSpaces(\n reference: string,\n newReference: string,\n actions: Promise<void>[],\n) {\n const pathSpace = `${resolvePath(reference)}`;\n const newSpacePath = `${resolvePath(newReference)}`;\n\n if (await isDirectory(pathSpace)) {\n actions.push(fs.promises.rename(pathSpace, newSpacePath));\n }\n}\n\n// eslint-disable-next-line max-statements\nasync function movePage(\n reference: string,\n newReference: string,\n preserveChildren: boolean,\n): Promise<void> {\n const path = `${resolvePath(reference)}.md`;\n const metaPath = resolveMetaDirectoryPath(reference);\n const newPath = `${resolvePath(newReference)}.md`;\n const newMetaPath = resolveMetaDirectoryPath(newReference);\n\n const actions = [];\n\n if (await isFile(path)) {\n actions.push(fs.promises.rename(path, newPath));\n }\n\n if (await isDirectory(metaPath)) {\n actions.push(fs.promises.rename(metaPath, newMetaPath));\n }\n\n if (preserveChildren) {\n await movePageSubSpaces(reference, newReference, actions);\n }\n\n await Promise.all(actions);\n}\n\n// TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n// eslint-disable-next-line max-statements\nexport default async function load(): Promise<void> {\n ipcMain.on(\"initRootDirectory\", async () => {\n // Check if the root directory does not exist, or exists and is empty.\n // If that's the case, create it and populate it with a default minimal content.\n const homePathFull = getHomePathFull();\n if (\n !(await pathExists(homePathFull)) ||\n ((await isDirectory(homePathFull)) && (await isEmpty(homePathFull)))\n ) {\n await createMinimalContent();\n }\n });\n\n protocol.handle(cristalFSProtocol, async (request) => {\n const homePathFull = getHomePathFull();\n const path = join(\n homePathFull,\n request.url.substring(`${cristalFSProtocol}://`.length),\n );\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n // The decode is required to handle paths containing spaces.\n return net.fetch(`file://${decodeURIComponent(path)}`);\n });\n\n ipcMain.handle(\"resolvePath\", (event, { page }) => {\n return resolvePagePath(page);\n });\n ipcMain.handle(\"resolveAttachmentsPath\", (event, { page }) => {\n return resolveAttachmentsPath(page);\n });\n ipcMain.handle(\"readPage\", async (event, { path }) => {\n return (await readPage(path))?.value;\n });\n ipcMain.handle(\"readAttachments\", (event, { path }) => {\n return readAttachments(path);\n });\n ipcMain.handle(\"readAttachment\", async (event, { path }) => {\n return (await readAttachment(path))?.value;\n });\n ipcMain.handle(\"savePage\", (event, { path, content, title }) => {\n return savePage(path, content, title);\n });\n ipcMain.handle(\"resolveAttachmentPath\", (event, { page, filename }) => {\n return resolveAttachmentPath(page, filename);\n });\n ipcMain.handle(\"saveAttachment\", (event, { path, filePath }) => {\n return saveAttachment(path, filePath);\n });\n ipcMain.handle(\"listChildren\", (event, { page }) => {\n return listChildren(page);\n });\n ipcMain.handle(\"deletePage\", (event, { path: reference }) => {\n return deletePage(reference);\n });\n ipcMain.handle(\"search\", (event, { query, type, mimetype }) => {\n return search(query, type, mimetype);\n });\n ipcMain.handle(\n \"movePage\",\n (event, { reference, newReference, preserveChildren }) => {\n return movePage(reference, newReference, preserveChildren);\n },\n );\n}\n"],"names":["HOME_PATH","HOME_PATH_FULL","join","app","getHomePathFull","getStorageRoot","resolvePath","page","lastSegments","resolvePagePath","makeLastSegmentHidden","segments","resolveMetaDirectoryPath","resolveAttachmentsPath","resolveAttachmentPath","filename","isFile","path","stat","fs","e","hasMimetype","mimetype","mimetypeFile","mime","p1","p2","q1","q2","isAttachment","isInAttachmentsDirectory","basename","dirname","isPage","pathFull","homePathFull","relative","parentPath","grandParentPath","parentName","grandParentName","isDirectory","isEmpty","pathExists","readPage","isWithin","pageContent","pageStats","content","data","DefaultPageReader","id","EntityType","os","readAttachments","attachments","attachment","readAttachment","it","stats","grandGrandParentPath","cristalFSProtocol","root","rel","savePage","title","fileContent","textDecoder","newContent","DefaultPageWriter","parentDirectory","saveAttachment","filePath","removeExtension","file","listSingleChild","folderPath","children","files","listChildren","deletePage","reference","values","shell","metaDirectoryPath","asyncFilter","arr","predicate","results","_v","index","search","query","type","readdir","allEntities","LinkType","searchedEntities","createMinimalContent","movePageSubSpaces","newReference","actions","pathSpace","newSpacePath","movePage","preserveChildren","metaPath","newPath","newMetaPath","load","ipcMain","protocol","request","net","event"],"mappings":";;;;;;;;;;;AAoCA,MAA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,EAAE,MAAA3G,QAChCwE,EAAaxE,CAAI,CACzB,GACDuG,EAAQ,OAAO,cAAc,CAACI,GAAO,EAAE,MAAMjC,QACpCD,GAAWC,CAAS,CAC5B,GACD6B,EAAQ,OAAO,UAAU,CAACI,GAAO,EAAE,OAAAtB,GAAO,MAAAC,GAAM,UAAAvE,QACvCqE,GAAOC,GAAOC,GAAMvE,CAAQ,CACpC,GACDwF,EAAQ;AAAA,IACN;AAAA,IACA,CAACI,GAAO,EAAE,WAAAjC,GAAW,cAAAmB,GAAc,kBAAAK,QAC1BD,GAASvB,GAAWmB,GAAcK,CAAgB;AAAA,EAC3D;AAEJ;"}
|
package/dist/main/index.umd.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
(function(l,h){typeof exports=="object"&&typeof module<"u"?module.exports=h(require("@xwiki/cristal-electron-state"),require("@xwiki/cristal-model-remote-url-filesystem-api"),require("@xwiki/cristal-page-default"),require("@xwiki/platform-link-suggest-api"),require("@xwiki/platform-model-api"),require("electron"),require("mime"),require("node:fs"),require("node:fs/promises"),require("node:os"),require("node:path")):typeof define=="function"&&define.amd?define(["@xwiki/cristal-electron-state","@xwiki/cristal-model-remote-url-filesystem-api","@xwiki/cristal-page-default","@xwiki/platform-link-suggest-api","@xwiki/platform-model-api","electron","mime","node:fs","node:fs/promises","node:os","node:path"],h):(l=typeof globalThis<"u"?globalThis:l||self,l.cristal_storage=h(l.cristalElectronState,l.cristalModelRemoteUrlFilesystemApi,l.cristalPageDefault,l.platformLinkSuggestApi,l.platformModelApi,l.electron,l.mime,l.fs,l.promises,l.os,l.node_path))})(this,(function(l,h,g,A,k,o,x,c,q,C,a){"use strict";const S=a.join(o.app.getPath("home"),".cristal");function d(){return l.getStorageRoot()??S}function w(e,...t){return a.join(d(),e,...t)}function H(e){return w(`${e}.md`)}function I(e){const t=e.split("/");return t.length==1?`.${e}`:`${t.slice(0,t.length-1).join("/")}/.${t[t.length-1]}`}function v(e){return w(I(e))}function T(e){return a.join(v(e),"attachments")}function N(e,t){return a.join(T(e),t)}async function f(e){let t;try{t=await c.promises.lstat(e)}catch(n){console.debug(n)}return t?.isFile()}function W(e,t){const n=x.getType(e);if(!n)return!1;const[i,s]=n.split("/"),[u,m]=t.split("/");return(u=="*"||u==i)&&(m=="*"||m==s)}async function $(e,t){if(!await f(e))return!1;const n=a.basename(a.dirname(e))=="attachments";return n&&t?W(e,t):n}async function p(e){if(!await f(e))return!1;const t=d(),n=a.relative(t,e),i=a.dirname(n),s=a.dirname(i),u=a.basename(i),m=a.basename(s);return u!="attachments"&&(!m.startsWith(".")||u==="."||m===".")}async function y(e){let t;try{t=await c.promises.lstat(e)}catch(n){console.debug(n)}return t?.isDirectory()}async function L(e){return(await c.promises.readdir(e)).length==0}async function F(e){try{await c.promises.lstat(e)}catch{return!1}return!0}async function M(e){const t=d();if(!await P(t,e))throw new Error(`[${e}] is not in in [${t}]`);if(await f(e)){const n=await c.promises.readFile(e),i=await c.promises.stat(e),s=n.toString("utf8"),u=new g.DefaultPageReader().readPage(s),m=a.relative(t,e).replace(/.md$/,"");return{type:k.EntityType.DOCUMENT,value:{...u,source:u.content,syntax:"markdown/1.2",lastAuthor:{name:C.userInfo().username},lastModificationDate:new Date(i.mtimeMs),id:m,canEdit:!0}}}else return}async function O(e){const t=d();if(!await P(t,e))throw new Error(`[${e}] is not in in [${t}]`);if(await y(e)){const n=await c.promises.readdir(e);return(await Promise.all(n.map(i=>E(a.join(e,i))))).filter(i=>i!==void 0).map(i=>i.value)}else return}async function E(e){const t=d();if(!await P(t,e))throw new Error(`[${e}] is not in in [${t}]`);if(await f(e)){const n=await c.promises.stat(e),i=x.getType(e)??"",s=a.dirname(a.dirname(e)),u=a.basename(s),m=a.dirname(s),r=a.basename(e);return{type:k.EntityType.ATTACHMENT,value:{id:r,mimetype:i,reference:a.relative(t,a.join(m,u,"attachments",r)),href:`${h.protocol}://${a.relative(t,a.join(m,u,"attachments",r))}`,date:n.mtime,size:n.size,author:void 0}}}else return}async function P(e,t){const n=a.relative(e,t);return!n.startsWith("../")&&n!==".."}async function j(e,t,n){const i=d();if(!await P(i,e))throw new Error(`[${e}] is not in in [${i}]`);let s;if(await F(e)&&await f(e)){const r=await c.promises.readFile(e),V=new TextDecoder("utf-8");s=new g.DefaultPageReader().readPage(V.decode(r)),s.content=t,s.name=n}else s={name:n,content:t};const u=new g.DefaultPageWriter().writePage(s),m=a.dirname(e);return await c.promises.mkdir(m,{recursive:!0}),await c.promises.writeFile(e,u,{flag:"w+"}),(await M(e))?.value}async function z(e,t){const n=d();if(!await P(n,e))throw new Error(`[${e}] is not in in [${n}]`);const i=a.dirname(e);await c.promises.mkdir(i,{recursive:!0}),await c.promises.copyFile(t,e)}function G(e){return e.includes(".")?e.slice(0,e.lastIndexOf(".")):e}async function R(e,t){const n=await c.promises.readdir(e);for(const i of n){if(i.startsWith("."))continue;const s=a.join(e,i);await f(s)?t.add(G(i)):await y(s)&&t.add(i)}}async function U(e){const t=w(e),n=new Set;return await y(t)&&await R(t,n),Array.from(n)}async function Y(e){const t=[],n=`${w(e)}.md`;await f(n)&&t.push(o.shell.trashItem(n));const i=v(e);await y(i)&&t.push(o.shell.trashItem(i)),await Promise.all(t)}async function D(e,t){const n=await Promise.all(e.map(t));return e.filter((i,s)=>n[s])}async function b(e,t,n){const i=d(),s=(await q.readdir(i,{recursive:!0})).map(r=>a.join(i,r)),u=await D(s,async r=>t==A.LinkType.ATTACHMENT?$(r,n):t==A.LinkType.PAGE?p(r):await $(r,n)||await p(r)),m=await D(u,async r=>await $(r)?a.basename(r).includes(e):await p(r)?a.basename(a.dirname(r)).includes(e):!1);return(await Promise.all(m.map(async r=>await p(r)?M(r):E(r)))).filter(r=>r!==void 0)}async function B(){await j(a.join(d(),"index.md"),`# Welcome
|
|
2
|
-
|
|
3
|
-
This is a new **Cristal** wiki.
|
|
4
|
-
|
|
5
|
-
You can use it to take your *own* notes.
|
|
6
|
-
|
|
7
|
-
You can also create new [pages](index/newpage).
|
|
8
|
-
|
|
9
|
-
Enjoy!`,"")}async function J(e,t,n){const i=`${w(e)}`,s=`${w(t)}`;await y(i)&&n.push(c.promises.rename(i,s))}async function K(e,t,n){const i=`${w(e)}.md`,s=v(e),u=`${w(t)}.md`,m=v(t),r=[];await f(i)&&r.push(c.promises.rename(i,u)),await y(s)&&r.push(c.promises.rename(s,m)),n&&await J(e,t,r),await Promise.all(r)}async function Q(){o.ipcMain.on("initRootDirectory",async()=>{const e=d();(!await F(e)||await y(e)&&await L(e))&&await B()}),o.protocol.handle(h.protocol,async e=>{const t=d(),n=a.join(t,e.url.substring(`${h.protocol}://`.length));if(!await P(t,n))throw new Error(`[${n}] is not in in [${t}]`);return o.net.fetch(`file://${decodeURIComponent(n)}`)}),o.ipcMain.handle("resolvePath",(e,{page:t})=>H(t)),o.ipcMain.handle("resolveAttachmentsPath",(e,{page:t})=>T(t)),o.ipcMain.handle("readPage",async(e,{path:t})=>(await M(t))?.value),o.ipcMain.handle("readAttachments",(e,{path:t})=>O(t)),o.ipcMain.handle("readAttachment",async(e,{path:t})=>(await E(t))?.value),o.ipcMain.handle("savePage",(e,{path:t,content:n,title:i})=>j(t,n,i)),o.ipcMain.handle("resolveAttachmentPath",(e,{page:t,filename:n})=>N(t,n)),o.ipcMain.handle("saveAttachment",(e,{path:t,filePath:n})=>z(t,n)),o.ipcMain.handle("listChildren",(e,{page:t})=>U(t)),o.ipcMain.handle("deletePage",(e,{path:t})=>Y(t)),o.ipcMain.handle("search",(e,{query:t,type:n,mimetype:i})=>b(t,n,i)),o.ipcMain.handle("movePage",(e,{reference:t,newReference:n,preserveChildren:i})=>K(t,n,i))}return Q}));
|
|
10
|
-
//# sourceMappingURL=index.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../../src/electron/main/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { getStorageRoot } from \"@xwiki/cristal-electron-state\";\nimport { protocol as cristalFSProtocol } from \"@xwiki/cristal-model-remote-url-filesystem-api\";\nimport {\n DefaultPageReader,\n DefaultPageWriter,\n} from \"@xwiki/cristal-page-default\";\nimport { LinkType } from \"@xwiki/platform-link-suggest-api\";\nimport { EntityType } from \"@xwiki/platform-model-api\";\nimport { app, ipcMain, net, protocol, shell } from \"electron\";\nimport mime from \"mime\";\nimport fs from \"node:fs\";\nimport { readdir } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport { basename, dirname, join, relative } from \"node:path\";\nimport type { PageAttachment, PageData } from \"@xwiki/platform-api\";\n\nconst HOME_PATH = \".cristal\";\nconst HOME_PATH_FULL = join(app.getPath(\"home\"), HOME_PATH);\n\nfunction getHomePathFull(): string {\n // If no custom storage root was provided in the current configuration, we\n // fallback to the folder `${HOME}/.cristal`.\n return getStorageRoot() ?? HOME_PATH_FULL;\n}\n\nfunction resolvePath(page: string, ...lastSegments: string[]) {\n return join(getHomePathFull(), page, ...lastSegments);\n}\n\nfunction resolvePagePath(page: string): string {\n return resolvePath(`${page}.md`);\n}\n\nfunction makeLastSegmentHidden(page: string) {\n const segments = page.split(\"/\");\n // Add a dot after the last segment of the page path\n if (segments.length == 1) {\n return `.${page}`;\n } else {\n const joined = segments.slice(0, segments.length - 1).join(\"/\");\n return `${joined}/.${segments[segments.length - 1]}`;\n }\n}\n\nfunction resolveMetaDirectoryPath(page: string) {\n return resolvePath(makeLastSegmentHidden(page));\n}\n\nfunction resolveAttachmentsPath(page: string): string {\n return join(resolveMetaDirectoryPath(page), \"attachments\");\n}\n\nfunction resolveAttachmentPath(page: string, filename: string): string {\n return join(resolveAttachmentsPath(page), filename);\n}\n\nasync function isFile(path: string) {\n let stat = undefined;\n try {\n stat = await fs.promises.lstat(path);\n } catch (e) {\n console.debug(e);\n }\n return stat?.isFile();\n}\n\nfunction hasMimetype(path: string, mimetype: string) {\n const mimetypeFile = mime.getType(path);\n if (!mimetypeFile) {\n return false;\n }\n\n const [p1, p2] = mimetypeFile.split(\"/\");\n const [q1, q2] = mimetype.split(\"/\");\n return (q1 == \"*\" || q1 == p1) && (q2 == \"*\" || q2 == p2);\n}\n\nasync function isAttachment(path: string, mimetype?: string) {\n if (!(await isFile(path))) {\n return false;\n }\n\n const isInAttachmentsDirectory = basename(dirname(path)) == \"attachments\";\n if (isInAttachmentsDirectory && mimetype) {\n return hasMimetype(path, mimetype);\n }\n return isInAttachmentsDirectory;\n}\n\nasync function isPage(pathFull: string) {\n if (!(await isFile(pathFull))) {\n return false;\n }\n\n const homePathFull = getHomePathFull();\n const path = relative(homePathFull, pathFull);\n\n const parentPath = dirname(path);\n const grandParentPath = dirname(parentPath);\n const parentName = basename(parentPath);\n const grandParentName = basename(grandParentPath);\n\n return (\n parentName != \"attachments\" &&\n (!grandParentName.startsWith(\".\") ||\n parentName === \".\" ||\n grandParentName === \".\")\n );\n}\n\nasync function isDirectory(path: string) {\n let stat = undefined;\n try {\n stat = await fs.promises.lstat(path);\n } catch (e) {\n console.debug(e);\n }\n return stat?.isDirectory();\n}\n\nasync function isEmpty(path: string) {\n const readdir = await fs.promises.readdir(path);\n return readdir.length == 0;\n}\n\nasync function pathExists(path: string) {\n try {\n await fs.promises.lstat(path);\n } catch {\n return false;\n }\n return true;\n}\n\n// eslint-disable-next-line max-statements\nasync function readPage(\n path: string,\n): Promise<{ type: EntityType.DOCUMENT; value: PageData } | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n if (await isFile(path)) {\n const pageContent = await fs.promises.readFile(path);\n const pageStats = await fs.promises.stat(path);\n const content = pageContent.toString(\"utf8\");\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const data = new DefaultPageReader().readPage(content) as any;\n\n const id = relative(homePathFull, path).replace(/.md$/, \"\");\n return {\n type: EntityType.DOCUMENT,\n value: {\n ...data,\n source: data.content,\n syntax: \"markdown/1.2\",\n lastAuthor: { name: os.userInfo().username },\n lastModificationDate: new Date(pageStats.mtimeMs),\n id: id,\n canEdit: true,\n },\n };\n } else {\n return undefined;\n }\n}\n\nasync function readAttachments(\n path: string,\n): Promise<PageAttachment[] | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n if (await isDirectory(path)) {\n const attachments = await fs.promises.readdir(path);\n return (\n await Promise.all(\n attachments.map((attachment) => readAttachment(join(path, attachment))),\n )\n )\n .filter((it) => it !== undefined)\n .map((it) => it.value);\n } else {\n return undefined;\n }\n}\n\n// eslint-disable-next-line max-statements\nasync function readAttachment(\n path: string,\n): Promise<{ type: EntityType.ATTACHMENT; value: PageAttachment } | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n\n if (await isFile(path)) {\n const stats = await fs.promises.stat(path);\n const mimetype = mime.getType(path) ?? \"\";\n const grandParentPath = dirname(dirname(path)); // .something\n const grandParentName = basename(grandParentPath);\n const grandGrandParentPath = dirname(grandParentPath); // space\n\n const id = basename(path);\n return {\n type: EntityType.ATTACHMENT,\n value: {\n id: id,\n mimetype,\n reference: relative(\n homePathFull,\n join(grandGrandParentPath, grandParentName, \"attachments\", id),\n ),\n href: `${cristalFSProtocol}://${relative(\n homePathFull,\n join(grandGrandParentPath, grandParentName, \"attachments\", id),\n )}`,\n date: stats.mtime,\n size: stats.size,\n author: undefined,\n },\n };\n } else {\n return undefined;\n }\n}\n\nasync function isWithin(root: string, path: string) {\n const rel = relative(root, path);\n return !rel.startsWith(\"../\") && rel !== \"..\";\n}\n\n/**\n * Note: currently this is more a method to update the content of a page than\n * an actual page save.\n *\n * @param path - the path of the page on the file system\n * @param content - the content of the page\n * @param title - the title of the page\n * @since 0.8\n * @beta\n */\n// TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n// eslint-disable-next-line max-statements\nasync function savePage(\n path: string,\n content: string,\n title: string,\n): Promise<PageData | undefined> {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n let page: { content: string; [key: string]: unknown };\n if ((await pathExists(path)) && (await isFile(path))) {\n const fileContent = await fs.promises.readFile(path);\n const textDecoder = new TextDecoder(\"utf-8\");\n page = new DefaultPageReader().readPage(textDecoder.decode(fileContent));\n page.content = content;\n page.name = title;\n } else {\n page = {\n name: title,\n content: content,\n };\n }\n\n const newContent = new DefaultPageWriter().writePage(page);\n const parentDirectory = dirname(path);\n // Create the parent directories in case they do not exist.\n await fs.promises.mkdir(parentDirectory, { recursive: true });\n // Set the flag to w+ so that the file is created if it does not already\n // exist, or fully replaced when it does.\n await fs.promises.writeFile(path, newContent, { flag: \"w+\" });\n return (await readPage(path))?.value;\n}\n\nasync function saveAttachment(path: string, filePath: string) {\n const homePathFull = getHomePathFull();\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n const parentDirectory = dirname(path);\n\n // Create the parent directories in case they do not exist.\n await fs.promises.mkdir(parentDirectory, { recursive: true });\n await fs.promises.copyFile(filePath, path);\n}\n\nfunction removeExtension(file: string): string {\n if (!file.includes(\".\")) {\n return file;\n }\n return file.slice(0, file.lastIndexOf(\".\"));\n}\n\nasync function listSingleChild(folderPath: string, children: Set<string>) {\n const files = await fs.promises.readdir(folderPath);\n\n for (const file of files) {\n // Ignore all hidden files.\n if (file.startsWith(\".\")) {\n continue;\n }\n const path = join(folderPath, file);\n if (await isFile(path)) {\n children.add(removeExtension(file));\n } else if (await isDirectory(path)) {\n children.add(file);\n }\n }\n}\n\n/**\n * Get the ids of the children pages for a given page.\n *\n * @param page - the id of the page\n * @returns a list of page ids\n * @since 0.10\n * @beta\n */\nasync function listChildren(page: string): Promise<Array<string>> {\n const folderPath = resolvePath(page);\n\n const children = new Set<string>();\n if (await isDirectory(folderPath)) {\n await listSingleChild(folderPath, children);\n }\n\n return Array.from(children);\n}\n\n/**\n * Delete a page and its attachments.\n *\n * @param reference - the reference of the page to delete\n * @since 0.19\n * @beta\n */\nasync function deletePage(reference: string): Promise<void> {\n // Remove the page and its attachments\n const values = [];\n\n const path = `${resolvePath(reference)}.md`;\n if (await isFile(path)) {\n values.push(shell.trashItem(path));\n }\n const metaDirectoryPath = resolveMetaDirectoryPath(reference);\n if (await isDirectory(metaDirectoryPath)) {\n values.push(shell.trashItem(metaDirectoryPath));\n }\n\n await Promise.all(values);\n}\n\nasync function asyncFilter<T>(arr: T[], predicate: (i: T) => Promise<boolean>) {\n // First compute the async result for each element\n const results = await Promise.all(arr.map(predicate));\n\n // The filter out on the async results, retrieving the async results by index\n return arr.filter((_v, index) => results[index]);\n}\n\nasync function search(\n query: string,\n type?: LinkType,\n mimetype?: string,\n): Promise<\n (\n | { type: EntityType.ATTACHMENT; value: PageAttachment }\n | { type: EntityType.DOCUMENT; value: PageData }\n )[]\n> {\n const homePathFull = getHomePathFull();\n const attachments = (await readdir(homePathFull, { recursive: true })).map(\n (it) => join(homePathFull, it),\n );\n const allEntities = await asyncFilter(attachments, async (path: string) => {\n if (type == LinkType.ATTACHMENT) {\n return isAttachment(path, mimetype);\n } else if (type == LinkType.PAGE) {\n return isPage(path);\n } else {\n return (await isAttachment(path, mimetype)) || (await isPage(path)); // TODO: filter out\n }\n });\n\n const searchedEntities = await asyncFilter(allEntities, async (it) => {\n if (await isAttachment(it)) {\n return basename(it).includes(query);\n } else if (await isPage(it)) {\n return basename(dirname(it)).includes(query);\n } else {\n return false;\n }\n });\n return (\n await Promise.all(\n searchedEntities.map(async (it) => {\n if (await isPage(it)) {\n return readPage(it);\n } else {\n return readAttachment(it);\n }\n }),\n )\n ).filter((it) => it !== undefined);\n}\n\n/**\n * Initialize the wiki with a minimal content.\n *\n * @since 0.14\n * @beta\n */\nasync function createMinimalContent() {\n await savePage(\n join(getHomePathFull(), \"index.md\"),\n \"# Welcome\\n\" +\n \"\\n\" +\n \"This is a new **Cristal** wiki.\\n\" +\n \"\\n\" +\n \"You can use it to take your *own* notes.\\n\" +\n \"\\n\" +\n \"You can also create new [pages](index/newpage).\\n\" +\n \"\\n\" +\n \"Enjoy!\",\n \"\",\n );\n}\n\nasync function movePageSubSpaces(\n reference: string,\n newReference: string,\n actions: Promise<void>[],\n) {\n const pathSpace = `${resolvePath(reference)}`;\n const newSpacePath = `${resolvePath(newReference)}`;\n\n if (await isDirectory(pathSpace)) {\n actions.push(fs.promises.rename(pathSpace, newSpacePath));\n }\n}\n\n// eslint-disable-next-line max-statements\nasync function movePage(\n reference: string,\n newReference: string,\n preserveChildren: boolean,\n): Promise<void> {\n const path = `${resolvePath(reference)}.md`;\n const metaPath = resolveMetaDirectoryPath(reference);\n const newPath = `${resolvePath(newReference)}.md`;\n const newMetaPath = resolveMetaDirectoryPath(newReference);\n\n const actions = [];\n\n if (await isFile(path)) {\n actions.push(fs.promises.rename(path, newPath));\n }\n\n if (await isDirectory(metaPath)) {\n actions.push(fs.promises.rename(metaPath, newMetaPath));\n }\n\n if (preserveChildren) {\n await movePageSubSpaces(reference, newReference, actions);\n }\n\n await Promise.all(actions);\n}\n\n// TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n// eslint-disable-next-line max-statements\nexport default async function load(): Promise<void> {\n ipcMain.on(\"initRootDirectory\", async () => {\n // Check if the root directory does not exist, or exists and is empty.\n // If that's the case, create it and populate it with a default minimal content.\n const homePathFull = getHomePathFull();\n if (\n !(await pathExists(homePathFull)) ||\n ((await isDirectory(homePathFull)) && (await isEmpty(homePathFull)))\n ) {\n await createMinimalContent();\n }\n });\n\n protocol.handle(cristalFSProtocol, async (request) => {\n const homePathFull = getHomePathFull();\n const path = join(\n homePathFull,\n request.url.substring(`${cristalFSProtocol}://`.length),\n );\n if (!(await isWithin(homePathFull, path))) {\n throw new Error(`[${path}] is not in in [${homePathFull}]`);\n }\n // The decode is required to handle paths containing spaces.\n return net.fetch(`file://${decodeURIComponent(path)}`);\n });\n\n ipcMain.handle(\"resolvePath\", (event, { page }) => {\n return resolvePagePath(page);\n });\n ipcMain.handle(\"resolveAttachmentsPath\", (event, { page }) => {\n return resolveAttachmentsPath(page);\n });\n ipcMain.handle(\"readPage\", async (event, { path }) => {\n return (await readPage(path))?.value;\n });\n ipcMain.handle(\"readAttachments\", (event, { path }) => {\n return readAttachments(path);\n });\n ipcMain.handle(\"readAttachment\", async (event, { path }) => {\n return (await readAttachment(path))?.value;\n });\n ipcMain.handle(\"savePage\", (event, { path, content, title }) => {\n return savePage(path, content, title);\n });\n ipcMain.handle(\"resolveAttachmentPath\", (event, { page, filename }) => {\n return resolveAttachmentPath(page, filename);\n });\n ipcMain.handle(\"saveAttachment\", (event, { path, filePath }) => {\n return saveAttachment(path, filePath);\n });\n ipcMain.handle(\"listChildren\", (event, { page }) => {\n return listChildren(page);\n });\n ipcMain.handle(\"deletePage\", (event, { path: reference }) => {\n return deletePage(reference);\n });\n ipcMain.handle(\"search\", (event, { query, type, mimetype }) => {\n return search(query, type, mimetype);\n });\n ipcMain.handle(\n \"movePage\",\n (event, { reference, newReference, preserveChildren }) => {\n return movePage(reference, newReference, preserveChildren);\n },\n );\n}\n"],"names":["HOME_PATH_FULL","join","app","getHomePathFull","getStorageRoot","resolvePath","page","lastSegments","resolvePagePath","makeLastSegmentHidden","segments","resolveMetaDirectoryPath","resolveAttachmentsPath","resolveAttachmentPath","filename","isFile","path","stat","fs","e","hasMimetype","mimetype","mimetypeFile","mime","p1","p2","q1","q2","isAttachment","isInAttachmentsDirectory","basename","dirname","isPage","pathFull","homePathFull","relative","parentPath","grandParentPath","parentName","grandParentName","isDirectory","isEmpty","pathExists","readPage","isWithin","pageContent","pageStats","content","data","DefaultPageReader","id","EntityType","os","readAttachments","attachments","attachment","readAttachment","it","stats","grandGrandParentPath","cristalFSProtocol","root","rel","savePage","title","fileContent","textDecoder","newContent","DefaultPageWriter","parentDirectory","saveAttachment","filePath","removeExtension","file","listSingleChild","folderPath","children","files","listChildren","deletePage","reference","values","shell","metaDirectoryPath","asyncFilter","arr","predicate","results","_v","index","search","query","type","readdir","allEntities","LinkType","searchedEntities","createMinimalContent","movePageSubSpaces","newReference","actions","pathSpace","newSpacePath","movePage","preserveChildren","metaPath","newPath","newMetaPath","load","ipcMain","protocol","request","net","event"],"mappings":"++BAqCA,MAAMA,EAAiBC,EAAAA,KAAKC,EAAAA,IAAI,QAAQ,MAAM,EAD5B,UACwC,EAE1D,SAASC,GAA0B,CAGjC,OAAOC,EAAAA,kBAAoBJ,CAC7B,CAEA,SAASK,EAAYC,KAAiBC,EAAwB,CAC5D,OAAON,EAAAA,KAAKE,EAAA,EAAmBG,EAAM,GAAGC,CAAY,CACtD,CAEA,SAASC,EAAgBF,EAAsB,CAC7C,OAAOD,EAAY,GAAGC,CAAI,KAAK,CACjC,CAEA,SAASG,EAAsBH,EAAc,CAC3C,MAAMI,EAAWJ,EAAK,MAAM,GAAG,EAE/B,OAAII,EAAS,QAAU,EACd,IAAIJ,CAAI,GAGR,GADQI,EAAS,MAAM,EAAGA,EAAS,OAAS,CAAC,EAAE,KAAK,GAAG,CAC9C,KAAKA,EAASA,EAAS,OAAS,CAAC,CAAC,EAEtD,CAEA,SAASC,EAAyBL,EAAc,CAC9C,OAAOD,EAAYI,EAAsBH,CAAI,CAAC,CAChD,CAEA,SAASM,EAAuBN,EAAsB,CACpD,OAAOL,O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AAO,iBAAkB,MAAOI,EAAO,CAAE,KAAAjG,MACvC,MAAMwC,EAAexC,CAAI,IAAI,KACtC,EACD6F,UAAQ,OAAO,WAAY,CAACI,EAAO,CAAE,KAAAjG,EAAM,QAAA+B,EAAS,MAAAiB,KAC3CD,EAAS/C,EAAM+B,EAASiB,CAAK,CACrC,EACD6C,EAAAA,QAAQ,OAAO,wBAAyB,CAACI,EAAO,CAAE,KAAA3G,EAAM,SAAAQ,KAC/CD,EAAsBP,EAAMQ,CAAQ,CAC5C,EACD+F,EAAAA,QAAQ,OAAO,iBAAkB,CAACI,EAAO,CAAE,KAAAjG,EAAM,SAAAuD,KACxCD,EAAetD,EAAMuD,CAAQ,CACrC,EACDsC,EAAAA,QAAQ,OAAO,eAAgB,CAACI,EAAO,CAAE,KAAA3G,KAChCwE,EAAaxE,CAAI,CACzB,EACDuG,EAAAA,QAAQ,OAAO,aAAc,CAACI,EAAO,CAAE,KAAMjC,KACpCD,EAAWC,CAAS,CAC5B,EACD6B,UAAQ,OAAO,SAAU,CAACI,EAAO,CAAE,MAAAtB,EAAO,KAAAC,EAAM,SAAAvE,KACvCqE,EAAOC,EAAOC,EAAMvE,CAAQ,CACpC,EACDwF,EAAAA,QAAQ,OACN,WACA,CAACI,EAAO,CAAE,UAAAjC,EAAW,aAAAmB,EAAc,iBAAAK,KAC1BD,EAASvB,EAAWmB,EAAcK,CAAgB,CAC3D,CAEJ"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { LinkType } from '@xwiki/platform-link-suggest-api';
|
|
2
|
-
import { EntityType } from '@xwiki/platform-model-api';
|
|
3
|
-
import { PageAttachment, PageData } from '@xwiki/platform-api';
|
|
4
|
-
export interface APITypes {
|
|
5
|
-
initRootDirectory(): void;
|
|
6
|
-
resolvePath(page: string): Promise<string>;
|
|
7
|
-
resolveAttachmentsPath(page: string): Promise<string>;
|
|
8
|
-
resolveAttachmentPath(page: string, filename: string): Promise<string>;
|
|
9
|
-
readPage(path: string): Promise<PageData>;
|
|
10
|
-
readAttachments(path: string): Promise<PageAttachment[]>;
|
|
11
|
-
readAttachment(path: string): Promise<PageAttachment>;
|
|
12
|
-
savePage(path: string, content: string, title: string): Promise<PageData>;
|
|
13
|
-
saveAttachment(path: string, file: File): Promise<PageData>;
|
|
14
|
-
listChildren(page: string): Promise<Array<string>>;
|
|
15
|
-
deletePage(reference: string): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param query - search query
|
|
19
|
-
* @param type - the type of attach
|
|
20
|
-
* @param mimetype - the expected mimetype, only applied for attachments
|
|
21
|
-
* @since 0.13
|
|
22
|
-
* @beta
|
|
23
|
-
*/
|
|
24
|
-
search(query: string, type?: LinkType, mimetype?: string): Promise<({
|
|
25
|
-
type: EntityType.ATTACHMENT;
|
|
26
|
-
value: PageAttachment;
|
|
27
|
-
} | {
|
|
28
|
-
type: EntityType.DOCUMENT;
|
|
29
|
-
value: PageData;
|
|
30
|
-
})[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Move a page.
|
|
33
|
-
*
|
|
34
|
-
* @param reference - the reference of the page to move
|
|
35
|
-
* @param newReference - the new reference of the page
|
|
36
|
-
* @param preserveChildren - whether to move children
|
|
37
|
-
*
|
|
38
|
-
* @since 0.20
|
|
39
|
-
* @beta
|
|
40
|
-
*/
|
|
41
|
-
movePage(reference: string, newReference: string, preserveChildren: boolean): Promise<void>;
|
|
42
|
-
}
|
package/dist/preload/index.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See the LICENSE file distributed with this work for additional
|
|
3
|
-
* information regarding copyright ownership.
|
|
4
|
-
*
|
|
5
|
-
* This is free software; you can redistribute it and/or modify it
|
|
6
|
-
* under the terms of the GNU Lesser General Public License as
|
|
7
|
-
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
-
* the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This software is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this software; if not, write to the Free
|
|
17
|
-
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
-
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
-
*/
|
|
20
|
-
export {};
|
package/dist/preload/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See the LICENSE file distributed with this work for additional
|
|
3
|
-
* information regarding copyright ownership.
|
|
4
|
-
*
|
|
5
|
-
* This is free software; you can redistribute it and/or modify it
|
|
6
|
-
* under the terms of the GNU Lesser General Public License as
|
|
7
|
-
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
-
* the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This software is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this software; if not, write to the Free
|
|
17
|
-
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
-
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
-
*/
|
|
20
|
-
export {};
|
package/dist/preload/index.es.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import "@xwiki/platform-link-suggest-api";
|
|
2
|
-
import "@xwiki/platform-model-api";
|
|
3
|
-
import { contextBridge as a, ipcRenderer as t, webUtils as o } from "electron";
|
|
4
|
-
const i = {
|
|
5
|
-
initRootDirectory() {
|
|
6
|
-
return t.send("initRootDirectory", {});
|
|
7
|
-
},
|
|
8
|
-
readPage: (e) => t.invoke("readPage", { path: e }),
|
|
9
|
-
readAttachments(e) {
|
|
10
|
-
return t.invoke("readAttachments", { path: e });
|
|
11
|
-
},
|
|
12
|
-
readAttachment(e) {
|
|
13
|
-
return t.invoke("readAttachment", { path: e });
|
|
14
|
-
},
|
|
15
|
-
resolvePath: (e) => t.invoke("resolvePath", { page: e || "index" }),
|
|
16
|
-
resolveAttachmentsPath: (e) => t.invoke("resolveAttachmentsPath", {
|
|
17
|
-
page: e || "index"
|
|
18
|
-
}),
|
|
19
|
-
savePage(e, r, n) {
|
|
20
|
-
return t.invoke("savePage", { path: e, title: n, content: r });
|
|
21
|
-
},
|
|
22
|
-
resolveAttachmentPath(e, r) {
|
|
23
|
-
return t.invoke("resolveAttachmentPath", {
|
|
24
|
-
page: e || "index",
|
|
25
|
-
filename: r
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
saveAttachment(e, r) {
|
|
29
|
-
const n = o.getPathForFile(r);
|
|
30
|
-
return t.invoke("saveAttachment", { path: e, filePath: n });
|
|
31
|
-
},
|
|
32
|
-
listChildren(e) {
|
|
33
|
-
return t.invoke("listChildren", { page: e });
|
|
34
|
-
},
|
|
35
|
-
deletePage(e) {
|
|
36
|
-
return t.invoke("deletePage", { path: e });
|
|
37
|
-
},
|
|
38
|
-
search(e, r, n) {
|
|
39
|
-
return t.invoke("search", { query: e, type: r, mimetype: n });
|
|
40
|
-
},
|
|
41
|
-
movePage(e, r, n) {
|
|
42
|
-
return t.invoke("movePage", {
|
|
43
|
-
reference: e,
|
|
44
|
-
newReference: r,
|
|
45
|
-
preserveChildren: n
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
a.exposeInMainWorld("fileSystemStorage", i);
|
|
50
|
-
//# sourceMappingURL=index.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../../src/electron/preload/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { LinkType } from \"@xwiki/platform-link-suggest-api\";\nimport { EntityType } from \"@xwiki/platform-model-api\";\nimport { contextBridge, ipcRenderer, webUtils } from \"electron\";\nimport type { APITypes } from \"./apiTypes\";\nimport type { PageAttachment, PageData } from \"@xwiki/platform-api\";\n\nconst api: APITypes = {\n initRootDirectory(): void {\n return ipcRenderer.send(\"initRootDirectory\", {});\n },\n readPage: (path: string) => {\n return ipcRenderer.invoke(\"readPage\", { path });\n },\n readAttachments(path: string): Promise<PageAttachment[]> {\n return ipcRenderer.invoke(\"readAttachments\", { path });\n },\n readAttachment(path: string): Promise<PageAttachment> {\n return ipcRenderer.invoke(\"readAttachment\", { path });\n },\n resolvePath: (page: string) => {\n return ipcRenderer.invoke(\"resolvePath\", { page: page || \"index\" });\n },\n resolveAttachmentsPath: (page: string) => {\n return ipcRenderer.invoke(\"resolveAttachmentsPath\", {\n page: page || \"index\",\n });\n },\n savePage(path: string, content: string, title: string): Promise<PageData> {\n return ipcRenderer.invoke(\"savePage\", { path, title, content });\n },\n resolveAttachmentPath(page: string, filename: string): Promise<string> {\n return ipcRenderer.invoke(\"resolveAttachmentPath\", {\n page: page || \"index\",\n filename,\n });\n },\n saveAttachment(path: string, file: File): Promise<PageData> {\n const filePath = webUtils.getPathForFile(file);\n return ipcRenderer.invoke(\"saveAttachment\", { path, filePath: filePath });\n },\n listChildren(page: string): Promise<Array<string>> {\n return ipcRenderer.invoke(\"listChildren\", { page });\n },\n deletePage(reference: string): Promise<void> {\n return ipcRenderer.invoke(\"deletePage\", { path: reference });\n },\n search(\n query: string,\n type?: LinkType,\n mimetype?: string,\n ): Promise<\n (\n | { type: EntityType.ATTACHMENT; value: PageAttachment }\n | { type: EntityType.DOCUMENT; value: PageData }\n )[]\n > {\n return ipcRenderer.invoke(\"search\", { query, type, mimetype });\n },\n movePage(\n reference: string,\n newReference: string,\n preserveChildren: boolean,\n ): Promise<void> {\n return ipcRenderer.invoke(\"movePage\", {\n reference,\n newReference,\n preserveChildren,\n });\n },\n};\ncontextBridge.exposeInMainWorld(\"fileSystemStorage\", api);\n"],"names":["api","ipcRenderer","path","page","content","title","filename","file","filePath","webUtils","reference","query","type","mimetype","newReference","preserveChildren","contextBridge"],"mappings":";;;AA0BA,MAAMA,IAAgB;AAAA,EACpB,oBAA0B;AACxB,WAAOC,EAAY,KAAK,qBAAqB,EAAE;AAAA,EACjD;AAAA,EACA,UAAU,CAACC,MACFD,EAAY,OAAO,YAAY,EAAE,MAAAC,GAAM;AAAA,EAEhD,gBAAgBA,GAAyC;AACvD,WAAOD,EAAY,OAAO,mBAAmB,EAAE,MAAAC,GAAM;AAAA,EACvD;AAAA,EACA,eAAeA,GAAuC;AACpD,WAAOD,EAAY,OAAO,kBAAkB,EAAE,MAAAC,GAAM;AAAA,EACtD;AAAA,EACA,aAAa,CAACC,MACLF,EAAY,OAAO,eAAe,EAAE,MAAME,KAAQ,SAAS;AAAA,EAEpE,wBAAwB,CAACA,MAChBF,EAAY,OAAO,0BAA0B;AAAA,IAClD,MAAME,KAAQ;AAAA,EAAA,CACf;AAAA,EAEH,SAASD,GAAcE,GAAiBC,GAAkC;AACxE,WAAOJ,EAAY,OAAO,YAAY,EAAE,MAAAC,GAAM,OAAAG,GAAO,SAAAD,GAAS;AAAA,EAChE;AAAA,EACA,sBAAsBD,GAAcG,GAAmC;AACrE,WAAOL,EAAY,OAAO,yBAAyB;AAAA,MACjD,MAAME,KAAQ;AAAA,MACd,UAAAG;AAAA,IAAA,CACD;AAAA,EACH;AAAA,EACA,eAAeJ,GAAcK,GAA+B;AAC1D,UAAMC,IAAWC,EAAS,eAAeF,CAAI;AAC7C,WAAON,EAAY,OAAO,kBAAkB,EAAE,MAAAC,GAAM,UAAAM,GAAoB;AAAA,EAC1E;AAAA,EACA,aAAaL,GAAsC;AACjD,WAAOF,EAAY,OAAO,gBAAgB,EAAE,MAAAE,GAAM;AAAA,EACpD;AAAA,EACA,WAAWO,GAAkC;AAC3C,WAAOT,EAAY,OAAO,cAAc,EAAE,MAAMS,GAAW;AAAA,EAC7D;AAAA,EACA,OACEC,GACAC,GACAC,GAMA;AACA,WAAOZ,EAAY,OAAO,UAAU,EAAE,OAAAU,GAAO,MAAAC,GAAM,UAAAC,GAAU;AAAA,EAC/D;AAAA,EACA,SACEH,GACAI,GACAC,GACe;AACf,WAAOd,EAAY,OAAO,YAAY;AAAA,MACpC,WAAAS;AAAA,MACA,cAAAI;AAAA,MACA,kBAAAC;AAAA,IAAA,CACD;AAAA,EACH;AACF;AACAC,EAAc,kBAAkB,qBAAqBhB,CAAG;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(require("@xwiki/platform-link-suggest-api"),require("@xwiki/platform-model-api"),require("electron")):typeof define=="function"&&define.amd?define(["@xwiki/platform-link-suggest-api","@xwiki/platform-model-api","electron"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(null,null,n.electron))})(this,(function(n,a,t){"use strict";const d={initRootDirectory(){return t.ipcRenderer.send("initRootDirectory",{})},readPage:e=>t.ipcRenderer.invoke("readPage",{path:e}),readAttachments(e){return t.ipcRenderer.invoke("readAttachments",{path:e})},readAttachment(e){return t.ipcRenderer.invoke("readAttachment",{path:e})},resolvePath:e=>t.ipcRenderer.invoke("resolvePath",{page:e||"index"}),resolveAttachmentsPath:e=>t.ipcRenderer.invoke("resolveAttachmentsPath",{page:e||"index"}),savePage(e,i,r){return t.ipcRenderer.invoke("savePage",{path:e,title:r,content:i})},resolveAttachmentPath(e,i){return t.ipcRenderer.invoke("resolveAttachmentPath",{page:e||"index",filename:i})},saveAttachment(e,i){const r=t.webUtils.getPathForFile(i);return t.ipcRenderer.invoke("saveAttachment",{path:e,filePath:r})},listChildren(e){return t.ipcRenderer.invoke("listChildren",{page:e})},deletePage(e){return t.ipcRenderer.invoke("deletePage",{path:e})},search(e,i,r){return t.ipcRenderer.invoke("search",{query:e,type:i,mimetype:r})},movePage(e,i,r){return t.ipcRenderer.invoke("movePage",{reference:e,newReference:i,preserveChildren:r})}};t.contextBridge.exposeInMainWorld("fileSystemStorage",d)}));
|
|
2
|
-
//# sourceMappingURL=index.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../../src/electron/preload/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { LinkType } from \"@xwiki/platform-link-suggest-api\";\nimport { EntityType } from \"@xwiki/platform-model-api\";\nimport { contextBridge, ipcRenderer, webUtils } from \"electron\";\nimport type { APITypes } from \"./apiTypes\";\nimport type { PageAttachment, PageData } from \"@xwiki/platform-api\";\n\nconst api: APITypes = {\n initRootDirectory(): void {\n return ipcRenderer.send(\"initRootDirectory\", {});\n },\n readPage: (path: string) => {\n return ipcRenderer.invoke(\"readPage\", { path });\n },\n readAttachments(path: string): Promise<PageAttachment[]> {\n return ipcRenderer.invoke(\"readAttachments\", { path });\n },\n readAttachment(path: string): Promise<PageAttachment> {\n return ipcRenderer.invoke(\"readAttachment\", { path });\n },\n resolvePath: (page: string) => {\n return ipcRenderer.invoke(\"resolvePath\", { page: page || \"index\" });\n },\n resolveAttachmentsPath: (page: string) => {\n return ipcRenderer.invoke(\"resolveAttachmentsPath\", {\n page: page || \"index\",\n });\n },\n savePage(path: string, content: string, title: string): Promise<PageData> {\n return ipcRenderer.invoke(\"savePage\", { path, title, content });\n },\n resolveAttachmentPath(page: string, filename: string): Promise<string> {\n return ipcRenderer.invoke(\"resolveAttachmentPath\", {\n page: page || \"index\",\n filename,\n });\n },\n saveAttachment(path: string, file: File): Promise<PageData> {\n const filePath = webUtils.getPathForFile(file);\n return ipcRenderer.invoke(\"saveAttachment\", { path, filePath: filePath });\n },\n listChildren(page: string): Promise<Array<string>> {\n return ipcRenderer.invoke(\"listChildren\", { page });\n },\n deletePage(reference: string): Promise<void> {\n return ipcRenderer.invoke(\"deletePage\", { path: reference });\n },\n search(\n query: string,\n type?: LinkType,\n mimetype?: string,\n ): Promise<\n (\n | { type: EntityType.ATTACHMENT; value: PageAttachment }\n | { type: EntityType.DOCUMENT; value: PageData }\n )[]\n > {\n return ipcRenderer.invoke(\"search\", { query, type, mimetype });\n },\n movePage(\n reference: string,\n newReference: string,\n preserveChildren: boolean,\n ): Promise<void> {\n return ipcRenderer.invoke(\"movePage\", {\n reference,\n newReference,\n preserveChildren,\n });\n },\n};\ncontextBridge.exposeInMainWorld(\"fileSystemStorage\", api);\n"],"names":["api","ipcRenderer","path","page","content","title","filename","file","filePath","webUtils","reference","query","type","mimetype","newReference","preserveChildren","contextBridge"],"mappings":"yYA0BA,MAAMA,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