mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Wait for extraction to finish before returninrg attachments
This commit is contained in:
parent
f9623089a2
commit
6aac9d1f26
@ -22,6 +22,10 @@ Projects using gocoder:
|
|||||||
- [Blee](https://github.com/Arthi-chaud/Blee)
|
- [Blee](https://github.com/Arthi-chaud/Blee)
|
||||||
- Add your own?
|
- Add your own?
|
||||||
|
|
||||||
|
## How does this work?
|
||||||
|
|
||||||
|
I did a blog post explaining the core idea, you can find it at [zoriya.dev/blogs/transcoder](https://zoriya.dev/blogs/transcoder).
|
||||||
|
|
||||||
## TODO:
|
## TODO:
|
||||||
- Add a swagger
|
- Add a swagger
|
||||||
- Add configurable JWT authorization (v5 of kyoo)
|
- Add configurable JWT authorization (v5 of kyoo)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -213,7 +212,10 @@ func (h *Handler) GetAttachment(c echo.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := fmt.Sprintf("%s/%s/att/%s", src.Settings.Metadata, sha, name)
|
ret, err := h.metadata.GetAttachmentPath(sha, false, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return c.File(ret)
|
return c.File(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +234,10 @@ func (h *Handler) GetSubtitle(c echo.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := fmt.Sprintf("%s/%s/sub/%s", src.Settings.Metadata, sha, name)
|
ret, err := h.metadata.GetAttachmentPath(sha, true, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return c.File(ret)
|
return c.File(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
var extracted = NewCMap[string, <-chan struct{}]()
|
|
||||||
|
|
||||||
const ExtractVersion = 1
|
const ExtractVersion = 1
|
||||||
|
|
||||||
func (s *MetadataService) ExtractSubs(info *MediaInfo) (interface{}, error) {
|
func (s *MetadataService) ExtractSubs(info *MediaInfo) (interface{}, error) {
|
||||||
@ -25,6 +23,18 @@ func (s *MetadataService) ExtractSubs(info *MediaInfo) (interface{}, error) {
|
|||||||
return set(nil, err)
|
return set(nil, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MetadataService) GetAttachmentPath(sha string, is_sub bool, name string) (string, error) {
|
||||||
|
_, err := s.extractLock.WaitFor(sha)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
dir := "att"
|
||||||
|
if is_sub {
|
||||||
|
dir = "sub"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s/%s/%s/%s", Settings.Metadata, sha, dir, name), nil
|
||||||
|
}
|
||||||
|
|
||||||
func extractSubs(info *MediaInfo) error {
|
func extractSubs(info *MediaInfo) error {
|
||||||
defer printExecTime("extraction of %s", info.Path)()
|
defer printExecTime("extraction of %s", info.Path)()
|
||||||
|
|
||||||
|
@ -61,3 +61,21 @@ func (r *RunLock[K, V]) Start(key K) (func() (V, error), func(val V, err error)
|
|||||||
return val, err
|
return val, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RunLock[K, V]) WaitFor(key K) (V, error) {
|
||||||
|
r.lock.Lock()
|
||||||
|
task, ok := r.running[key]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
r.lock.Unlock()
|
||||||
|
var val V
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := make(chan Result[V])
|
||||||
|
task.listeners = append(task.listeners, ret)
|
||||||
|
|
||||||
|
r.lock.Unlock()
|
||||||
|
res := <-ret
|
||||||
|
return res.ok, res.err
|
||||||
|
}
|
||||||
|
@ -27,8 +27,6 @@ type Thumbnail struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
var thumbnails = NewCMap[string, *Thumbnail]()
|
|
||||||
|
|
||||||
const ThumbsVersion = 1
|
const ThumbsVersion = 1
|
||||||
|
|
||||||
func getThumbGlob(sha string) string {
|
func getThumbGlob(sha string) string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user