Fresh start (#110)
* Fresh start * Create an xml include plugin (#111) * Restructure and add testing (#114) * rooibos setup * Restructure and add testing * docs * Restore manifestpipi * Description in tools * A bit of docs * Auto bind feature (#115) * Auto bind feature * Fix children merge * bs plugin fix * Feature/app controller (#120) * Initial layout * Restructuring and plugin work * A couple of tweaks in binding stuff * tweaks * basic stack * Add basic app controller * Support json5/yaml in playlet config files (#123) * Support json5 in playlet config files * Add yaml to the mix * Delete old lib project * plugin fix * plugin tweak * verbose logging * Revert "verbose logging" This reverts commit 25867f4226703d83102519a0d48d1cc46a9876de. * One idea to fix the include plugin * Fix instability in plugins * Feature/navbar (#126) * Navbar * typo * comment * Single content node, and tests * Remove unused field * tweaks * update dependencies command * tweak formatting * Add web app screen * Set id in created screens * Search screen * Tests * Show playlists and channels in search results * Move screen stuff to app controller * Home screen (wip) * Add preferences node * README.md copyedits (#130) * README.md: Fix typos * README.md: Standardize capitalization and punctuation * Update docs/README.md --------- Co-authored-by: Brahim Hadriche <brahim.hadriche@gmail.com> * Web server: round 1 (#131) * web server object * Logging * Web server round 1 * Lint fix * Small tweaks --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Logging to file * Leftover * Add logs file to web server * Fix for timeout * Disable keepalive connection * add openapi spec file * Lint fix * add prefs version in api * Add ecp api definition * Lint fix * Settings rework (#135) * Settings rework * Standard OnFocusChange event * Video player stuff (#136) * Video player stuff * Restructure things so that focus is better handled * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Exit dialog * A bunch of changes * New http client * Set TODO priorities * picture in picture * mark video watched * Video player stuff mostly there * update spec file * Sponsorblock * FuncName * SponsorBlock notifications * Lint fix * misc * remove basic auth feature flag (until we start using it) * Play queue part 1 * type fix * handle unicode in request body * SponsorBlock chapter label * modal base * remove a hack * Invidious settings * web server reduce timeout * Test for captions * Lint fix * remove rpc stuff * small change * Solve focus management * a couple of fixes * Remove a bunch of todos * feed error handling wip * Lint fix * navigation in instance settings * home screen pagination support * Refactor feed to support pagination on search page * cell loading animation * Tweak caching * delete test screen * playlist support part 1 * Basic playlist view * Restore playlist/channel handler * Refactor some content node stuff, and add an auth popup dialog * A bad implementation of a playqueue * Lint fix * playlist cast fix * Feature/web app catch up (#139) * playlist cast fix * Move things around * support playlists in web app * update api * Bump deps * Downgrade todo --------- Co-authored-by: Bryce Harrington <bryce@bryceharrington.org> Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
349 files changed
+12784
-7660
No files matched your search
@@ -0,0 +1,34 @@
|
||||
namespace Http
|
||||
|
||||
class CorsMiddleware extends HttpRouter
|
||||
private origin
|
||||
private headers
|
||||
private methods
|
||||
|
||||
function new(origin = "*" as string, headers = "*" as string, methods = "POST, PUT, GET, DELETE, OPTIONS" as string)
|
||||
super()
|
||||
|
||||
m.origin = origin
|
||||
m.headers = headers
|
||||
m.methods = methods
|
||||
|
||||
m.All("*", function(context as object) as boolean
|
||||
router = context.router
|
||||
request = context.request
|
||||
response = context.response
|
||||
response.headers["Access-Control-Allow-Origin"] = router.origin
|
||||
response.headers["Access-Control-Allow-Headers"] = router.headers
|
||||
response.headers["Access-Control-Allow-Methods"] = router.methods
|
||||
|
||||
if request.method = "OPTIONS"
|
||||
response.header_only = true
|
||||
response.http_code = 200
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Http
|
||||
|
||||
class HttpDefaultRouter extends HttpRouter
|
||||
|
||||
function new()
|
||||
super()
|
||||
|
||||
m.All("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
method = request.method
|
||||
uri = request.uri
|
||||
|
||||
if method = ""
|
||||
response.Default(400, "You sent a request that the server couldn't understand.")
|
||||
else
|
||||
response.Default(404, `Cannot ${method} ${uri}`)
|
||||
end if
|
||||
|
||||
return true
|
||||
end function)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,216 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
namespace Http
|
||||
|
||||
class HttpStaticFilesRouter extends HttpRouter
|
||||
private log as log.Logger
|
||||
|
||||
private root
|
||||
private route
|
||||
private showDirectories
|
||||
private showHidden
|
||||
private fsCheck
|
||||
|
||||
function new(route as string, root as string, showDirectories = false as boolean, showHidden = false as boolean, fsCheck = true as boolean)
|
||||
super()
|
||||
m.log = new log.Logger("HttpStaticFilesRouter")
|
||||
|
||||
m.root = root
|
||||
m.route = route
|
||||
m.showDirectories = showDirectories
|
||||
m.showHidden = showHidden
|
||||
m.fsCheck = fsCheck
|
||||
|
||||
m.Get("*", function(context as object) as boolean
|
||||
router = context.router
|
||||
request = context.request
|
||||
response = context.response
|
||||
server = context.server
|
||||
|
||||
if not request.route.StartsWith(router.route)
|
||||
return false
|
||||
end if
|
||||
|
||||
path_in_route = request.route.Mid(router.route.Len())
|
||||
|
||||
decoded_path = path_in_route.DecodeUri()
|
||||
full_path = StringUtils.PathJoin(router.root, decoded_path)
|
||||
|
||||
if not router.fsCheck
|
||||
' libpkg:/ does not work with roFilesystem...
|
||||
buffer = createObject("roByteArray")
|
||||
if buffer.ReadFile(full_path) and buffer.count() > 0
|
||||
mimetype = server.utils.MimeType(decoded_path)
|
||||
response.SetBodyDataBuffer(buffer)
|
||||
response.ContentType(mimetype)
|
||||
response.http_code = 200
|
||||
response.source = Http.HttpResponseSource.GENERATED
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
|
||||
path = CreateObject("roPath", full_path)
|
||||
fs = CreateObject("roFilesystem")
|
||||
|
||||
if not path.isValid()
|
||||
' Skip, let next middleware handle it
|
||||
return false
|
||||
else if not fs.exists(path)
|
||||
' Skip, let next middleware handle it
|
||||
return false
|
||||
end if
|
||||
|
||||
stat = fs.stat(path)
|
||||
if stat = invalid
|
||||
response.Default(500, "fstat() failed.")
|
||||
return true
|
||||
end if
|
||||
|
||||
if stat.type = "directory"
|
||||
if not router.showDirectories
|
||||
response.Default(403, "Forbidden")
|
||||
return true
|
||||
end if
|
||||
response.ContentType("text/html")
|
||||
router.GenerateDirectoryListing(path, router, request, response)
|
||||
return true
|
||||
else if stat.type = "file"
|
||||
mimetype = server.utils.MimeType(decoded_path)
|
||||
response.ContentType(mimetype)
|
||||
response.fileLength = stat.size
|
||||
router.log.info(`uri=${request.uri}, target=${path}, content-type=${mimetype}, content-length=${response.fileLength}`)
|
||||
router.GenerateFile(path, router, request, response)
|
||||
return true
|
||||
else
|
||||
response.Default(403, "Not a regular file.")
|
||||
return true
|
||||
end if
|
||||
end function)
|
||||
end function
|
||||
|
||||
function GenerateFile(path as object, router as object, request as HttpRequest, response as HttpResponse) as boolean
|
||||
response.path = path
|
||||
response.source = Http.HttpResponseSource.FROMFILE
|
||||
fileFinish = response.fileLength - 1
|
||||
|
||||
if request.range_begin_given or request.range_end_given
|
||||
start = 0
|
||||
finish = 0
|
||||
if request.range_begin_given and request.range_end_given
|
||||
' 100-200
|
||||
start = request.range_begin
|
||||
finish = request.range_end
|
||||
' clamp finish to fileFinish
|
||||
if finish > fileFinish
|
||||
finish = fileFinish
|
||||
end if
|
||||
else if request.range_begin_given and not request.range_end_given
|
||||
' 100- :: yields 100 to end
|
||||
start = request.range_begin
|
||||
finish = fileFinish
|
||||
else if not request.range_begin_given and request.range_end_given
|
||||
' -200 :: yields last 200
|
||||
finish = fileFinish
|
||||
start = finish - request.range_end + 1
|
||||
' check for wrapping
|
||||
if start > finish
|
||||
start = 0
|
||||
end if
|
||||
else
|
||||
router.log.error(1, "internal error - range start/finish logic inconsistency")
|
||||
end if
|
||||
|
||||
response.start = start
|
||||
response.body_buffer_length = finish - start + 1
|
||||
response.ContentLength(response.body_buffer_length)
|
||||
response.headers["Content-Range"] = "bytes " + response.MakeRange(response.start, response.body_buffer_length, response.filelength)
|
||||
response.http_code = 206
|
||||
|
||||
router.log.info("sending range " + response.MakeRange(start, response.body_buffer_length, response.fileLength))
|
||||
else ' no range stuff
|
||||
response.body_buffer_length = response.fileLength
|
||||
response.ContentLength(response.body_buffer_length)
|
||||
response.http_code = 200
|
||||
end if
|
||||
|
||||
response.headers["Accept-Ranges"] = "bytes"
|
||||
response.KeepAlive(true)
|
||||
return true
|
||||
end function
|
||||
|
||||
function GenerateDirectoryListing(path as object, router as object, request as HttpRequest, response as HttpResponse) as boolean
|
||||
fs = CreateObject("roFilesystem")
|
||||
dirList = fs.GetDirectoryListing(path)
|
||||
if dirList = invalid
|
||||
response.default(500, "Couldn't list directory")
|
||||
return false
|
||||
end if
|
||||
|
||||
' for tabbed alignment of file sizes
|
||||
maxlen = 0
|
||||
for each item in dirList
|
||||
il = item.len()
|
||||
if maxlen < il
|
||||
maxlen = il
|
||||
end if
|
||||
end for
|
||||
|
||||
listing = `<html>
|
||||
<head>
|
||||
<title>${response.settings.ServerName}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${request.uri.DecodeUri()}</h1>
|
||||
<tt><pre>\n`
|
||||
|
||||
dir = path.getString()
|
||||
if dir.len() > 0 and dir.right(1) <> "/"
|
||||
dir = dir + "/"
|
||||
end if
|
||||
uriDir = request.uri
|
||||
if uriDir.len() > 0 and uriDir.right(1) <> "/"
|
||||
uriDir = uriDir + "/"
|
||||
end if
|
||||
|
||||
routeDir = router.route
|
||||
if routeDir.len() > 0 and routeDir.right(1) <> "/"
|
||||
routeDir = routeDir + "/"
|
||||
end if
|
||||
|
||||
if not uriDir = routeDir
|
||||
uri = uriDir + ".."
|
||||
listing += `<a href="${uri}">..</a>\n`
|
||||
end if
|
||||
|
||||
for each item in dirList
|
||||
if router.showHidden or item.left(1) <> "."
|
||||
indicator = invalid
|
||||
stat = fs.stat(dir + item)
|
||||
if stat <> invalid
|
||||
if stat.doesexist("type") and stat.type = "directory"
|
||||
indicator = "/"
|
||||
else if stat.doesexist("size")
|
||||
indicator = string(maxlen - item.len(), " ") + Stri(stat.size)
|
||||
end if
|
||||
end if
|
||||
if indicator <> invalid
|
||||
uri = uriDir + item
|
||||
safe_url = uri ' UrlEncode(uri) ' too much encoding
|
||||
listing += `<a href="${safe_url}">${item}${indicator}</a>\n`
|
||||
else
|
||||
router.log.warn("insufficient stat info to include '" + dir + item + "'")
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
|
||||
listing += `</pre></tt><hr>${response.GeneratedBy()}</body></html>`
|
||||
|
||||
response.SetBodyDataString(listing)
|
||||
response.http_code = 200
|
||||
response.KeepAlive(true)
|
||||
response.source = Http.HttpResponseSource.GENERATED
|
||||
return true
|
||||
end function
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user