diff --git a/handler/file/file.go b/handler/file/file.go
index e4c0378..8ea8978 100644
--- a/handler/file/file.go
+++ b/handler/file/file.go
@@ -14,17 +14,7 @@ import (
func GET(w http.ResponseWriter, r *http.Request) {
userSession := r.Context().Value("user").(types.User)
- query := r.URL.Query().Get("q")
- status := r.URL.Query().Get("status")
- var fileStatus types.FileStatus
- if status == "private" {
- fileStatus = types.Private
- } else if status == "public" {
- fileStatus = types.Public
- } else {
- fileStatus = types.All
- }
- files, err := app.Server.Database.GetFiles(userSession.UserID.String(), query, fileStatus)
+ files, err := app.Server.Database.GetFiles(userSession.UserID.String(), "", types.All)
if err != nil {
app.Server.Logger.Error(err.Error())
w.WriteHeader(http.StatusInternalServerError)
@@ -51,15 +41,6 @@ func GET(w http.ResponseWriter, r *http.Request) {
})
}
- if r.Header.Get("hx-request") == "true" {
- component := fileView.FileTable(filesData)
- err := component.Render(r.Context(), w)
- if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
- return
- }
allowance, err := app.Server.Database.GetAllowance(userSession.UserID)
if err != nil {
app.Server.Logger.Error(err.Error())
diff --git a/handler/file/query/query.go b/handler/file/query/query.go
new file mode 100644
index 0000000..18df543
--- /dev/null
+++ b/handler/file/query/query.go
@@ -0,0 +1,66 @@
+package queryHandler
+
+import (
+ "fmt"
+ "github.com/fossyy/filekeeper/app"
+ "github.com/fossyy/filekeeper/types"
+ "github.com/fossyy/filekeeper/utils"
+ fileView "github.com/fossyy/filekeeper/view/client/file"
+ "net/http"
+ "path/filepath"
+ "strconv"
+)
+
+func GET(w http.ResponseWriter, r *http.Request) {
+ userSession := r.Context().Value("user").(types.User)
+ query := r.URL.Query().Get("q")
+ status := r.URL.Query().Get("status")
+ var fileStatus types.FileStatus
+ if status == "private" {
+ fileStatus = types.Private
+ } else if status == "public" {
+ fileStatus = types.Public
+ } else {
+ fileStatus = types.All
+ }
+ files, err := app.Server.Database.GetFiles(userSession.UserID.String(), query, fileStatus)
+ if err != nil {
+ app.Server.Logger.Error(err.Error())
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ var filesData []types.FileData
+
+ for _, file := range files {
+ saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String())
+
+ pattern := fmt.Sprintf("%s/chunk_*", saveFolder)
+ chunkFiles, err := filepath.Glob(pattern)
+
+ missingChunk := err != nil || len(chunkFiles) != int(file.TotalChunk)
+
+ filesData = append(filesData, types.FileData{
+ ID: file.ID.String(),
+ Name: file.Name,
+ Size: utils.ConvertFileSize(file.Size),
+ IsPrivate: file.IsPrivate,
+ Type: file.Type,
+ Done: !missingChunk,
+ Downloaded: strconv.FormatUint(file.Downloaded, 10),
+ })
+ }
+
+ if r.Header.Get("hx-request") == "true" {
+ component := fileView.FileTable(filesData)
+ err := component.Render(r.Context(), w)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ return
+ }
+
+ w.WriteHeader(http.StatusForbidden)
+ return
+}
diff --git a/routes/client/routes.go b/routes/client/routes.go
index 4964c8a..03c4772 100644
--- a/routes/client/routes.go
+++ b/routes/client/routes.go
@@ -8,6 +8,7 @@ import (
fileHandler "github.com/fossyy/filekeeper/handler/file"
deleteHandler "github.com/fossyy/filekeeper/handler/file/delete"
downloadHandler "github.com/fossyy/filekeeper/handler/file/download"
+ queryHandler "github.com/fossyy/filekeeper/handler/file/query"
renameFileHandler "github.com/fossyy/filekeeper/handler/file/rename"
uploadHandler "github.com/fossyy/filekeeper/handler/file/upload"
visibilityHandler "github.com/fossyy/filekeeper/handler/file/visibility"
@@ -116,6 +117,10 @@ func SetupRoutes() *http.ServeMux {
middleware.Auth(fileHandler.GET, w, r)
})
+ handler.HandleFunc("GET /file/query", func(w http.ResponseWriter, r *http.Request) {
+ middleware.Auth(queryHandler.GET, w, r)
+ })
+
handler.HandleFunc("POST /file/{id}", func(w http.ResponseWriter, r *http.Request) {
middleware.Auth(uploadHandler.POST, w, r)
})
diff --git a/view/admin/index/index_templ.go b/view/admin/index/index_templ.go
index a4a91b9..db05664 100644
--- a/view/admin/index/index_templ.go
+++ b/view/admin/index/index_templ.go
@@ -31,7 +31,7 @@ func Main() templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
System Usage
Real-time metrics for your server.
User List
Manage your registered users.
Name\r | Email\r | Role\r | Actions\r |
John Doe | john@example.com | Admin\r | |
Jane Smith | jane@example.com | Editor\r | |
Bob Johnson | bob@example.com | User\r | |
Server Control
Manage your server instances.
Server Environment
Manage your server environment variables.
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/admin/layout/base_templ.go b/view/admin/layout/base_templ.go
index 8f70e90..a2010ab 100644
--- a/view/admin/layout/base_templ.go
+++ b/view/admin/layout/base_templ.go
@@ -23,7 +23,7 @@ func Base() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Admin Page")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -31,7 +31,7 @@ func Base() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/client/auth/auth_templ.go b/view/client/auth/auth_templ.go
index ee59e7e..d22ac2c 100644
--- a/view/client/auth/auth_templ.go
+++ b/view/client/auth/auth_templ.go
@@ -34,13 +34,13 @@ func form(err types.Message, title string) templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Set Up Your Account
Enter your information to create a new account
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
switch err.Code {
case 0:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -53,12 +53,12 @@ func form(err types.Message, title string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
case 1:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -71,12 +71,12 @@ func form(err types.Message, title string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Already have an account?
Sign in ")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/client/email/email_templ.go b/view/client/email/email_templ.go
index e2fd38c..e263bc9 100644
--- a/view/client/email/email_templ.go
+++ b/view/client/email/email_templ.go
@@ -23,7 +23,7 @@ func RegistrationEmail(name string, link string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Email VerificationEmail Verification
Dear ")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -36,7 +36,7 @@ func RegistrationEmail(name string, link string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(",
Please verify your email address by clicking the button below:
Verify EmailOr copy and paste this URL into a new tab of your browser:
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -67,7 +67,7 @@ func RegistrationEmail(name string, link string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
If you did not request this verification, please disregard this email.
Thank you,
The Filekeeper Team
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -91,7 +91,7 @@ func ForgotPassword(name string, link string) templ.Component {
templ_7745c5c3_Var6 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Email VerificationPassword Change Request
Dear ")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -104,7 +104,7 @@ func ForgotPassword(name string, link string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(",
Please verify your password change request by clicking the button below:
Verify Password ChangeOr copy and paste this URL into a new tab of your browser:
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -135,7 +135,7 @@ func ForgotPassword(name string, link string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
If you did not request this password change, please disregard this email.
Thank you,
The Filekeeper Team
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/client/error/error_templ.go b/view/client/error/error_templ.go
index 8b53f96..ce8a709 100644
--- a/view/client/error/error_templ.go
+++ b/view/client/error/error_templ.go
@@ -31,7 +31,7 @@ func NotFound(title string) templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("404 Not Found
The page you are looking for does not exist. It might have been moved or deleted.
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -70,7 +70,7 @@ func InternalServerError(title string) templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Oops! Something went wrong.
We're sorry, but an internal server error has occurred. Please try again later.
")
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/client/file/file.templ b/view/client/file/file.templ
index 023ecaf..0baccfc 100644
--- a/view/client/file/file.templ
+++ b/view/client/file/file.templ
@@ -108,9 +108,9 @@ templ MainContent(title string, files []types.FileData, user types.User, allowan
-
+
-