Skip to content

Commit

Permalink
Feature/queries (#7)
Browse files Browse the repository at this point in the history
massively simplify api and implement several features
  • Loading branch information
littlebenlittle authored Jul 13, 2024
1 parent afda889 commit 845de50
Show file tree
Hide file tree
Showing 18 changed files with 795 additions and 1,000 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"rust-analyzer.rustfmt.overrideCommand": ["leptosfmt", "--stdin", "--rustfmt"],
// "rust-analyzer.cargo.features": ["demo"]
//"rust-analyzer.cargo.features": ["demo"],
"rust-analyzer.server.extraEnv": {"RUSTFLAGS": "--cfg=web_sys_unstable_apis"}
}
9 changes: 5 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

### UI

- [ ] Better reactive design
- [x] Better reactive design
- [x] Select should preserve scroll
- [ ] Query and view instead of total sync
- [ ] Filter media in selector by query
- [x] Filter media in selector by query
- [x] Media detial on hover

### API

Expand All @@ -23,7 +23,8 @@

## Maintenance

- [ ] Split resumable uploads into a separate crate
- [x] Split resumable uploads into a separate crate
- [ ] API should return schema-appropriate media URLs

## Greenfield

Expand Down
25 changes: 10 additions & 15 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ func main() {
router.PUT("/media/:id", find_id(), find_media(m), func(c *gin.Context) {
id := c.MustGet("id").(ID)
media := c.MustGet("media").(Media)
var update map[string]string
if err := c.BindJSON(&update); err != nil {
c.String(http.StatusBadRequest, "%s", err)
return
}
if err := media.Merge(update); err != nil {
c.String(http.StatusBadRequest, "%s", err)
return
field := c.Query("f")
value := c.Query("v")
switch field {
case "title":
media.Title = value
case "format":
media.Format = value
default:
c.String(http.StatusBadRequest, "invalid value for query param `f`")
}
m.Media.Assign(id, media)
})
Expand Down Expand Up @@ -191,11 +192,6 @@ func find_media(m *Manager) func(c *gin.Context) {
return func(c *gin.Context) {
id, _ := c.Get("id")
media, ok := m.Media.Get(id.(ID))
// if err != nil {
// log.Printf("error finding media: %s", err)
// c.AbortWithStatus(http.StatusInternalServerError)
// return
// }
if !ok {
log.Printf("media not found: %s", id)
c.AbortWithStatus(http.StatusNotFound)
Expand Down Expand Up @@ -251,7 +247,7 @@ func to_client_media(dir string, origin string, media Media) gin.H {
"title": media.Title,
"format": media.Format,
"shortname": media.Shortname,
"url": origin + "/media/" + path,
"url": origin + "/downloads/" + path,
}
}

Expand All @@ -274,6 +270,5 @@ func origin(c *gin.Context) {
if scheme == "" {
scheme = "http"
}
log.Printf("\n%s%s\n", scheme, host)
c.Set("origin", scheme+"://"+host)
}
8 changes: 7 additions & 1 deletion api/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ func (c *Collection[T]) List() (items map[ID]T, err error) {
}

func (c *Collection[T]) Get(id ID) (val T, ok bool) {
if v, ok := c.kv.Get(c.prefix + id.repr); ok {
items, _ := c.kv.List()
for i := range items {
log.Printf("%s", i)
}
var v string
v, ok = c.kv.Get(c.prefix + id.repr)
if ok {
if err := json.Unmarshal([]byte(v), &val); err != nil {
log.Printf("failed to unmarshal `%s`: %s", id.repr, err)
}
Expand Down
33 changes: 17 additions & 16 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ services:
working_dir: /ui
environment:
- CARGO_TARGET_DIR=/target
- RUSTFLAGS=--cfg=web_sys_unstable_apis
volumes:
- ./ui:/ui:rw
- rust-cache:/target:rw
transmission:
image: lscr.io/linuxserver/transmission:latest
volumes:
- data:/downloads/complete:rw
- incomplete:/downloads/incomplete:rw
- config:/config:rw
# transmission:
# image: lscr.io/linuxserver/transmission:latest
# volumes:
# - data:/downloads/complete:rw
# - incomplete:/downloads/incomplete:rw
# - config:/config:rw
api:
build:
context: ./api
Expand All @@ -26,14 +27,14 @@ services:
- ./api:/api:rw
- gopath:/go:rw
- gocache:/root/.cache/go:rw
tusd:
image: docker.io/tusproject/tusd:v1.9
command: -behind-proxy -upload-dir=/data -hooks-dir=/hooks
user: "0"
volumes:
- data:/complete:rw
- tusd-data:/data:rw
- ./tusd:/hooks:ro
# tusd:
# image: docker.io/tusproject/tusd:v1.9
# command: -behind-proxy -upload-dir=/data -hooks-dir=/hooks
# user: "0"
# volumes:
# - data:/complete:rw
# - tusd-data:/data:rw
# - ./tusd:/hooks:ro
nginx:
image: docker.io/library/nginx:latest
ports:
Expand All @@ -44,8 +45,8 @@ services:
- ./ui/dist:/www/data:ro
depends_on:
- api
- tusd
- transmission
# - tusd
# - transmission

volumes:
gopath:
Expand Down
32 changes: 16 additions & 16 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ http {
try_files /index.html =404;
}

location /files {
proxy_pass http://tusd:1080;
# location /files {
# proxy_pass http://tusd:1080;

proxy_request_buffering off;
proxy_buffering off;
proxy_http_version 1.1;
# proxy_request_buffering off;
# proxy_buffering off;
# proxy_http_version 1.1;

proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $http_scheme;
# proxy_set_header X-Forwarded-Host $http_host;
# proxy_set_header X-Forwarded-Proto $http_scheme;

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 0;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# client_max_body_size 0;

proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Origin * always;
}
# proxy_hide_header Access-Control-Allow-Origin;
# add_header Access-Control-Allow-Origin * always;
# }

location /media/ {
location /downloads/ {
sendfile on;
alias /www/media/;
try_files $uri =404;
Expand All @@ -60,8 +60,8 @@ http {
# http_host can be a security issue for some apps, but in this
# case all you could do is make your own browser use the wrong
# URL
proxy_set_header Host $http;
proxy_set_header Scheme $scheme;
proxy_set_header Host $http_host;
proxy_set_header Scheme $http_scheme;
proxy_pass http://api:8080/;
}

Expand Down
Loading

0 comments on commit 845de50

Please sign in to comment.