Skip to content

Commit

Permalink
Enhance share extension with HTML and view
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Jan 18, 2025
1 parent 9c7451f commit 60f435f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
13 changes: 12 additions & 1 deletion extensions/share/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,21 @@
"type": "string",
"default": "rwl"
},
"mode": {
"title": "The mode",
"type": "string",
"enumValues": [
{"const": "HTML", "title": "HTML"},
{"const": "HTTP", "title": "HTTP"},
{"const": "WebDAV", "title": "WebDAV"}
],
"default": "HTML"
},
"useWebDAV": {
"title": "Use WebDAV",
"type": "boolean",
"default": false
"default": false,
"deprecated": true
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions extensions/share/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define(['./share.xml', 'engine/configuration/extensions/share/'], function(shareTemplate, shareConfig) {

var shareVue = new Vue({
template: shareTemplate,
data: {
shares: shareConfig.value.shares || []
}
});

addPageComponent(shareVue, 'share');

});
12 changes: 10 additions & 2 deletions extensions/share/share.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ local extension = ...

local logger = extension:getLogger()
local FileHttpHandler = require('jls.net.http.handler.FileHttpHandler')
local HtmlFileHttpHandler = require('jls.net.http.handler.HtmlFileHttpHandler')
local ProxyHttpHandler = require('jls.net.http.handler.ProxyHttpHandler')
local WebDavHttpHandler = require('jls.net.http.handler.WebDavHttpHandler')

local utils = require('lha.utils')

local webBaseAddons = extension:require('web-base.addons', true)

webBaseAddons.register(extension)

local function isValidPath(name)
if not name or name == '' or name == 'engine' or name == 'things' then
logger:warn('Invalid share name "%s"', name)
Expand All @@ -25,9 +31,11 @@ extension:subscribeEvent('startup', function()
logger:warn('Invalid share directory "%s"', dir)
end
if isValidPath(share.name) then
logger:info('Share directory "%s" on "%s"', dir, share.name)
logger:info('Share directory "%s" on "/%s"', dir, share.name)
local path = '/'..share.name..'/(.*)'
if share.useWebDAV then
if share.mode == 'HTML' then
extension:addContext(path, HtmlFileHttpHandler:new(dir, share.permissions))
elseif share.mode == 'WebDAV' then
extension:addContext(path, WebDavHttpHandler:new(dir, share.permissions))
else
extension:addContext(path, FileHttpHandler:new(dir, share.permissions))
Expand Down
16 changes: 16 additions & 0 deletions extensions/share/share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<app-page id="share" title="Share">
<template slot="bar-right">
<button v-on:click="app.toPage('extension', 'share')" title="Configuration"><i class="fas fa-cog"></i></button>
</template>
<article>
<div class="tile-container">
<template v-for="share in shares">
<div class="tile">
<div class="bar">
<a :href="share.name + '/'">{{ share.name }}</span>
</div>
</div>
</template>
</div>
</article>
</app-page>

0 comments on commit 60f435f

Please sign in to comment.