Add video/audio delete button
This commit is contained in:
60
handlers.go
60
handlers.go
@@ -661,6 +661,7 @@ func videosHandler(c echo.Context) error {
|
||||
}
|
||||
|
||||
type VideoTemplate struct {
|
||||
ID uint // Video.ID
|
||||
Source string
|
||||
Width uint
|
||||
Height uint
|
||||
@@ -673,6 +674,8 @@ type VideoTemplate struct {
|
||||
}
|
||||
|
||||
type AudioTemplate struct {
|
||||
ID uint // Audio.ID
|
||||
Source string
|
||||
Kbps string
|
||||
Size string
|
||||
Filename string
|
||||
@@ -747,6 +750,7 @@ func videoHandler(c echo.Context) error {
|
||||
rate := float64(video.Size) / video.Length
|
||||
|
||||
videoURLs = append(videoURLs, VideoTemplate{
|
||||
ID: video.ID,
|
||||
Source: video.Source,
|
||||
Width: video.Width,
|
||||
Height: video.Height,
|
||||
@@ -768,6 +772,8 @@ func videoHandler(c echo.Context) error {
|
||||
rate := float64(audio.Size) / audio.Length
|
||||
|
||||
audioURLs = append(audioURLs, AudioTemplate{
|
||||
ID: audio.ID,
|
||||
Source: audio.Source,
|
||||
Kbps: fmt.Sprintf("%.1f kbps", kbps),
|
||||
Size: humanSize(audio.Size),
|
||||
Filename: audio.Filename,
|
||||
@@ -867,6 +873,60 @@ func deleteOriginalHandler(c echo.Context) error {
|
||||
return c.Redirect(http.StatusSeeOther, "/videos")
|
||||
}
|
||||
|
||||
func deleteVideoHandler(c echo.Context) error {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
referrer := c.Request().Referer()
|
||||
if referrer == "" {
|
||||
referrer = "/"
|
||||
}
|
||||
|
||||
var video Video
|
||||
result := db.First(&video, id)
|
||||
if result.Error != nil {
|
||||
log.Errorln("error retrieving video", id, result.Error)
|
||||
return c.Redirect(http.StatusSeeOther, referrer)
|
||||
}
|
||||
|
||||
videoPath := filepath.Join(getDataDir(), video.Filename)
|
||||
log.Debugln("remove", videoPath)
|
||||
err := os.Remove(videoPath)
|
||||
if err != nil {
|
||||
log.Errorln("coudn't remove", videoPath, err)
|
||||
}
|
||||
|
||||
if err := db.Delete(&Video{}, id).Error; err != nil {
|
||||
log.Errorln("error deleting video record", id, err)
|
||||
}
|
||||
return c.Redirect(http.StatusSeeOther, referrer)
|
||||
}
|
||||
|
||||
func deleteAudioHandler(c echo.Context) error {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
referrer := c.Request().Referer()
|
||||
if referrer == "" {
|
||||
referrer = "/"
|
||||
}
|
||||
|
||||
var audio Audio
|
||||
result := db.First(&audio, id)
|
||||
if result.Error != nil {
|
||||
log.Errorln("error retrieving audio", id, result.Error)
|
||||
return c.Redirect(http.StatusSeeOther, referrer)
|
||||
}
|
||||
|
||||
filePath := filepath.Join(getDataDir(), audio.Filename)
|
||||
log.Debugln("remove", filePath)
|
||||
err := os.Remove(filePath)
|
||||
if err != nil {
|
||||
log.Errorln("coudn't remove", filePath, err)
|
||||
}
|
||||
|
||||
if err := db.Delete(&Audio{}, id).Error; err != nil {
|
||||
log.Errorln("error deleting audio record", id, err)
|
||||
}
|
||||
return c.Redirect(http.StatusSeeOther, referrer)
|
||||
}
|
||||
|
||||
func tempHandler(c echo.Context) error {
|
||||
token := c.Param("token")
|
||||
|
||||
|
2
main.go
2
main.go
@@ -123,6 +123,8 @@ func main() {
|
||||
e.POST("/video/:id/delete", deleteOriginalHandler, authMiddleware)
|
||||
e.GET("/temp/:token", tempHandler)
|
||||
e.POST("/video/:id/process", processHandler, authMiddleware)
|
||||
e.POST("/delete_video/:id", deleteVideoHandler, authMiddleware)
|
||||
e.POST("/delete_audio/:id", deleteAudioHandler, authMiddleware)
|
||||
|
||||
dataGroup := e.Group("/data")
|
||||
dataGroup.Use(authMiddleware)
|
||||
|
@@ -1,3 +1,8 @@
|
||||
button {
|
||||
all: unset;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
@@ -46,6 +51,20 @@
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.media-controls {
|
||||
text-align: center;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
.media-controls button {
|
||||
display: inline-block;
|
||||
padding: 10px 15px;
|
||||
background-color: red;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* narrower than 600px */
|
||||
@media (max-width: 600px) {
|
||||
.media-grid {
|
||||
|
@@ -27,6 +27,13 @@
|
||||
<div class="media-download">
|
||||
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
|
||||
</div>
|
||||
{{if ne .Source "original"}}
|
||||
<div class="media-controls">
|
||||
<form action="/delete_video/{{.ID}}" method="post">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
@@ -43,6 +50,13 @@
|
||||
<div class="media-download">
|
||||
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
|
||||
</div>
|
||||
{{if ne .Source "original"}}
|
||||
<div class="media-controls">
|
||||
<form action="/delete_audio/{{.ID}}" method="post">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user