This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
125 lines (109 loc) · 3.9 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import {v2 as webdav} from "webdav-server";
import * as express from 'express'
import WebFileSystem from "./WebFileSystem";
import UserManager from "./UserManager";
import logger from './logger';
import {environment} from './config/globals';
import Propfind from "webdav-server/lib/server/v2/commands/Propfind";
const userManager = new UserManager()
const server = new webdav.WebDAVServer({
httpAuthentication: new webdav.HTTPBasicAuthentication(userManager)
});
server.setFileSystem('courses', new WebFileSystem('courses'), (succeeded) => {
if (succeeded) {
logger.info("Successfully mounted 'courses' file system!")
}
});
server.setFileSystem('my', new WebFileSystem('my'), (succeeded) => {
if (succeeded) {
logger.info("Successfully mounted 'my files' file system!")
}
});
server.setFileSystem('teams', new WebFileSystem('teams'), (succeeded) => {
if (succeeded) {
logger.info("Successfully mounted 'teams' file system!")
}
});
server.setFileSystem('shared', new WebFileSystem('shared'), (succeeded) => {
if (succeeded) {
logger.info("Successfully mounted 'shared' file system!")
}
});
const app = express()
/*
Calling GET /ocs/v1.php/cloud/capabilities?format=json...
Calling GET /ocs/v1.php/config?format=json...
Calling GET /ocs/v1.php/cloud/user?format=json...
Calling GET /remote.php/dav/avatars/[email protected]/128.png...
Calling GET /ocs/v2.php/apps/notifications/api/v2/notifications?format=json...
Calling GET /ocs/v2.php/core/navigation/apps?absolute=true&format=json...
*/
app.use((req, res, next) => {
logger.info('Calling ' + req.method + ' ' + req.originalUrl + '...')
next()
})
app.get('/nextcloud/status.php', (req, res) => {
logger.info('Requesting status...')
// TODO: Answer with real data
res.send({
installed: true,
maintenance: false,
needsDbUpgrade: false,
version: "10.0.3.3",
versionstring: "10.0.3",
edition: "Community",
productname: "HPI Schul-Cloud"
})
})
// TODO: Determine what is needed
const capabilities = {
ocs: {
data: {
capabilities: {
files: {
blacklisted_files : [],
bigfilechunking: false,
privateLinks: false,
privateLinksDetailsParam: false,
undelete: false,
versioning: false
},
dav: {
chunking: '1.0'
},
core: {
'webdav-root' : environment.WEBDAV_ROOT,
status: {
edition: 'Community',
installed: 'true',
needsDbUpgrade: 'false',
versionstring: '10.0.3',
productname: 'HPI Schul-Cloud',
maintenance: 'false',
version : '10.0.3.3'
},
pollinterval: 60
}
}
}
}
}
app.get('/ocs/v1.php/cloud/capabilities?format=json', (req, res) => {
logger.info('Requesting v1 capabilities (JSON)...')
res.send(capabilities)
})
// Seems to get requested much earlier, however, nextcloud tries to get /remote.php/webdav
app.get('/ocs/v2.php/cloud/capabilities?format=json', (req, res) => {
logger.info('Requesting v2 capabilities (JSON)...')
res.send(capabilities)
})
// HEAD Request to webdav root maybe needs to be processed, doesn't work until now
app.head('/remote.php/webdav/', (req, res, next) => {
logger.info('Requesting HEAD of root...')
res.send()
})
// root path doesn't seem to work that easily with all webdav clients, if it doesn't work simply put an empty string there
app.use(webdav.extensions.express(environment.WEBDAV_ROOT, server))
app.listen(environment.PORT, () => {
logger.info('Ready on port ' + environment.PORT)
})