mirror of
https://github.com/thomiceli/opengist
synced 2024-11-12 07:05:50 +01:00
Update preview and file count when git push with http/ssh
This commit is contained in:
parent
b505f7147e
commit
8998e46fea
@ -4,6 +4,7 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"opengist/internal/git"
|
"opengist/internal/git"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -260,6 +261,36 @@ func (gist *Gist) RPC(service string) ([]byte, error) {
|
|||||||
return git.RPC(gist.User.Username, gist.Uuid, service)
|
return git.RPC(gist.User.Username, gist.Uuid, service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gist *Gist) UpdatePreviewAndCount() error {
|
||||||
|
filesStr, err := git.GetFilesOfRepository(gist.User.Username, gist.Uuid, "HEAD")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
gist.NbFiles = len(filesStr)
|
||||||
|
|
||||||
|
if len(filesStr) == 0 {
|
||||||
|
gist.Preview = ""
|
||||||
|
gist.PreviewFilename = ""
|
||||||
|
} else {
|
||||||
|
file, err := gist.File("HEAD", filesStr[0], true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
split := strings.Split(file.Content, "\n")
|
||||||
|
if len(split) > 10 {
|
||||||
|
gist.Preview = strings.Join(split[:10], "\n")
|
||||||
|
} else {
|
||||||
|
gist.Preview = file.Content
|
||||||
|
}
|
||||||
|
|
||||||
|
gist.Preview = file.Content
|
||||||
|
gist.PreviewFilename = file.Filename
|
||||||
|
}
|
||||||
|
|
||||||
|
return gist.Update()
|
||||||
|
}
|
||||||
|
|
||||||
// -- DTO -- //
|
// -- DTO -- //
|
||||||
|
|
||||||
type GistDTO struct {
|
type GistDTO struct {
|
||||||
|
@ -83,6 +83,7 @@ func runGitCommand(ch ssh.Channel, gitCmd string, keyID uint) error {
|
|||||||
// updatedAt is updated only if serviceType is receive-pack
|
// updatedAt is updated only if serviceType is receive-pack
|
||||||
if verb == "receive-pack" {
|
if verb == "receive-pack" {
|
||||||
_ = gist.SetLastActiveNow()
|
_ = gist.SetLastActiveNow()
|
||||||
|
_ = gist.UpdatePreviewAndCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -134,7 +134,9 @@ func pack(ctx echo.Context, serviceType string) error {
|
|||||||
|
|
||||||
// updatedAt is updated only if serviceType is receive-pack
|
// updatedAt is updated only if serviceType is receive-pack
|
||||||
if serviceType == "receive-pack" {
|
if serviceType == "receive-pack" {
|
||||||
_ = getData(ctx, "gist").(*models.Gist).SetLastActiveNow()
|
gist := getData(ctx, "gist").(*models.Gist)
|
||||||
|
_ = gist.SetLastActiveNow()
|
||||||
|
_ = gist.UpdatePreviewAndCount()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user