Select Git revision
server_apps.go
Forked from
flow3r / API
Source project has a limited visibility.
server_apps.go 15.83 KiB
package main
import (
"archive/tar"
"archive/zip"
"bytes"
"compress/gzip"
"context"
"crypto/md5"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"path"
"regexp"
"strings"
"time"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/pelletier/go-toml/v2"
)
type appRegistry struct {
shame []*appShame
apps []*appDescriptor
}
type appShame struct {
repository string
errorMsg string
}
type appDescriptor struct {
repository string
pathInRepo string
appInfo *appInfo
}
type appInfo struct {
name string
menu string
author string
description string
version int
commit string
stars int
flow3rSeed string
commitObj *object.Commit
zip []byte
targz []byte
}
type GLProject struct {
StarCount int `json:"star_count"`
}
var (
reAppPath = regexp.MustCompile(`^apps/([^/]+.toml)$`)
reAppRepo = regexp.MustCompile(`^([a-zA-Z\-_\.0-9]+)/([a-zA-Z\-_0-9]+)$`)
)
func (s *server) getStars(ctx context.Context, repo string) (int, error) {
path := fmt.Sprintf("https://%s/api/v4/projects/%s", flagGitlabHost, url.PathEscape(repo))