-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package controllers | ||
|
||
import ( | ||
"ch/kirari04/videocms/helpers" | ||
"ch/kirari04/videocms/inits" | ||
"ch/kirari04/videocms/models" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func DeleteUploadSession(c *fiber.Ctx) error { | ||
// parse & validate request | ||
var validation models.DeleteUploadSessionValidation | ||
if err := c.BodyParser(&validation); err != nil { | ||
return c.Status(fiber.StatusBadRequest).SendString("Invalid body request format") | ||
} | ||
|
||
if errors := helpers.ValidateStruct(validation); len(errors) > 0 { | ||
return c.Status(fiber.StatusBadRequest).SendString(fmt.Sprintf("%s [%s] : %s", errors[0].FailedField, errors[0].Tag, errors[0].Value)) | ||
} | ||
|
||
userId, ok := c.Locals("UserID").(uint) | ||
if !ok { | ||
log.Println("GetUploadSessions: Failed to catch userId") | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
|
||
var uploadSession models.UploadSession | ||
if res := inits.DB.Where(&models.UploadSession{ | ||
UUID: validation.UploadSessionUUID, | ||
}, "UUID").First(&uploadSession); res.Error != nil { | ||
return c.Status(fiber.StatusBadRequest).SendString("Upload Session not found") | ||
} | ||
|
||
if uploadSession.UserID != userId { | ||
return c.Status(fiber.StatusBadRequest).SendString("Upload Session not found") | ||
} | ||
|
||
if res := inits.DB. | ||
Model(&models.UploadChunck{}). | ||
Where(&models.UploadChunck{ | ||
UploadSessionID: uploadSession.ID, | ||
}). | ||
Delete(&models.UploadChunck{}); res.Error != nil { | ||
log.Printf("[WARNING] createUploadFileCleanup -> remove upload chuncks from database (%d): %v\n", uploadSession.ID, res.Error) | ||
} | ||
if res := inits.DB. | ||
Delete(&models.UploadSession{}, uploadSession.ID); res.Error != nil { | ||
log.Printf("[WARNING] createUploadFileCleanup -> remove upload session from database (%d): %v\n", uploadSession.ID, res.Error) | ||
} | ||
|
||
if err := os.RemoveAll(uploadSession.SessionFolder); err != nil { | ||
log.Printf("[WARNING] createUploadFileCleanup -> remove session folder: %v\n", err) | ||
} | ||
|
||
return c.Status(fiber.StatusOK).SendString("ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package controllers | ||
|
||
import ( | ||
"ch/kirari04/videocms/inits" | ||
"ch/kirari04/videocms/models" | ||
"log" | ||
"time" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type GetUploadSessionsRes struct { | ||
CreatedAt *time.Time | ||
Name string | ||
UUID string | ||
Size int64 | ||
ChunckCount int | ||
} | ||
|
||
func GetUploadSessions(c *fiber.Ctx) error { | ||
userId, ok := c.Locals("UserID").(uint) | ||
if !ok { | ||
log.Println("GetUploadSessions: Failed to catch userId") | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
|
||
var sessions []GetUploadSessionsRes | ||
if res := inits.DB. | ||
Model(&models.UploadSession{}). | ||
Where(&models.UploadSession{ | ||
UserID: userId, | ||
}, "UserID"). | ||
Find(&sessions); res.Error != nil { | ||
log.Println("Failed to list upload sessions", res.Error) | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
|
||
return c.Status(fiber.StatusOK).JSON(&sessions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters