Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "infinity", "clone"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
silent = false
time = false

[misc]
clean_on_exit = false

[proxy]
app_port = 0
enabled = false
proxy_port = 0

[screen]
clear_on_rebuild = false
keep_scroll = true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/data/
/ignore/
/tmp/
/clone/
/infinity/
corrugation-backend
*.sqlite
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Dockerfile References: https://docs.docker.com/engine/reference/builder/

# Start from golang:1.12-alpine base image
FROM golang:1.19-alpine
FROM golang:1.25-alpine

# The latest alpine images don't have some tools like (`git` and `bash`).
# Adding git, bash and openssh to the image
RUN apk update && apk upgrade && apk add --no-cache bash git openssh

# Add Maintainer Info
LABEL maintainer="William Floyd <[email protected]>"
LABEL maintainer="William Floyd <[email protected]>"

# Set the Current Working Directory inside the container
WORKDIR /app
Expand Down
82 changes: 82 additions & 0 deletions backend/artifact-handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package backend

import (
"context"
"net/http"
"path/filepath"
"strings"

"github.com/danielgtaylor/huma/v2"
)

var CreateArtifactOperation = huma.Operation{
Method: http.MethodPost,
Path: "/api/v2/artifact",
}

func CreateArtifact(ctx context.Context, input *struct {
RawBody huma.MultipartFormFiles[struct {
File huma.FormFile `form:"file" required:"true"`
}]
}) (output *UIntOutput, err error) {

f := input.RawBody.Data().File

var a ArtifactInterface

if strings.HasPrefix(f.ContentType, "image/") {
a = &Image{}
} else {
switch filepath.Ext(f.Filename) {
case ".png", ".jpeg", ".jpg", ".webp":
a = &Image{}
default:
err = huma.Error415UnsupportedMediaType("unsupported media type " + f.ContentType)
return
}
}

err = a.Store(f)
if err != nil {
return
}

output = &UIntOutput{
Body: a.GetID(),
}

return
}

var GetArtifactOperation = huma.Operation{
Method: http.MethodGet,
Path: "/api/v2/artifact/{id}",
}

func GetArtifact(ctx context.Context, input *struct {
ID uint `path:"id" example:"1" doc:"Artifact ID to get"`
}) (output *BytesOutput, err error) {

artifact, err := GetArtifactFromDB(input.ID)
if err != nil {
return
}

i, err := artifact.GetInterface()
if err != nil {
return
}

output = &BytesOutput{}

ob, err := i.GetSmallPreviewContents()
if err != nil {
return
}

output.Body = *ob
output.ContentType = http.DetectContentType(output.Body)
output.CacheControl = "public, max-age=604800"

return
}
Loading