diff --git a/db/database.go b/db/database.go
index 7001117..03b4cd3 100644
--- a/db/database.go
+++ b/db/database.go
@@ -243,6 +243,17 @@ func (db *mySQLdb) GetFile(fileID string) (*models.File, error) {
return &file, nil
}
+func (db *mySQLdb) RenameFile(fileID string, name string) (*models.File, error) {
+ var file models.File
+ err := db.DB.Table("files").Where("id = ?", fileID).First(&file).Error
+ file.Name = name
+ err = db.DB.Save(&file).Error
+ if err != nil {
+ return &file, err
+ }
+ return &file, nil
+}
+
func (db *mySQLdb) DeleteFile(fileID string) error {
err := db.DB.Table("files").Where("id = ?", fileID).Delete(&models.File{}).Error
if err != nil {
@@ -411,6 +422,17 @@ func (db *postgresDB) GetFile(fileID string) (*models.File, error) {
return &file, nil
}
+func (db *postgresDB) RenameFile(fileID string, name string) (*models.File, error) {
+ var file models.File
+ err := db.DB.Table("files").Where("id = $1", fileID).First(&file).Error
+ file.Name = name
+ err = db.DB.Save(&file).Error
+ if err != nil {
+ return &file, err
+ }
+ return &file, nil
+}
+
func (db *postgresDB) DeleteFile(fileID string) error {
err := db.DB.Table("files").Where("id = $1", fileID).Delete(&models.File{}).Error
if err != nil {
diff --git a/handler/file/download/download.go b/handler/file/download/download.go
index 33ef009..66d3b2c 100644
--- a/handler/file/download/download.go
+++ b/handler/file/download/download.go
@@ -93,7 +93,7 @@ func sendFileChunk(w http.ResponseWriter, saveFolder string, file *models.File,
endOffset := end % chunkSize
for i := startChunk; i <= endChunk; i++ {
- chunkPath := filepath.Join(saveFolder, file.Name, fmt.Sprintf("chunk_%d", i))
+ chunkPath := filepath.Join(saveFolder, fmt.Sprintf("chunk_%d", i))
chunkFile, err := os.Open(chunkPath)
if err != nil {
http.Error(w, fmt.Sprintf("Error opening chunk: %v", err), http.StatusInternalServerError)
diff --git a/handler/file/file.go b/handler/file/file.go
index cbb2e25..6976f85 100644
--- a/handler/file/file.go
+++ b/handler/file/file.go
@@ -23,7 +23,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
var filesData []types.FileData
for _, file := range files {
- saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String(), file.Name)
+ saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String())
pattern := fmt.Sprintf("%s/chunk_*", saveFolder)
chunkFiles, err := filepath.Glob(pattern)
diff --git a/handler/file/rename/rename.go b/handler/file/rename/rename.go
new file mode 100644
index 0000000..7a61e30
--- /dev/null
+++ b/handler/file/rename/rename.go
@@ -0,0 +1,65 @@
+package renameFileHandler
+
+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 PATCH(w http.ResponseWriter, r *http.Request) {
+ fileID := r.PathValue("id")
+ newName := r.URL.Query().Get("name")
+ userSession := r.Context().Value("user").(types.User)
+
+ file, err := app.Server.Database.GetFile(fileID)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ if userSession.UserID != file.OwnerID {
+ w.WriteHeader(http.StatusUnauthorized)
+ return
+ }
+
+ if newName == "" {
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
+ newFile, err := app.Server.Database.RenameFile(fileID, newName)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ 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)
+
+ fileData := types.FileData{
+ ID: newFile.ID.String(),
+ Name: newFile.Name,
+ Size: utils.ConvertFileSize(newFile.Size),
+ IsPrivate: newFile.IsPrivate,
+ Type: newFile.Type,
+ Done: !missingChunk,
+ Downloaded: strconv.FormatUint(newFile.Downloaded, 10),
+ }
+
+ component := fileView.JustFile(fileData)
+ err = component.Render(r.Context(), w)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ fileView.JustFile(fileData)
+ w.WriteHeader(http.StatusOK)
+}
diff --git a/handler/file/upload/upload.go b/handler/file/upload/upload.go
index 9bc35ed..4ec0822 100644
--- a/handler/file/upload/upload.go
+++ b/handler/file/upload/upload.go
@@ -53,7 +53,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
basePath := filepath.Join(currentDir, uploadDir)
cleanBasePath := filepath.Clean(basePath)
- saveFolder := filepath.Join(cleanBasePath, userSession.UserID.String(), file.ID.String(), file.Name)
+ saveFolder := filepath.Join(cleanBasePath, userSession.UserID.String(), file.ID.String())
cleanSaveFolder := filepath.Clean(saveFolder)
diff --git a/handler/file/visibility/visibility.go b/handler/file/visibility/visibility.go
index 343c5ad..6b62183 100644
--- a/handler/file/visibility/visibility.go
+++ b/handler/file/visibility/visibility.go
@@ -32,7 +32,7 @@ func PUT(w http.ResponseWriter, r *http.Request) {
app.Server.Logger.Error(err.Error())
return
}
- saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String(), file.Name)
+ saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String())
pattern := fmt.Sprintf("%s/chunk_*", saveFolder)
chunkFiles, err := filepath.Glob(pattern)
diff --git a/routes/client/routes.go b/routes/client/routes.go
index 9d2ee05..4964c8a 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"
+ renameFileHandler "github.com/fossyy/filekeeper/handler/file/rename"
uploadHandler "github.com/fossyy/filekeeper/handler/file/upload"
visibilityHandler "github.com/fossyy/filekeeper/handler/file/visibility"
forgotPasswordHandler "github.com/fossyy/filekeeper/handler/forgotPassword"
@@ -131,6 +132,10 @@ func SetupRoutes() *http.ServeMux {
middleware.Auth(visibilityHandler.PUT, w, r)
})
+ handler.HandleFunc("PATCH /file/{id}", func(w http.ResponseWriter, r *http.Request) {
+ middleware.Auth(renameFileHandler.PATCH, w, r)
+ })
+
handler.HandleFunc("GET /logout", func(w http.ResponseWriter, r *http.Request) {
middleware.Auth(logoutHandler.GET, w, r)
})
diff --git a/types/types.go b/types/types.go
index 83817fd..8e3661e 100644
--- a/types/types.go
+++ b/types/types.go
@@ -60,6 +60,7 @@ type Database interface {
CreateFile(file *models.File) error
GetFile(fileID string) (*models.File, error)
+ RenameFile(fileID string, name string) (*models.File, error)
DeleteFile(fileID string) error
GetUserFile(name string, ownerID string) (*models.File, error)
GetFiles(ownerID string) ([]*models.File, error)
diff --git a/view/client/file/file.templ b/view/client/file/file.templ
index d90d788..9533f43 100644
--- a/view/client/file/file.templ
+++ b/view/client/file/file.templ
@@ -55,25 +55,53 @@ templ MainContent(files []types.FileData, user types.User, allowance *types.Allo
-
@@ -472,11 +500,9 @@ templ FileIcon(fileType string) {
}
script showDeletionModal(name string, id string) {
- const deleteButton = document.getElementById('deleteButton');
const modal = document.getElementById('deleteModal');
const modalContent = modal.querySelector('div');
const confirmDelete = document.getElementById('confirmDelete');
- const cancelDelete = document.getElementById('cancelDelete');
const fileNameToDelete = document.getElementById('fileNameToDelete');
confirmDelete.setAttribute("hx-delete", "/file/" + id + "?consent=true");
@@ -491,12 +517,8 @@ script showDeletionModal(name string, id string) {
}
script hideDeletionModal() {
- const deleteButton = document.getElementById('deleteButton');
const modal = document.getElementById('deleteModal');
const modalContent = modal.querySelector('div');
- const confirmDelete = document.getElementById('confirmDelete');
- const cancelDelete = document.getElementById('cancelDelete');
- const fileNameToDelete = document.getElementById('fileNameToDelete');
modal.classList.add('opacity-0');
modalContent.classList.add('-translate-y-full', 'scale-95', 'opacity-0');
@@ -505,6 +527,39 @@ script hideDeletionModal() {
}, 300);
}
+script showRenameModal(name string, id string) {
+ const rename = document.getElementById('renameModal');
+ const renameModalContent = rename.querySelector('div');
+ const fileName = document.getElementById("newFileName");
+ const confirmRenameFile = document.getElementById("confirmRenameFile");
+
+ confirmRenameFile.setAttribute("hx-target", "#file-" + id);
+ htmx.process(confirmRenameFile);
+
+ fileName.addEventListener("change", function (event) {
+ event.preventDefault();
+ confirmRenameFile.setAttribute("hx-patch", "/file/" + id + "?name=" + event.target.value);
+ htmx.process(confirmRenameFile);
+ });
+ rename.classList.remove('hidden');
+ setTimeout(() => {
+ rename.classList.remove('opacity-0');
+ renameModalContent.classList.remove('-translate-y-full', 'scale-95', 'opacity-0');
+ }, 50);
+ fileName.value = name
+}
+
+script hideRenameModal() {
+ const rename = document.getElementById('renameModal');
+ const renameModalContent = rename.querySelector('div');
+
+ rename.classList.add('opacity-0');
+ renameModalContent.classList.add('-translate-y-full', 'scale-95', 'opacity-0');
+ setTimeout(() => {
+ rename.classList.add('hidden');
+ }, 300);
+}
+
templ Main(title string, files []types.FileData, user types.User, allowance *types.Allowance) {
@component(title, files, user, allowance)
}
diff --git a/view/client/file/file_templ.go b/view/client/file/file_templ.go
index ddaf093..2aaf2e7 100644
--- a/view/client/file/file_templ.go
+++ b/view/client/file/file_templ.go
@@ -120,7 +120,41 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" id=\"cancelDelete\" class=\"mt-3 px-4 py-2 bg-white text-gray-700 text-base font-medium rounded-md w-full shadow-sm border border-gray-300 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-gray-300 transition duration-300\">Cancel
File Name | File Size | Downloads | Status | Action |
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" id=\"cancelDelete\" class=\"mt-3 px-4 py-2 bg-white text-gray-700 text-base font-medium rounded-md w-full shadow-sm border border-gray-300 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-gray-300 transition duration-300\">Cancel")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hideRenameModal())
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hideRenameModal())
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
File Name | File Size | Downloads | Status | Action |
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -129,12 +163,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var6 string
- templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs("file-" + file.ID)
+ var templ_7745c5c3_Var8 string
+ templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs("file-" + file.ID)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 93, Col: 37}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 121, Col: 37}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -155,12 +189,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var7 string
- templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
+ var templ_7745c5c3_Var9 string
+ templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 98, Col: 134}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 126, Col: 134}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -168,12 +202,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var8 string
- templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
+ var templ_7745c5c3_Var10 string
+ templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 99, Col: 74}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 127, Col: 74}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -194,12 +228,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var9 string
- templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
+ var templ_7745c5c3_Var11 string
+ templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 113, Col: 134}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 141, Col: 134}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -207,12 +241,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var10 string
- templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
+ var templ_7745c5c3_Var12 string
+ templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 114, Col: 74}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 142, Col: 74}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -225,12 +259,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var11 string
- templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(file.Size)
+ var templ_7745c5c3_Var13 string
+ templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(file.Size)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 120, Col: 45}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 148, Col: 45}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -238,12 +272,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var12 string
- templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(file.Downloaded)
+ var templ_7745c5c3_Var14 string
+ templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(file.Downloaded)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 128, Col: 31}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 156, Col: 31}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -274,8 +308,8 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var13 templ.ComponentScript = toggleDropDown()
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13.Call)
+ var templ_7745c5c3_Var15 templ.ComponentScript = toggleDropDown()
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15.Call)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -288,8 +322,8 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var14 templ.SafeURL = templ.SafeURL("/file/" + file.ID)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var14)))
+ var templ_7745c5c3_Var16 templ.SafeURL = templ.SafeURL("/file/" + file.ID)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var16)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -298,37 +332,6 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
return templ_7745c5c3_Err
}
if file.IsPrivate {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- } else {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ } else {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
@@ -365,7 +399,24 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, showRenameModal(file.Name, file.ID))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -377,8 +428,8 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var19 templ.ComponentScript = showDeletionModal(file.Name, file.ID)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19.Call)
+ var templ_7745c5c3_Var22 templ.ComponentScript = showDeletionModal(file.Name, file.ID)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var22.Call)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -391,12 +442,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var20 string
- templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(len(files)))
+ var templ_7745c5c3_Var23 string
+ templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(len(files)))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 244, Col: 120}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 272, Col: 120}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -404,12 +455,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var21 string
- templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(allowance.AllowanceUsedByte)
+ var templ_7745c5c3_Var24 string
+ templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(allowance.AllowanceUsedByte)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 245, Col: 123}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 273, Col: 123}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -417,12 +468,12 @@ func MainContent(files []types.FileData, user types.User, allowance *types.Allow
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var22 string
- templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(allowance.AllowanceByte)
+ var templ_7745c5c3_Var25 string
+ templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(allowance.AllowanceByte)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 246, Col: 123}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/client/file/file.templ`, Line: 274, Col: 123}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -476,21 +527,21 @@ func JustFile(file types.FileData) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var23 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var23 == nil {
- templ_7745c5c3_Var23 = templ.NopComponent
+ templ_7745c5c3_Var26 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var26 == nil {
+ templ_7745c5c3_Var26 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, showRenameModal(file.Name, file.ID))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, showDeletionModal(file.Name, file.ID))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -745,9 +830,9 @@ func FileIcon(fileType string) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var37 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var37 == nil {
- templ_7745c5c3_Var37 = templ.NopComponent
+ templ_7745c5c3_Var42 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var42 == nil {
+ templ_7745c5c3_Var42 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
if fileType == "jpg" || fileType == "jpeg" || fileType == "png" || fileType == "gif" || fileType == "bmp" || fileType == "tiff" {
@@ -787,12 +872,10 @@ func FileIcon(fileType string) templ.Component {
func showDeletionModal(name string, id string) templ.ComponentScript {
return templ.ComponentScript{
- Name: `__templ_showDeletionModal_c813`,
- Function: `function __templ_showDeletionModal_c813(name, id){const deleteButton = document.getElementById('deleteButton');
- const modal = document.getElementById('deleteModal');
+ Name: `__templ_showDeletionModal_42e1`,
+ Function: `function __templ_showDeletionModal_42e1(name, id){const modal = document.getElementById('deleteModal');
const modalContent = modal.querySelector('div');
const confirmDelete = document.getElementById('confirmDelete');
- const cancelDelete = document.getElementById('cancelDelete');
const fileNameToDelete = document.getElementById('fileNameToDelete');
confirmDelete.setAttribute("hx-delete", "/file/" + id + "?consent=true");
@@ -805,20 +888,16 @@ func showDeletionModal(name string, id string) templ.ComponentScript {
}, 50);
fileNameToDelete.textContent = name;
}`,
- Call: templ.SafeScript(`__templ_showDeletionModal_c813`, name, id),
- CallInline: templ.SafeScriptInline(`__templ_showDeletionModal_c813`, name, id),
+ Call: templ.SafeScript(`__templ_showDeletionModal_42e1`, name, id),
+ CallInline: templ.SafeScriptInline(`__templ_showDeletionModal_42e1`, name, id),
}
}
func hideDeletionModal() templ.ComponentScript {
return templ.ComponentScript{
- Name: `__templ_hideDeletionModal_a203`,
- Function: `function __templ_hideDeletionModal_a203(){const deleteButton = document.getElementById('deleteButton');
- const modal = document.getElementById('deleteModal');
+ Name: `__templ_hideDeletionModal_0159`,
+ Function: `function __templ_hideDeletionModal_0159(){const modal = document.getElementById('deleteModal');
const modalContent = modal.querySelector('div');
- const confirmDelete = document.getElementById('confirmDelete');
- const cancelDelete = document.getElementById('cancelDelete');
- const fileNameToDelete = document.getElementById('fileNameToDelete');
modal.classList.add('opacity-0');
modalContent.classList.add('-translate-y-full', 'scale-95', 'opacity-0');
@@ -826,8 +905,53 @@ func hideDeletionModal() templ.ComponentScript {
modal.classList.add('hidden');
}, 300);
}`,
- Call: templ.SafeScript(`__templ_hideDeletionModal_a203`),
- CallInline: templ.SafeScriptInline(`__templ_hideDeletionModal_a203`),
+ Call: templ.SafeScript(`__templ_hideDeletionModal_0159`),
+ CallInline: templ.SafeScriptInline(`__templ_hideDeletionModal_0159`),
+ }
+}
+
+func showRenameModal(name string, id string) templ.ComponentScript {
+ return templ.ComponentScript{
+ Name: `__templ_showRenameModal_e95d`,
+ Function: `function __templ_showRenameModal_e95d(name, id){const rename = document.getElementById('renameModal');
+ const renameModalContent = rename.querySelector('div');
+ const fileName = document.getElementById("newFileName");
+ const confirmRenameFile = document.getElementById("confirmRenameFile");
+
+ confirmRenameFile.setAttribute("hx-target", "#file-" + id);
+ htmx.process(confirmRenameFile);
+
+ fileName.addEventListener("change", function (event) {
+ event.preventDefault();
+ confirmRenameFile.setAttribute("hx-patch", "/file/" + id + "?name=" + event.target.value);
+ htmx.process(confirmRenameFile);
+ });
+ rename.classList.remove('hidden');
+ setTimeout(() => {
+ rename.classList.remove('opacity-0');
+ renameModalContent.classList.remove('-translate-y-full', 'scale-95', 'opacity-0');
+ }, 50);
+ fileName.value = name
+}`,
+ Call: templ.SafeScript(`__templ_showRenameModal_e95d`, name, id),
+ CallInline: templ.SafeScriptInline(`__templ_showRenameModal_e95d`, name, id),
+ }
+}
+
+func hideRenameModal() templ.ComponentScript {
+ return templ.ComponentScript{
+ Name: `__templ_hideRenameModal_e2c4`,
+ Function: `function __templ_hideRenameModal_e2c4(){const rename = document.getElementById('renameModal');
+ const renameModalContent = rename.querySelector('div');
+
+ rename.classList.add('opacity-0');
+ renameModalContent.classList.add('-translate-y-full', 'scale-95', 'opacity-0');
+ setTimeout(() => {
+ rename.classList.add('hidden');
+ }, 300);
+}`,
+ Call: templ.SafeScript(`__templ_hideRenameModal_e2c4`),
+ CallInline: templ.SafeScriptInline(`__templ_hideRenameModal_e2c4`),
}
}
@@ -847,9 +971,9 @@ func Main(title string, files []types.FileData, user types.User, allowance *type
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var38 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var38 == nil {
- templ_7745c5c3_Var38 = templ.NopComponent
+ templ_7745c5c3_Var43 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var43 == nil {
+ templ_7745c5c3_Var43 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = component(title, files, user, allowance).Render(ctx, templ_7745c5c3_Buffer)