Skip to content

Commit

Permalink
Add Client and WebDAV stuff (#17)
Browse files Browse the repository at this point in the history
* add editor to metadata

* add client

* fix stuff
  • Loading branch information
Kruemmelspalter authored Dec 27, 2022
1 parent 3348a79 commit 434f411
Show file tree
Hide file tree
Showing 9 changed files with 783 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class DocumentMeta(
val id: UUID,
val title: String,
val added: Timestamp,
val editor: String,
val created: Timestamp,
val modified: Timestamp,
val accessed: Timestamp,
Expand All @@ -19,5 +20,5 @@ data class DocumentMeta(
modified: Timestamp,
accessed: Timestamp,
tags: List<String>
) : this(doc.id, doc.title, doc.added, created, modified, accessed, tags)
) : this(doc.id, doc.title, doc.added, doc.editor, created, modified, accessed, tags)
}
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
66 changes: 66 additions & 0 deletions client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const express = require('express')
const proxy = require('express-http-proxy')
const { execSync, spawn } = require("child_process")
const axios = require('axios')

const API_HOST = 'http://172.31.69.5'
const MOUNT_PATH = process.env.HOME + '/.filespider'
const PORT = 8080

const app = express()

const editors = {
mimeSpecific: path => ({explorer: true, command: 'xdg-open', args: [path]}),
plain: path => ({explorer: true, command: 'kate', args: [path]}),
xournalpp: path => ({explorer: true, command: 'xournalpp', args: [path]}),
}

function mountWebDAV(host) {
execSync(`mkdir -p ${MOUNT_PATH}`)
console.log('created directory')
execSync(`konsole -e 'sudo mount -t davfs -o uid=${process.getuid()},gid=${process.getgid()} ${API_HOST}/files/ ${MOUNT_PATH}'`)
console.log('mounted')
}

function unmountWebDAV() {
execSync(`konsole -e 'sudo umount ${MOUNT_PATH}'`)
}

app.post('/document/:docId/edit', async (req, res) => {
var meta
try {
meta = await axios.get(`${API_HOST}/document/${req.params.docId}`)
} catch(e) {
res.status(500).send({path: `${API_HOST}/document/${req.params.docId}`, error: e})
return
}
const path = `${MOUNT_PATH}/${req.params.docId}/${req.params.docId}`
const editor = editors[meta.data.editor](path)
if(editor === undefined) {
res.status(400).send(`Wrong editor ${meta.data.editor}`)
console.log(`Wrong editor ${meta.data.editor}`)
return
}
if(editor.explorer) spawn('dolphin', [`${path}/..`])
spawn(editor.command, editor.args)
res.send()
})

app.use('/', proxy(API_HOST))

var server
async function startServer() {
await mountWebDAV(API_HOST)
server = app.listen(PORT, () => console.log(`Server listening on http://localhost:${PORT}`))
}


function stopServer() {
console.log('Unmounting...')
if(server?.close !== undefined) server.close()
unmountWebDAV()
}

process.on('SIGINT', stopServer)

startServer()
14 changes: 14 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "filespider-client",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"axios": "^1.2.1",
"express": "^4.18.2",
"express-http-proxy": "^1.6.3"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}
Loading

0 comments on commit 434f411

Please sign in to comment.