-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add editor to metadata * add client * fix stuff
- Loading branch information
1 parent
3348a79
commit 434f411
Showing
9 changed files
with
783 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.