@axium/office 0.0.0-stage → 0.1.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/LICENSE.md +157 -0
- package/README.md +50 -2
- package/assets/blank.docx +0 -0
- package/assets/blank.pptx +0 -0
- package/assets/blank.xlsx +0 -0
- package/assets/documentserver.json +11 -0
- package/dist/common.d.ts +257 -0
- package/dist/common.js +71 -0
- package/dist/hooks.d.ts +4 -0
- package/dist/hooks.js +12 -0
- package/dist/server/api.d.ts +1 -0
- package/dist/server/api.js +60 -0
- package/dist/server/cli.d.ts +1 -0
- package/dist/server/cli.js +14 -0
- package/dist/server/documentserver.d.ts +14 -0
- package/dist/server/documentserver.js +211 -0
- package/dist/server/image.d.ts +17 -0
- package/dist/server/image.js +161 -0
- package/dist/server/jwt.d.ts +6 -0
- package/dist/server/jwt.js +37 -0
- package/dist/server/patches.json +57 -0
- package/dist/server/themes.d.ts +9 -0
- package/dist/server/themes.js +179 -0
- package/dist/web_hook.d.ts +1 -0
- package/dist/web_hook.js +7 -0
- package/locales/en.json +38 -0
- package/package.json +70 -5
- package/routes/office/+layout.svelte +10 -0
- package/routes/office/+layout.ts +16 -0
- package/routes/office/+page.svelte +90 -0
- package/routes/office/+page.ts +14 -0
- package/routes/office/DocumentCard.svelte +153 -0
- package/routes/office/[id]/+page.svelte +126 -0
- package/routes/office/[id]/+page.ts +6 -0
- package/routes/office/[id]/Editor.svelte +73 -0
- package/routes/tsconfig.json +14 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
|
|
3
|
+
Version 3, 29 June 2007
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
6
|
+
<https://fsf.org/>
|
|
7
|
+
|
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
9
|
+
license document, but changing it is not allowed.
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates the
|
|
12
|
+
terms and conditions of version 3 of the GNU General Public License,
|
|
13
|
+
supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
## 0. Additional Definitions.
|
|
16
|
+
|
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the
|
|
19
|
+
GNU General Public License.
|
|
20
|
+
|
|
21
|
+
"The Library" refers to a covered work governed by this License, other
|
|
22
|
+
than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
|
32
|
+
Version".
|
|
33
|
+
|
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
## 1. Exception to Section 3 of the GNU GPL.
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
## 2. Conveying Modified Versions.
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
- a) under this License, provided that you make a good faith effort
|
|
58
|
+
to ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
- b) under the GNU GPL, with none of the additional permissions of
|
|
62
|
+
this License applicable to that copy.
|
|
63
|
+
|
|
64
|
+
## 3. Object Code Incorporating Material from Library Header Files.
|
|
65
|
+
|
|
66
|
+
The object code form of an Application may incorporate material from a
|
|
67
|
+
header file that is part of the Library. You may convey such object
|
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
|
69
|
+
material is not limited to numerical parameters, data structure
|
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
|
72
|
+
|
|
73
|
+
- a) Give prominent notice with each copy of the object code that
|
|
74
|
+
the Library is used in it and that the Library and its use are
|
|
75
|
+
covered by this License.
|
|
76
|
+
- b) Accompany the object code with a copy of the GNU GPL and this
|
|
77
|
+
license document.
|
|
78
|
+
|
|
79
|
+
## 4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that, taken
|
|
82
|
+
together, effectively do not restrict modification of the portions of
|
|
83
|
+
the Library contained in the Combined Work and reverse engineering for
|
|
84
|
+
debugging such modifications, if you also do each of the following:
|
|
85
|
+
|
|
86
|
+
- a) Give prominent notice with each copy of the Combined Work that
|
|
87
|
+
the Library is used in it and that the Library and its use are
|
|
88
|
+
covered by this License.
|
|
89
|
+
- b) Accompany the Combined Work with a copy of the GNU GPL and this
|
|
90
|
+
license document.
|
|
91
|
+
- c) For a Combined Work that displays copyright notices during
|
|
92
|
+
execution, include the copyright notice for the Library among
|
|
93
|
+
these notices, as well as a reference directing the user to the
|
|
94
|
+
copies of the GNU GPL and this license document.
|
|
95
|
+
- d) Do one of the following:
|
|
96
|
+
- 0) Convey the Minimal Corresponding Source under the terms of
|
|
97
|
+
this License, and the Corresponding Application Code in a form
|
|
98
|
+
suitable for, and under terms that permit, the user to
|
|
99
|
+
recombine or relink the Application with a modified version of
|
|
100
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
101
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
102
|
+
Corresponding Source.
|
|
103
|
+
- 1) Use a suitable shared library mechanism for linking with
|
|
104
|
+
the Library. A suitable mechanism is one that (a) uses at run
|
|
105
|
+
time a copy of the Library already present on the user's
|
|
106
|
+
computer system, and (b) will operate properly with a modified
|
|
107
|
+
version of the Library that is interface-compatible with the
|
|
108
|
+
Linked Version.
|
|
109
|
+
- e) Provide Installation Information, but only if you would
|
|
110
|
+
otherwise be required to provide such information under section 6
|
|
111
|
+
of the GNU GPL, and only to the extent that such information is
|
|
112
|
+
necessary to install and execute a modified version of the
|
|
113
|
+
Combined Work produced by recombining or relinking the Application
|
|
114
|
+
with a modified version of the Linked Version. (If you use option
|
|
115
|
+
4d0, the Installation Information must accompany the Minimal
|
|
116
|
+
Corresponding Source and Corresponding Application Code. If you
|
|
117
|
+
use option 4d1, you must provide the Installation Information in
|
|
118
|
+
the manner specified by section 6 of the GNU GPL for conveying
|
|
119
|
+
Corresponding Source.)
|
|
120
|
+
|
|
121
|
+
## 5. Combined Libraries.
|
|
122
|
+
|
|
123
|
+
You may place library facilities that are a work based on the Library
|
|
124
|
+
side by side in a single library together with other library
|
|
125
|
+
facilities that are not Applications and are not covered by this
|
|
126
|
+
License, and convey such a combined library under terms of your
|
|
127
|
+
choice, if you do both of the following:
|
|
128
|
+
|
|
129
|
+
- a) Accompany the combined library with a copy of the same work
|
|
130
|
+
based on the Library, uncombined with any other library
|
|
131
|
+
facilities, conveyed under the terms of this License.
|
|
132
|
+
- b) Give prominent notice with the combined library that part of it
|
|
133
|
+
is a work based on the Library, and explaining where to find the
|
|
134
|
+
accompanying uncombined form of the same work.
|
|
135
|
+
|
|
136
|
+
## 6. Revised Versions of the GNU Lesser General Public License.
|
|
137
|
+
|
|
138
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
139
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
140
|
+
versions will be similar in spirit to the present version, but may
|
|
141
|
+
differ in detail to address new problems or concerns.
|
|
142
|
+
|
|
143
|
+
Each version is given a distinguishing version number. If the Library
|
|
144
|
+
as you received it specifies that a certain numbered version of the
|
|
145
|
+
GNU Lesser General Public License "or any later version" applies to
|
|
146
|
+
it, you have the option of following the terms and conditions either
|
|
147
|
+
of that published version or of any later version published by the
|
|
148
|
+
Free Software Foundation. If the Library as you received it does not
|
|
149
|
+
specify a version number of the GNU Lesser General Public License, you
|
|
150
|
+
may choose any version of the GNU Lesser General Public License ever
|
|
151
|
+
published by the Free Software Foundation.
|
|
152
|
+
|
|
153
|
+
If the Library as you received it specifies that a proxy can decide
|
|
154
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
155
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
156
|
+
permanent authorization for you to choose that version for the
|
|
157
|
+
Library.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Axium Office
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This is a plugin for editing office documents (docx, xlsx, pptx, odt, ods, odp) stored in Axium's Files, in the browser.
|
|
4
|
+
Editing happens using any document server which supports the OnlyOffice Docs API, like [Euro-Office](https://github.com/euro-office).
|
|
5
|
+
|
|
6
|
+
## Deploying the document server
|
|
7
|
+
|
|
8
|
+
Axium patches the document server for better theming and other UX:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
axium office patch-image # tags axium-documentserver
|
|
12
|
+
axium office patch-image --tag documents:9.3.8 ghcr.io/euro-office/documentserver:v9.3.8
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run it. This example is for Docker Compose:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
services:
|
|
19
|
+
documentserver:
|
|
20
|
+
image: axium-documentserver
|
|
21
|
+
restart: unless-stopped
|
|
22
|
+
ports:
|
|
23
|
+
- 127.0.0.1:8080:80
|
|
24
|
+
environment:
|
|
25
|
+
JWT_SECRET: ${OFFICE_SECRET} # the plugin's `secret`
|
|
26
|
+
volumes:
|
|
27
|
+
- ./documentserver/data:/var/www/euro-office/Data
|
|
28
|
+
- ./documentserver/logs:/var/log/euro-office/documentserver
|
|
29
|
+
- ./documentserver/cache:/var/lib/euro-office/documentserver
|
|
30
|
+
- ./documentserver/database:/var/lib/postgresql
|
|
31
|
+
- ./fonts:/usr/share/fonts/truetype/custom:ro
|
|
32
|
+
# Only if `internal_url` points at this host rather than Axium's public origin
|
|
33
|
+
# extra_hosts:
|
|
34
|
+
# - host.docker.internal:host-gateway
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **Secret:** `JWT_SECRET` must equal the plugin's `secret`. Generate one with `openssl rand -hex 32`.
|
|
38
|
+
- **Volumes:**
|
|
39
|
+
- `Data` holds the server's generated secrets.
|
|
40
|
+
- `cache` holds the files of open sessions.
|
|
41
|
+
- `database` holds the session state that lets editing survive a restart.
|
|
42
|
+
- `logs` is for troubleshooting.
|
|
43
|
+
- **Fonts:** fonts in `/usr/share/fonts/truetype/custom` are indexed when the container starts. Documents whose fonts are missing are laid out with substitutes, so lines and pages break differently; e.g. Palatino Linotype is not included. Add the fonts your documents use (licensed copies, or metric-compatible ones such as TeX Gyre Pagella or URW P052 for Palatino).
|
|
44
|
+
- **Autosave:** the image saves open documents with changes every 5 minutes, not only when the last editor closes or someone presses Save.
|
|
45
|
+
|
|
46
|
+
### TLS and URLs
|
|
47
|
+
|
|
48
|
+
- **Cloudflare Tunnel:** route a hostname such as `documents.example.com` to `http://localhost:8080` and set `server_url` to `https://documents.example.com`. TLS ends at Cloudflare, and the container serves plain HTTP. The tunnel forwards `X-Forwarded-Proto: https` and the public `Host`, which the server uses for the absolute URLs it generates, so no setting is needed.
|
|
49
|
+
- **Other reverse proxies** must forward `Host` (or `X-Forwarded-Host`) and `X-Forwarded-Proto`. To serve the server under a path, the proxy strips the path and sends it as `X-Forwarded-Prefix`, and `server_url` includes it. A hostname of its own is simpler.
|
|
50
|
+
- **TLS in the container:** mount a certificate and key, set `SSL_CERTIFICATE_PATH` and `SSL_KEY_PATH` to their paths, and publish port 443, e.g. `8443:443` for the default `server_url`.
|
|
51
|
+
- **`internal_url`:** the container can reach Axium through its public origin, the default, which goes through the tunnel and needs no host mapping. Or it can use a local address, e.g. `https://host.docker.internal` with the `extra_hosts` entry above. That address needs a certificate the server trusts, or set `USE_UNAUTHORIZED_STORAGE=true`. Local Axium addresses also need `ALLOW_PRIVATE_IP_ADDRESS=true`.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const kinds: readonly ["document", "spreadsheet", "presentation"];
|
|
3
|
+
export declare const Kind: z.ZodLiteral<"document" | "spreadsheet" | "presentation">;
|
|
4
|
+
export type Kind = z.infer<typeof Kind>;
|
|
5
|
+
export interface Format {
|
|
6
|
+
extension: string;
|
|
7
|
+
type: string;
|
|
8
|
+
kind: Kind;
|
|
9
|
+
}
|
|
10
|
+
export declare const formats: readonly Format[];
|
|
11
|
+
/** The format new documents of each kind are created in */
|
|
12
|
+
export declare const newFormats: {
|
|
13
|
+
document: Format;
|
|
14
|
+
spreadsheet: Format;
|
|
15
|
+
presentation: Format;
|
|
16
|
+
};
|
|
17
|
+
export declare const icons: {
|
|
18
|
+
document: string;
|
|
19
|
+
spreadsheet: string;
|
|
20
|
+
presentation: string;
|
|
21
|
+
};
|
|
22
|
+
/** Matches by MIME type first, since browsers set it on upload, then by extension */
|
|
23
|
+
export declare function formatOf(item: {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}): Format | undefined;
|
|
27
|
+
export declare const Config: z.ZodObject<{
|
|
28
|
+
server_url: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
29
|
+
internal_url: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
30
|
+
secret: z.ZodString;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export interface Config extends z.infer<typeof Config> {
|
|
33
|
+
}
|
|
34
|
+
declare module '@axium/core/plugins' {
|
|
35
|
+
interface $PluginConfigs {
|
|
36
|
+
'@axium/office': Config;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export declare const EditorOptions: z.ZodObject<{
|
|
40
|
+
mobile: z.ZodBoolean;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export interface EditorOptions extends z.infer<typeof EditorOptions> {
|
|
43
|
+
}
|
|
44
|
+
export declare const Editor: z.ZodObject<{
|
|
45
|
+
url: z.ZodURL;
|
|
46
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export interface Editor extends z.infer<typeof Editor> {
|
|
49
|
+
}
|
|
50
|
+
export declare const EditorSession: z.ZodObject<{
|
|
51
|
+
item: z.ZodObject<{
|
|
52
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
53
|
+
dataURL: z.ZodString;
|
|
54
|
+
hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
55
|
+
id: z.ZodUUID;
|
|
56
|
+
immutable: z.ZodBoolean;
|
|
57
|
+
modifiedAt: z.ZodCoercedDate<unknown>;
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
userId: z.ZodUUID;
|
|
60
|
+
parentId: z.ZodNullable<z.ZodUUID>;
|
|
61
|
+
size: z.ZodCoercedBigInt<unknown>;
|
|
62
|
+
trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
63
|
+
type: z.ZodString;
|
|
64
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
65
|
+
acl: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
66
|
+
itemId: z.ZodUUID;
|
|
67
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodUUID>>;
|
|
68
|
+
role: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
tag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
70
|
+
user: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
71
|
+
id: z.ZodUUID;
|
|
72
|
+
name: z.ZodString;
|
|
73
|
+
username: z.ZodString;
|
|
74
|
+
email: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodEmail>>>;
|
|
75
|
+
emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
|
|
76
|
+
preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
77
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
78
|
+
theme: z.ZodDefault<z.ZodLiteral<"default" | "light" | "forest" | "midnight" | "beach" | "cherry" | "volcano">>;
|
|
79
|
+
time_zone: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<string>, z.ZodString]>>;
|
|
80
|
+
}, z.core.$strip>>>;
|
|
81
|
+
roles: z.ZodArray<z.ZodString>;
|
|
82
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
83
|
+
registeredAt: z.ZodCoercedDate<unknown>;
|
|
84
|
+
isAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
isSuspended: z.ZodOptional<z.ZodBoolean>;
|
|
86
|
+
}, z.core.$strip>>>;
|
|
87
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
88
|
+
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
89
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
90
|
+
id: z.ZodUUID;
|
|
91
|
+
name: z.ZodString;
|
|
92
|
+
}, z.core.$strip>>>;
|
|
93
|
+
sync: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
94
|
+
rules: z.ZodArray<z.ZodTemplateLiteral<`+${string}` | `-${string}`>>;
|
|
95
|
+
hidden: z.ZodBoolean;
|
|
96
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
97
|
+
devices: z.ZodArray<z.ZodObject<{
|
|
98
|
+
host: z.ZodString;
|
|
99
|
+
localPath: z.ZodString;
|
|
100
|
+
lastSynced: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
101
|
+
itemId: z.ZodUUID;
|
|
102
|
+
userId: z.ZodUUID;
|
|
103
|
+
}, z.core.$strip>>;
|
|
104
|
+
}, z.core.$strip>>>;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
readOnly: z.ZodBoolean;
|
|
107
|
+
canRename: z.ZodBoolean;
|
|
108
|
+
editor: z.ZodObject<{
|
|
109
|
+
url: z.ZodURL;
|
|
110
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
export interface EditorSession extends z.infer<typeof EditorSession> {
|
|
114
|
+
}
|
|
115
|
+
export declare const NewDocument: z.ZodObject<{
|
|
116
|
+
kind: z.ZodLiteral<"document" | "spreadsheet" | "presentation">;
|
|
117
|
+
name: z.ZodString;
|
|
118
|
+
parentId: z.ZodOptional<z.ZodNullable<z.ZodUUID>>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
export interface NewDocument extends z.infer<typeof NewDocument> {
|
|
121
|
+
}
|
|
122
|
+
declare const OfficeAPI: {
|
|
123
|
+
readonly office: {
|
|
124
|
+
readonly PUT: readonly [z.ZodObject<{
|
|
125
|
+
kind: z.ZodLiteral<"document" | "spreadsheet" | "presentation">;
|
|
126
|
+
name: z.ZodString;
|
|
127
|
+
parentId: z.ZodOptional<z.ZodNullable<z.ZodUUID>>;
|
|
128
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
129
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
130
|
+
dataURL: z.ZodString;
|
|
131
|
+
hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
132
|
+
id: z.ZodUUID;
|
|
133
|
+
immutable: z.ZodBoolean;
|
|
134
|
+
modifiedAt: z.ZodCoercedDate<unknown>;
|
|
135
|
+
name: z.ZodString;
|
|
136
|
+
userId: z.ZodUUID;
|
|
137
|
+
parentId: z.ZodNullable<z.ZodUUID>;
|
|
138
|
+
size: z.ZodCoercedBigInt<unknown>;
|
|
139
|
+
trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
140
|
+
type: z.ZodString;
|
|
141
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
142
|
+
acl: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
143
|
+
itemId: z.ZodUUID;
|
|
144
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodUUID>>;
|
|
145
|
+
role: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
146
|
+
tag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
147
|
+
user: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
148
|
+
id: z.ZodUUID;
|
|
149
|
+
name: z.ZodString;
|
|
150
|
+
username: z.ZodString;
|
|
151
|
+
email: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodEmail>>>;
|
|
152
|
+
emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
|
|
153
|
+
preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
154
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
155
|
+
theme: z.ZodDefault<z.ZodLiteral<"default" | "light" | "forest" | "midnight" | "beach" | "cherry" | "volcano">>;
|
|
156
|
+
time_zone: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<string>, z.ZodString]>>;
|
|
157
|
+
}, z.core.$strip>>>;
|
|
158
|
+
roles: z.ZodArray<z.ZodString>;
|
|
159
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
160
|
+
registeredAt: z.ZodCoercedDate<unknown>;
|
|
161
|
+
isAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
162
|
+
isSuspended: z.ZodOptional<z.ZodBoolean>;
|
|
163
|
+
}, z.core.$strip>>>;
|
|
164
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
165
|
+
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
166
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
167
|
+
id: z.ZodUUID;
|
|
168
|
+
name: z.ZodString;
|
|
169
|
+
}, z.core.$strip>>>;
|
|
170
|
+
sync: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
171
|
+
rules: z.ZodArray<z.ZodTemplateLiteral<`+${string}` | `-${string}`>>;
|
|
172
|
+
hidden: z.ZodBoolean;
|
|
173
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
174
|
+
devices: z.ZodArray<z.ZodObject<{
|
|
175
|
+
host: z.ZodString;
|
|
176
|
+
localPath: z.ZodString;
|
|
177
|
+
lastSynced: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
178
|
+
itemId: z.ZodUUID;
|
|
179
|
+
userId: z.ZodUUID;
|
|
180
|
+
}, z.core.$strip>>;
|
|
181
|
+
}, z.core.$strip>>>;
|
|
182
|
+
}, z.core.$strip>];
|
|
183
|
+
};
|
|
184
|
+
readonly 'office/:id': {
|
|
185
|
+
readonly GET: readonly [z.ZodObject<{
|
|
186
|
+
mobile: z.ZodBoolean;
|
|
187
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
188
|
+
item: z.ZodObject<{
|
|
189
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
190
|
+
dataURL: z.ZodString;
|
|
191
|
+
hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
192
|
+
id: z.ZodUUID;
|
|
193
|
+
immutable: z.ZodBoolean;
|
|
194
|
+
modifiedAt: z.ZodCoercedDate<unknown>;
|
|
195
|
+
name: z.ZodString;
|
|
196
|
+
userId: z.ZodUUID;
|
|
197
|
+
parentId: z.ZodNullable<z.ZodUUID>;
|
|
198
|
+
size: z.ZodCoercedBigInt<unknown>;
|
|
199
|
+
trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
200
|
+
type: z.ZodString;
|
|
201
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
202
|
+
acl: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
203
|
+
itemId: z.ZodUUID;
|
|
204
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodUUID>>;
|
|
205
|
+
role: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
206
|
+
tag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
207
|
+
user: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
208
|
+
id: z.ZodUUID;
|
|
209
|
+
name: z.ZodString;
|
|
210
|
+
username: z.ZodString;
|
|
211
|
+
email: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodEmail>>>;
|
|
212
|
+
emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
|
|
213
|
+
preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
214
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
215
|
+
theme: z.ZodDefault<z.ZodLiteral<"default" | "light" | "forest" | "midnight" | "beach" | "cherry" | "volcano">>;
|
|
216
|
+
time_zone: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<string>, z.ZodString]>>;
|
|
217
|
+
}, z.core.$strip>>>;
|
|
218
|
+
roles: z.ZodArray<z.ZodString>;
|
|
219
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
220
|
+
registeredAt: z.ZodCoercedDate<unknown>;
|
|
221
|
+
isAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
+
isSuspended: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
+
}, z.core.$strip>>>;
|
|
224
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
225
|
+
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
226
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
227
|
+
id: z.ZodUUID;
|
|
228
|
+
name: z.ZodString;
|
|
229
|
+
}, z.core.$strip>>>;
|
|
230
|
+
sync: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
231
|
+
rules: z.ZodArray<z.ZodTemplateLiteral<`+${string}` | `-${string}`>>;
|
|
232
|
+
hidden: z.ZodBoolean;
|
|
233
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
234
|
+
devices: z.ZodArray<z.ZodObject<{
|
|
235
|
+
host: z.ZodString;
|
|
236
|
+
localPath: z.ZodString;
|
|
237
|
+
lastSynced: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
238
|
+
itemId: z.ZodUUID;
|
|
239
|
+
userId: z.ZodUUID;
|
|
240
|
+
}, z.core.$strip>>;
|
|
241
|
+
}, z.core.$strip>>>;
|
|
242
|
+
}, z.core.$strip>;
|
|
243
|
+
readOnly: z.ZodBoolean;
|
|
244
|
+
canRename: z.ZodBoolean;
|
|
245
|
+
editor: z.ZodObject<{
|
|
246
|
+
url: z.ZodURL;
|
|
247
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
248
|
+
}, z.core.$strip>;
|
|
249
|
+
}, z.core.$strip>];
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
type OfficeAPI = typeof OfficeAPI;
|
|
253
|
+
declare module '@axium/core/api' {
|
|
254
|
+
interface $API extends OfficeAPI {
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
export {};
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { $API, serverConfigs } from '@axium/core';
|
|
2
|
+
import { StorageItemMetadata } from '@axium/storage/common';
|
|
3
|
+
import * as locales from '@james-pre/locales';
|
|
4
|
+
import * as z from 'zod';
|
|
5
|
+
export const kinds = ['document', 'spreadsheet', 'presentation'];
|
|
6
|
+
export const Kind = z.literal(kinds);
|
|
7
|
+
export const formats = [
|
|
8
|
+
{ extension: 'docx', type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', kind: 'document' },
|
|
9
|
+
{ extension: 'xlsx', type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', kind: 'spreadsheet' },
|
|
10
|
+
{ extension: 'pptx', type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', kind: 'presentation' },
|
|
11
|
+
{ extension: 'odt', type: 'application/vnd.oasis.opendocument.text', kind: 'document' },
|
|
12
|
+
{ extension: 'ods', type: 'application/vnd.oasis.opendocument.spreadsheet', kind: 'spreadsheet' },
|
|
13
|
+
{ extension: 'odp', type: 'application/vnd.oasis.opendocument.presentation', kind: 'presentation' },
|
|
14
|
+
];
|
|
15
|
+
/** The format new documents of each kind are created in */
|
|
16
|
+
export const newFormats = {
|
|
17
|
+
document: formats[0],
|
|
18
|
+
spreadsheet: formats[1],
|
|
19
|
+
presentation: formats[2],
|
|
20
|
+
};
|
|
21
|
+
export const icons = {
|
|
22
|
+
document: 'file-word',
|
|
23
|
+
spreadsheet: 'file-excel',
|
|
24
|
+
presentation: 'file-powerpoint',
|
|
25
|
+
};
|
|
26
|
+
/** Matches by MIME type first, since browsers set it on upload, then by extension */
|
|
27
|
+
export function formatOf(item) {
|
|
28
|
+
const name = item.name.toLowerCase();
|
|
29
|
+
return formats.find(format => format.type == item.type) ?? formats.find(format => name.endsWith('.' + format.extension));
|
|
30
|
+
}
|
|
31
|
+
export const Config = z
|
|
32
|
+
.object({
|
|
33
|
+
/** Where browsers reach the document server */
|
|
34
|
+
server_url: z.url().nullish(),
|
|
35
|
+
/** Where the document server reaches Axium */
|
|
36
|
+
internal_url: z.url().nullish(),
|
|
37
|
+
/** The document server's JWT secret */
|
|
38
|
+
secret: z.string().register(locales.zod, { secret: true }),
|
|
39
|
+
})
|
|
40
|
+
.register(locales.zod, { prefix: 'office.config' });
|
|
41
|
+
serverConfigs.set('@axium/office', Config);
|
|
42
|
+
export const EditorOptions = z.object({
|
|
43
|
+
mobile: z.boolean(),
|
|
44
|
+
});
|
|
45
|
+
export const Editor = z.object({
|
|
46
|
+
/** The document server */
|
|
47
|
+
url: z.url(),
|
|
48
|
+
/** The signed `DocsAPI.DocEditor` configuration */
|
|
49
|
+
config: z.record(z.string(), z.unknown()),
|
|
50
|
+
});
|
|
51
|
+
export const EditorSession = z.object({
|
|
52
|
+
item: StorageItemMetadata,
|
|
53
|
+
readOnly: z.boolean(),
|
|
54
|
+
canRename: z.boolean(),
|
|
55
|
+
editor: Editor,
|
|
56
|
+
});
|
|
57
|
+
export const NewDocument = z.object({
|
|
58
|
+
kind: Kind,
|
|
59
|
+
/** Without the extension, which is added */
|
|
60
|
+
name: z.string().trim().nonempty().max(250),
|
|
61
|
+
parentId: z.uuid().nullish(),
|
|
62
|
+
});
|
|
63
|
+
const OfficeAPI = {
|
|
64
|
+
office: {
|
|
65
|
+
PUT: [NewDocument, StorageItemMetadata],
|
|
66
|
+
},
|
|
67
|
+
'office/:id': {
|
|
68
|
+
GET: [EditorOptions, EditorSession],
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
Object.assign($API, OfficeAPI);
|
package/dist/hooks.d.ts
ADDED
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import serverConfig from '@axium/server/config';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import tls from 'node:tls';
|
|
4
|
+
import './common.js';
|
|
5
|
+
import './server/api.js';
|
|
6
|
+
/** Trusts the certificate Axium serves with, which a self-hosted document server may share */
|
|
7
|
+
export function load() {
|
|
8
|
+
const { ssl_cert } = serverConfig.web;
|
|
9
|
+
if (!existsSync(ssl_cert))
|
|
10
|
+
return;
|
|
11
|
+
tls.setDefaultCACertificates([...tls.getCACertificates('default'), readFileSync(ssl_cert, 'utf8')]);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { authSessionForItem, requireSession } from '@axium/server/auth';
|
|
2
|
+
import { error, isResponseError, parseBody, parseSearch } from '@axium/server/requests';
|
|
3
|
+
import { addRoute } from '@axium/server/routes';
|
|
4
|
+
import { parseItem } from '@axium/storage/server/db';
|
|
5
|
+
import { checkNewItem, createNewItem } from '@axium/storage/server/item';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import * as z from 'zod';
|
|
10
|
+
import { EditorOptions, formatOf, NewDocument, newFormats } from '../common.js';
|
|
11
|
+
import { editorFor } from './documentserver.js';
|
|
12
|
+
async function isAllowed(itemId, permissions, session) {
|
|
13
|
+
return await authSessionForItem('storage', itemId, permissions, session, true).then(() => true, (e) => {
|
|
14
|
+
if (isResponseError(e) && e.status == 403)
|
|
15
|
+
return false;
|
|
16
|
+
throw e;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @todo reduce DB round trips (currently 3)
|
|
21
|
+
*/
|
|
22
|
+
addRoute({
|
|
23
|
+
path: '/api/office/:id',
|
|
24
|
+
params: { id: z.uuid() },
|
|
25
|
+
async GET(request, { id }) {
|
|
26
|
+
const options = parseSearch(request, EditorOptions);
|
|
27
|
+
const session = await requireSession(request);
|
|
28
|
+
const { item: rawItem } = await authSessionForItem('storage', id, { read: true }, session, true);
|
|
29
|
+
const item = parseItem(rawItem);
|
|
30
|
+
if (item.trashedAt)
|
|
31
|
+
error(410, 'Trashed items can not be opened');
|
|
32
|
+
const format = formatOf(item);
|
|
33
|
+
if (!format || item.type == 'inode/directory')
|
|
34
|
+
error(415, 'Office can not open this kind of file');
|
|
35
|
+
const isOwner = item.userId == session.userId;
|
|
36
|
+
const canWrite = !item.immutable && (isOwner || (await isAllowed(id, { write: true }, session)));
|
|
37
|
+
const canRename = isOwner || (await isAllowed(id, { manage: true }, session));
|
|
38
|
+
const editor = editorFor({ item, format, user: session.user, canWrite, options });
|
|
39
|
+
return { item, readOnly: !canWrite, canRename, editor };
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const assets = join(import.meta.dirname, '../../assets/');
|
|
43
|
+
addRoute({
|
|
44
|
+
path: '/api/office',
|
|
45
|
+
async PUT(request) {
|
|
46
|
+
const { kind, name, parentId } = await parseBody(request, NewDocument);
|
|
47
|
+
const session = await requireSession(request);
|
|
48
|
+
const format = newFormats[kind];
|
|
49
|
+
const content = readFileSync(join(assets, `blank.${format.extension}`));
|
|
50
|
+
const init = {
|
|
51
|
+
name: `${name}.${format.extension}`,
|
|
52
|
+
size: BigInt(content.byteLength),
|
|
53
|
+
type: format.type,
|
|
54
|
+
parentId,
|
|
55
|
+
hash: createHash('BLAKE2b512').update(content).digest('hex'),
|
|
56
|
+
};
|
|
57
|
+
await checkNewItem(init, session);
|
|
58
|
+
return await createNewItem(init, session.userId, path => writeFileSync(path, content));
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import * as io from 'ioium/node';
|
|
3
|
+
import { buildImage, defaultBase, detectEngine } from './image.js';
|
|
4
|
+
const cli = program.command('office').helpGroup('Plugins:').description('CLI integration for @axium/office');
|
|
5
|
+
cli.command('patch-image')
|
|
6
|
+
.description("Build the document server image: Euro-Office patched for Axium, with Axium's themes")
|
|
7
|
+
.argument('[base]', 'the Euro-Office image to patch', defaultBase)
|
|
8
|
+
.option('--engine <engine>', 'the container engine, docker or podman (default: whichever is installed)')
|
|
9
|
+
.option('--tag <tag>', 'the tag of the built image', 'axium-documentserver')
|
|
10
|
+
.option('--context <directory>', 'keep the build context in this directory, which is replaced (default: a temporary directory)')
|
|
11
|
+
.action((base, options) => {
|
|
12
|
+
const engine = options.engine ?? detectEngine();
|
|
13
|
+
io.track(`Building ${options.tag} from ${base} with ${engine}`, () => buildImage({ base, engine, tag: options.tag, context: options.context }));
|
|
14
|
+
});
|