├── .github └── workflows │ └── workflow.yml ├── .goreleaser.yml ├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml ├── entrypoint.sh ├── go.mod ├── go.sum ├── server ├── assets │ ├── css │ │ ├── codemirror.css │ │ ├── default.css │ │ └── diffview.css │ ├── diff.html │ ├── gallery.html │ ├── img │ │ └── fullscreen.svg │ ├── js │ │ ├── codemirror.js │ │ ├── difflib.js │ │ ├── diffview.js │ │ ├── glsl.js │ │ ├── helpers.js │ │ ├── jquery.js │ │ └── lzma.js │ └── login.html ├── auth.go ├── cmd │ ├── glsladmin │ │ └── main.go │ └── glslsandbox │ │ └── main.go ├── server.go ├── store │ ├── data_test.go │ ├── effects.go │ ├── effects_test.go │ ├── import.go │ ├── store.go │ ├── users.go │ └── users_test.go └── thumb │ ├── thumb.go │ └── thumb_test.go └── static ├── css ├── codemirror.css └── default.css ├── img └── fullscreen.svg ├── index.html ├── index_.html └── js ├── LICENSE-LZMA ├── codemirror.js ├── glsl.js ├── helpers.js ├── jquery.js ├── lzma.js └── lzma_worker.js /.github/workflows/workflow.yml: -------------------------------------------------------------------------------- 1 | name: glslsandbox 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | release: 11 | types: 12 | - created 13 | 14 | env: 15 | REGISTRY: ghcr.io 16 | IMAGE_NAME: ${{ github.repository }} 17 | 18 | permissions: 19 | contents: write 20 | 21 | jobs: 22 | test: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Install Go 26 | uses: actions/setup-go@v1 27 | with: 28 | go-version: 1.21.x 29 | 30 | - name: Checkout code 31 | uses: actions/checkout@v2 32 | 33 | - name: Test 34 | run: go test ./... 35 | 36 | docker: 37 | if: github.event_name == 'release' && github.event.action == 'created' 38 | needs: test 39 | 40 | runs-on: ubuntu-latest 41 | permissions: 42 | contents: read 43 | packages: write 44 | 45 | steps: 46 | - name: Checkout repository 47 | uses: actions/checkout@v2 48 | 49 | - name: Log in to the Container registry 50 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 51 | with: 52 | registry: ${{ env.REGISTRY }} 53 | username: ${{ github.actor }} 54 | password: ${{ secrets.GITHUB_TOKEN }} 55 | 56 | - name: Extract metadata (tags, labels) for Docker 57 | id: meta 58 | uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 59 | with: 60 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 61 | 62 | - name: Build and push Docker image 63 | uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc 64 | with: 65 | context: . 66 | push: true 67 | tags: ${{ steps.meta.outputs.tags }} 68 | labels: ${{ steps.meta.outputs.labels }} 69 | 70 | binaries: 71 | if: github.event_name == 'release' && github.event.action == 'created' 72 | needs: test 73 | 74 | runs-on: ubuntu-latest 75 | steps: 76 | - name: Checkout 77 | uses: actions/checkout@v2 78 | with: 79 | fetch-depth: 0 80 | 81 | - name: Set up Go 82 | uses: actions/setup-go@v2 83 | with: 84 | go-version: 1.21.x 85 | 86 | - name: Run GoReleaser 87 | uses: goreleaser/goreleaser-action@v2 88 | with: 89 | distribution: goreleaser 90 | version: latest 91 | args: release --clean 92 | env: 93 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 94 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example .goreleaser.yml file with some sane defaults. 2 | # Make sure to check the documentation at http://goreleaser.com 3 | before: 4 | hooks: 5 | # You may remove this if you don't use go modules. 6 | - go mod tidy 7 | # you may remove this if you don't need go generate 8 | - go generate ./... 9 | builds: 10 | - env: 11 | - CGO_ENABLED=0 12 | goos: 13 | - linux 14 | - windows 15 | - darwin 16 | main: ./server/cmd/glslsandbox 17 | binary: glslsandbox 18 | id: glslsandbox 19 | - env: 20 | - CGO_ENABLED=0 21 | goos: 22 | - linux 23 | - windows 24 | - darwin 25 | main: ./server/cmd/glsladmin 26 | binary: glsladmin 27 | id: glsladmin 28 | archives: 29 | # replacements was deprecated 30 | # https://goreleaser.com/deprecations/#archivesreplacements 31 | - id: foo 32 | name_template: >- 33 | {{- .ProjectName }}_ 34 | {{- title .Os }}_ 35 | {{- if eq .Arch "amd64" }}x86_64 36 | {{- else if eq .Arch "386" }}i386 37 | {{- else }}{{ .Arch }}{{ end }} 38 | {{- if .Arm }}v{{ .Arm }}{{ end -}} 39 | 40 | checksum: 41 | name_template: 'checksums.txt' 42 | snapshot: 43 | name_template: "{{ .Tag }}-next" 44 | changelog: 45 | sort: asc 46 | filters: 47 | exclude: 48 | - '^docs:' 49 | - '^test:' 50 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.21 AS builder 2 | 3 | ENV GOPATH /go 4 | RUN apt-get update && \ 5 | apt-get install -y libsqlite3-0 libsqlite3-dev 6 | 7 | WORKDIR /build 8 | COPY . . 9 | 10 | RUN go build -tags cgosqlite -v ./server/cmd/glslsandbox 11 | 12 | FROM debian:bookworm-slim 13 | 14 | RUN apt-get update && \ 15 | apt-get install -y --no-install-recommends ca-certificates && \ 16 | apt-get clean && \ 17 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 18 | 19 | EXPOSE 8888 20 | EXPOSE 8883 21 | COPY --from=builder /build/ /glslsandbox/ 22 | ENTRYPOINT [ "/glslsandbox/entrypoint.sh" ] 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011 Mr.doob 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glsl-sandbox 2 | 3 | ## Server development 4 | 5 | ### Setup 6 | 7 | * Fork repository 8 | * Download repository and create new development branch: 9 | 10 | ``` 11 | $ git clone git@github.com:/glsl-sandbox 12 | $ cd glsl-sandbox 13 | $ git checkout -b 14 | ``` 15 | 16 | * Download and uncompress test data: 17 | 18 | ``` 19 | $ curl -O https://downloads.zooloo.org/glslsandbox-data.tar.gz 20 | $ tar xvf glslsandbox-data.tar.gz 21 | ``` 22 | 23 | * Build server binary needs go compiler: 24 | 25 | ``` 26 | $ go build ./server/cmd/glslsandbox 27 | ``` 28 | 29 | * Alternatively you can download and uncompress the binary in the repository directory from https://github.com/mrdoob/glsl-sandbox/releases/latest 30 | 31 | * Run server: 32 | 33 | ``` 34 | $ ./glslsandbox 35 | ``` 36 | 37 | * The first time it starts it creates an admin user and the credentials are printed. 38 | 39 | * The server should be accessible on http://localhost:8888 40 | 41 | * Admin interface is on http://localhost:8888/admin 42 | 43 | ### Template and javascript modifications 44 | 45 | The server reloads templates and assets on each query. This eases the development as you can modify the files and changes will take effect reloading the page. 46 | 47 | There's only one template that is used for both the gallery (index) and admin page. The file is `server/assets/gallery.html` and uses go language templates. You can find more information about its syntax here: 48 | 49 | * https://gohugo.io/templates/introduction/ 50 | * https://pkg.go.dev/text/template 51 | * https://pkg.go.dev/html/template 52 | 53 | Currently the page receives this data: 54 | 55 | ```go 56 | // galleryEffect has information about each effect displayed in the gallery. 57 | type galleryEffect struct { 58 | // ID is the effect identifyier. 59 | ID int 60 | // Version is the latest effect version. 61 | Version int 62 | // Image holds the thumbnail name. 63 | Image string 64 | // Hidden tells if the effect has been moderated. 65 | Hidden bool 66 | } 67 | 68 | // galleryData has information about the current gallery page. 69 | type galleryData struct { 70 | // Effects is an array with all the effects for the page. 71 | Effects []galleryEffect 72 | // URL is the path of the gallery. Can be "/" or "/admin". 73 | URL string 74 | // Page holds the current page number. 75 | Page int 76 | // IsPrevious is true if there is a previous page. 77 | IsPrevious bool 78 | // PreviousPage is the previous page number. 79 | PreviousPage int 80 | // IsNext is true if there is a next page. 81 | IsNext bool 82 | // NextPage is the next page number. 83 | NextPage int 84 | // Admin is true when accessing "/admin" path. 85 | Admin bool 86 | } 87 | ``` 88 | 89 | This is, `galleryData` for the page and `galleryEffect` for each effect. For example, to print all the effect IDs you can use: 90 | 91 | ```html 92 |