Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Client and WebDAV stuff #17

Merged
merged 3 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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