code refactoring

This commit is contained in:
2023-05-26 15:10:23 +02:00
parent 985629fd2e
commit 58b05e1403
3 changed files with 5 additions and 11 deletions

View File

@@ -66,7 +66,6 @@ export default function Downloaded() {
? folders.slice(-(folders.length - 1)).join('/') ? folders.slice(-(folders.length - 1)).join('/')
: folders.pop() : folders.pop()
const _upperLevel = folders.slice(1, -1) const _upperLevel = folders.slice(1, -1)
const upperLevel = _upperLevel.length === 2 const upperLevel = _upperLevel.length === 2
? ['.', ..._upperLevel].join('/') ? ['.', ..._upperLevel].join('/')
@@ -131,7 +130,7 @@ export default function Downloaded() {
const onFileClick = (path: string) => startTransition(() => { const onFileClick = (path: string) => startTransition(() => {
window.open(`${serverAddr}/play?path=${Buffer.from(path).toString('hex')}`) window.open(`${serverAddr}/d/${Buffer.from(path).toString('hex')}`)
}) })
const onFolderClick = (path: string) => startTransition(() => { const onFolderClick = (path: string) => startTransition(() => {

View File

@@ -94,12 +94,8 @@ func DeleteFile(ctx *fiber.Ctx) error {
return ctx.JSON("ok") return ctx.JSON("ok")
} }
type PlayRequest struct { func SendFile(ctx *fiber.Ctx) error {
Path string path := ctx.Params("id")
}
func PlayFile(ctx *fiber.Ctx) error {
path := ctx.Query("path")
if path == "" { if path == "" {
return errors.New("inexistent path") return errors.New("inexistent path")
@@ -114,10 +110,9 @@ func PlayFile(ctx *fiber.Ctx) error {
// TODO: further path / file validations // TODO: further path / file validations
if strings.Contains(filepath.Dir(string(decoded)), root) { if strings.Contains(filepath.Dir(string(decoded)), root) {
ctx.SendStatus(fiber.StatusPartialContent) ctx.SendStatus(fiber.StatusOK)
return ctx.SendFile(string(decoded)) return ctx.SendFile(string(decoded))
} }
ctx.Status(fiber.StatusOK)
return ctx.SendStatus(fiber.StatusUnauthorized) return ctx.SendStatus(fiber.StatusUnauthorized)
} }

View File

@@ -45,7 +45,7 @@ func RunBlocking(port int, frontend fs.FS) {
app.Post("/downloaded", rest.ListDownloaded) app.Post("/downloaded", rest.ListDownloaded)
app.Post("/delete", rest.DeleteFile) app.Post("/delete", rest.DeleteFile)
app.Get("/play", rest.PlayFile) app.Get("/d/:id", rest.SendFile)
// RPC handlers // RPC handlers
// websocket // websocket