mirror of
https://github.com/alfg/ffmpegd.git
synced 2025-09-26 19:41:15 +08:00
feat: add cors support for localhost and alfg.github.io.
docker: add dockerfile, docker-compose example and update goreleaser with docker support.
This commit is contained in:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
*.mp4
|
||||
*.tmp
|
||||
*.exe
|
@@ -18,4 +18,7 @@ archives:
|
||||
format: zip
|
||||
files:
|
||||
- README.md
|
||||
- LICENSE
|
||||
- LICENSE
|
||||
dockers:
|
||||
- image_templates:
|
||||
- alfg/ffmpegd
|
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
###############################
|
||||
# Build the ffmpegd-build image.
|
||||
FROM golang:1.16-alpine as build
|
||||
|
||||
WORKDIR /go/src/ffmpegd
|
||||
COPY . .
|
||||
|
||||
RUN go get -d -v ./...
|
||||
RUN go install -v ./...
|
||||
|
||||
##########################
|
||||
# Build the release image.
|
||||
FROM alfg/ffmpeg:latest
|
||||
LABEL MAINTAINER Alfred Gutierrez <alf.g.jr@gmail.com>
|
||||
|
||||
WORKDIR /home
|
||||
ENV PATH=/opt/bin:$PATH
|
||||
|
||||
COPY --from=build /go/bin/ffmpegd /opt/bin/ffmpegd
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["ffmpegd"]
|
17
README.md
17
README.md
@@ -16,11 +16,24 @@ See [Usage](#Usage) for more details.
|
||||
```
|
||||
|
||||
## Install
|
||||
### Go
|
||||
```
|
||||
$ go get -u github.com/alfg/ffmpegd
|
||||
```
|
||||
|
||||
Docker, Homebrew, and release binaries coming soon.
|
||||
### Docker
|
||||
A Docker image is available with [alfg/ffmpeg](https://github.com/alfg/docker-ffmpeg) installed:
|
||||
|
||||
```
|
||||
$ docker run -it -p 8080:8080 -v /tmp/:/home ffmpegd
|
||||
```
|
||||
|
||||
Or using the `docker-compose` example:
|
||||
```
|
||||
$ docker-compose up ffmpegd
|
||||
```
|
||||
|
||||
Homebrew package coming soon.
|
||||
|
||||
## Usage
|
||||
* [ffmpeg](https://www.ffmpeg.org/download.html) must be installed and available on your `$PATH`.
|
||||
@@ -70,10 +83,8 @@ TBD
|
||||
* Logging levels and output
|
||||
* More error handling
|
||||
* API documentation
|
||||
* Docker
|
||||
* Test Client Demo
|
||||
* Tests
|
||||
* Cross-compile binaries for releases
|
||||
|
||||
## License
|
||||
MIT
|
||||
|
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
ffmpegd:
|
||||
build: .
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./:/home
|
31
main.go
31
main.go
@@ -22,9 +22,9 @@ const (
|
||||
██╔══╝ ██╔══╝ ██║╚██╔╝██║██╔═══╝ ██╔══╝ ██║ ██║██║ ██║
|
||||
██║ ██║ ██║ ╚═╝ ██║██║ ███████╗╚██████╔╝██████╔╝
|
||||
╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚══════╝ ╚═════╝ ╚═════╝
|
||||
v0.0.3
|
||||
v0.0.4
|
||||
`
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
description = "[\u001b[32mffmpegd\u001b[0m] - websocket server for \u001b[33mffmpeg-commander\u001b[0m.\n"
|
||||
usage = `
|
||||
Usage:
|
||||
@@ -35,11 +35,21 @@ Usage:
|
||||
)
|
||||
|
||||
var (
|
||||
allowedOrigins = []string{
|
||||
"http://localhost:8080",
|
||||
"http://localhost:8081",
|
||||
"https://alfg.github.io",
|
||||
}
|
||||
clients = make(map[*websocket.Conn]bool)
|
||||
broadcast = make(chan Message)
|
||||
upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
for _, origin := range allowedOrigins {
|
||||
if r.Header.Get("Origin") == origin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
}
|
||||
progressCh chan struct{}
|
||||
@@ -107,7 +117,7 @@ func startServer() {
|
||||
fmt.Println(" - \u001b[33mffmpegd\u001b[0m must be enabled in ffmpeg-commander options.")
|
||||
fmt.Println("")
|
||||
fmt.Printf("Waiting for connection...")
|
||||
err := http.ListenAndServe("127.0.0.1:8080", nil)
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
fmt.Println("ListenAndServe: ", err)
|
||||
}
|
||||
@@ -116,7 +126,8 @@ func startServer() {
|
||||
func handleConnections(w http.ResponseWriter, r *http.Request) {
|
||||
ws, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Printf("\rWaiting for connection...\u001b[31m websocket connection failed!\u001b[0m")
|
||||
return
|
||||
}
|
||||
defer ws.Close()
|
||||
|
||||
@@ -173,10 +184,18 @@ func handleFiles(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
cors(&w, r)
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
|
||||
func cors(w *http.ResponseWriter, r *http.Request) {
|
||||
for _, origin := range allowedOrigins {
|
||||
if r.Header.Get("Origin") == origin {
|
||||
(*w).Header().Set("Access-Control-Allow-Origin", origin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleMessages() {
|
||||
for {
|
||||
msg := <-broadcast
|
||||
|
Reference in New Issue
Block a user