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 {
|
type VideoTemplate struct {
|
||||||
|
ID uint // Video.ID
|
||||||
Source string
|
Source string
|
||||||
Width uint
|
Width uint
|
||||||
Height uint
|
Height uint
|
||||||
@@ -673,6 +674,8 @@ type VideoTemplate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AudioTemplate struct {
|
type AudioTemplate struct {
|
||||||
|
ID uint // Audio.ID
|
||||||
|
Source string
|
||||||
Kbps string
|
Kbps string
|
||||||
Size string
|
Size string
|
||||||
Filename string
|
Filename string
|
||||||
@@ -747,6 +750,7 @@ func videoHandler(c echo.Context) error {
|
|||||||
rate := float64(video.Size) / video.Length
|
rate := float64(video.Size) / video.Length
|
||||||
|
|
||||||
videoURLs = append(videoURLs, VideoTemplate{
|
videoURLs = append(videoURLs, VideoTemplate{
|
||||||
|
ID: video.ID,
|
||||||
Source: video.Source,
|
Source: video.Source,
|
||||||
Width: video.Width,
|
Width: video.Width,
|
||||||
Height: video.Height,
|
Height: video.Height,
|
||||||
@@ -768,6 +772,8 @@ func videoHandler(c echo.Context) error {
|
|||||||
rate := float64(audio.Size) / audio.Length
|
rate := float64(audio.Size) / audio.Length
|
||||||
|
|
||||||
audioURLs = append(audioURLs, AudioTemplate{
|
audioURLs = append(audioURLs, AudioTemplate{
|
||||||
|
ID: audio.ID,
|
||||||
|
Source: audio.Source,
|
||||||
Kbps: fmt.Sprintf("%.1f kbps", kbps),
|
Kbps: fmt.Sprintf("%.1f kbps", kbps),
|
||||||
Size: humanSize(audio.Size),
|
Size: humanSize(audio.Size),
|
||||||
Filename: audio.Filename,
|
Filename: audio.Filename,
|
||||||
@@ -867,6 +873,60 @@ func deleteOriginalHandler(c echo.Context) error {
|
|||||||
return c.Redirect(http.StatusSeeOther, "/videos")
|
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 {
|
func tempHandler(c echo.Context) error {
|
||||||
token := c.Param("token")
|
token := c.Param("token")
|
||||||
|
|
||||||
|
2
main.go
2
main.go
@@ -123,6 +123,8 @@ func main() {
|
|||||||
e.POST("/video/:id/delete", deleteOriginalHandler, authMiddleware)
|
e.POST("/video/:id/delete", deleteOriginalHandler, authMiddleware)
|
||||||
e.GET("/temp/:token", tempHandler)
|
e.GET("/temp/:token", tempHandler)
|
||||||
e.POST("/video/:id/process", processHandler, authMiddleware)
|
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 := e.Group("/data")
|
||||||
dataGroup.Use(authMiddleware)
|
dataGroup.Use(authMiddleware)
|
||||||
|
@@ -1,3 +1,8 @@
|
|||||||
|
button {
|
||||||
|
all: unset;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.media-grid {
|
.media-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||||
@@ -46,6 +51,20 @@
|
|||||||
border-radius: 4px;
|
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 */
|
/* narrower than 600px */
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
.media-grid {
|
.media-grid {
|
||||||
|
@@ -27,6 +27,13 @@
|
|||||||
<div class="media-download">
|
<div class="media-download">
|
||||||
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
|
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
@@ -43,6 +50,13 @@
|
|||||||
<div class="media-download">
|
<div class="media-download">
|
||||||
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
|
<a href="/data/{{.Filename}}" download="{{.DownloadFilename}}">Download ({{.Size}}, {{.StreamRate}})</a>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user