Skip to content

Commit

Permalink
!feat: changed release from tags to commits
Browse files Browse the repository at this point in the history
feat: simplified updates, and custom sha versions
chore: updated `README.md`
  • Loading branch information
mysterion committed Sep 3, 2024
1 parent b3518a3 commit 4191a4c
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 102 deletions.
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@ single executable program for aframe-vr-player with update feature

# usage
```
Usage of avrp:
-dev
starts in dev mode, serves 'index.html' from current directory
-dir string
path to video files
-reset
removes all configs, thumbnails & 'aframe-vr-player' files
-sha string
Optional - download a specific commit of aframe-vr-player (default "latest")
-update
checks & downloads the latest version of 'aframe-vr-player'
checks & downloads the latest version(commit) of 'aframe-vr-player'
```

### Examples
```sh
# -flag
# --flag
# -flag=x

# deletes all configs of avrp and aframe-vr-player / factory reset
avrp --reset

# serve video directory
avrp --dir "C:\\Users\\User\\Video\\SFW\\"
# linux path
avrp --dir "/home/user/Videos/NSFW"

# downloads the latest version(commit) of aframe-vr-player
avrp --update

# downloads https://github.com/mysterion/aframe-vr-player/tree/6d1b7cfacfd873180e80fde53cb2a7873e1faffc
# https://github.com/mysterion/aframe-vr-player/commits/main/
avrp --update --sha 6d1b7cfacfd873180e80fde53cb2a7873e1faffc

-dev
starts in dev mode, serves 'index.html' from current directory

-reset
removes all configs, thumbnails & 'aframe-vr-player' files
```
# installation
## go cli
Expand Down
8 changes: 5 additions & 3 deletions avrp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ func main() {
log.SetFlags(log.Lshortfile | log.LstdFlags)

var servDir string
var sha string
var update bool
var reset bool

flag.BoolVar(&utils.DEV, "dev", false, "starts in dev mode, serves 'index.html' from current directory")
flag.BoolVar(&update, "update", false, "checks & downloads the latest version of 'aframe-vr-player'")
flag.BoolVar(&update, "update", false, "checks & downloads the latest version(commit) of 'aframe-vr-player'")
flag.StringVar(&sha, "sha", "latest", "Optional - download a specific commit of aframe-vr-player")
flag.StringVar(&servDir, "dir", "", "path to video files")
flag.BoolVar(&reset, "reset", false, "removes all configs, thumbnails & 'aframe-vr-player' files")

Expand All @@ -69,15 +71,15 @@ func main() {
}

if update {
dist.Update()
dist.Update(sha)
}

/// do i need this anymore?
utils.GoRunGatekeeper()

// running for the first time
if !dist.Valid() && !utils.DEV {
dist.Update()
dist.Update("latest")
}

if len(servDir) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions internal/thumbnails/thumbnails.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package thumbnails

import (
"errors"
"fmt"
"log"
"math"
Expand All @@ -18,6 +19,8 @@ import (

var thumbdir string

var ErrNotVideo = errors.New("not a video")

var Available = true

var muGen sync.Mutex
Expand All @@ -38,6 +41,9 @@ func Init() {
}

func GetDuration(file string) (float64, error) {
if !utils.IsVideo(file) {
return 0, ErrNotVideo
}
var secs string
secs = cache.Get("DUR_" + file)
if secs == "" {
Expand Down
26 changes: 23 additions & 3 deletions internal/utils/video.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package utils

import "strings"
import (
"strings"
)

var exts = []string{
var video = []string{
"3g2",
"3gp",
"aaf",
Expand Down Expand Up @@ -37,12 +39,30 @@ var exts = []string{
"webm",
"wmv",
"yuv",
}

var subs = []string{
"srt",
}

func CanServe(file string) bool {
f := strings.ToLower(file)
for _, e := range video {
if strings.HasSuffix(f, e) {
return true
}
}
for _, e := range subs {
if strings.HasSuffix(f, e) {
return true
}
}
return false
}

func IsVideo(file string) bool {
f := strings.ToLower(file)
for _, e := range exts {
for _, e := range video {
if strings.HasSuffix(f, e) {
return true
}
Expand Down
3 changes: 2 additions & 1 deletion web/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func listFilesAndFolders(dirPath string) ([]File, []string, error) {
if entry.IsDir() {
folders = append(folders, entry.Name())
} else {
if !utils.IsVideo(entry.Name()) {
if !utils.CanServe(entry.Name()) {
continue
}

secs, _ := thumbnails.GetDuration(path.Join(dirPath, entry.Name()))

files = append(files, File{Name: entry.Name(), Duration: int(secs)})
Expand Down
32 changes: 6 additions & 26 deletions web/dist/dist.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package dist

import (
"errors"
"io/fs"
"log"
"math"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/mysterion/avrp/internal/utils"
)

const RepoOwner = "mysterion"
const RepoName = "aframe-vr-player"

var VersionFile string

func Init() {
Expand All @@ -32,26 +24,14 @@ func Delete() error {
return os.RemoveAll(utils.DistDir)
}

// returns 0 , when no dist
func Ver() int {
fd, err := os.Open(VersionFile)
if errors.Is(err, fs.ErrNotExist) {
log.Println("ERR: Version file doesn't exist")
return 0
}
defer fd.Close()

d := make([]byte, 1024)
n, err := fd.Read(d)
if err != nil {
return math.MaxInt
}
// returns sha of aframe-vr-player dist
func Ver() string {
d, err := os.ReadFile(VersionFile)

vs := strings.ReplaceAll(string(d[:n]), ".", "")
v, err := strconv.Atoi(vs)
if err != nil {
return math.MaxInt
log.Printf("WARN: while reading dist version, %v\n", err.Error())
return ""
}

return v
return string(d)
}
17 changes: 9 additions & 8 deletions web/dist/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ import (
"github.com/mysterion/avrp/internal/utils"
)

func DownloadTag(t Tag) error {
func DownloadCommit(sha string) error {

log.Printf("Latest Release - %v - %v\n", t.Name, t.ZipballUrl)
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/zipball/%s", RepoOwner, RepoName, sha)
log.Printf("Downloading - %v\n", url)

zipFile, err := os.CreateTemp("", "avrp-latest")
zipFile, err := os.CreateTemp("", "aframe-vr-player")
if err != nil {
return err
}
defer zipFile.Close()

log.Println("Downloading to - ", zipFile.Name())

resp, err := http.Get(t.ZipballUrl)
resp, err := http.Get(url)
if err != nil {
return err
}
Expand All @@ -36,13 +37,13 @@ func DownloadTag(t Tag) error {
return err
}

err = extractZip(t, zipFile.Name())
err = extractZip(sha, zipFile.Name())
if err != nil {
log.Println("ERR: Failed to extract the zip")
return err
}

err = os.WriteFile(VersionFile, []byte(t.Name), 0644)
err = os.WriteFile(VersionFile, []byte(sha), 0644)

if err != nil {
log.Println("ERR: Failed to write version file")
Expand All @@ -56,7 +57,7 @@ func DownloadTag(t Tag) error {
return nil
}

func extractZip(t Tag, srcZip string) error {
func extractZip(sha string, srcZip string) error {

log.Printf("Extracting %v", srcZip)
r, err := zip.OpenReader(srcZip)
Expand All @@ -70,7 +71,7 @@ func extractZip(t Tag, srcZip string) error {
return err
}

folderName := fmt.Sprintf("%s-%s-%s", RepoOwner, RepoName, t.Commit.Sha[:7])
folderName := fmt.Sprintf("%s-%s-%s", RepoOwner, RepoName, sha[:7])

for _, f := range r.File {
fi := f.FileInfo()
Expand Down
Loading

0 comments on commit 4191a4c

Please sign in to comment.