chore: add imgur api
This commit is contained in:
parent
2cbd981902
commit
9a26239aa7
|
@ -1,8 +1,8 @@
|
||||||
name: Deploy
|
name: Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
# push:
|
||||||
branches: [ "master" ]
|
# branches: [ "master" ]
|
||||||
release:
|
release:
|
||||||
types: [ published ]
|
types: [ published ]
|
||||||
|
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -3,8 +3,9 @@ export HTTP_LISTEN=:8085
|
||||||
export PASTE_STORE=data/paste/
|
export PASTE_STORE=data/paste/
|
||||||
export ARTIFACT_STORE=data/artifact/
|
export ARTIFACT_STORE=data/artifact/
|
||||||
export IMAGE_STORE=data/image/
|
export IMAGE_STORE=data/image/
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
|
||||||
SOURCE=$(wildcard v2/*.go) $(wildcard v2/paste/*.go) $(wildcard assets/*.go)
|
SOURCE=$(wildcard *.go) $(wildcard paste/*.go) $(wildcard assets/*.go)
|
||||||
ASSETS=$(wildcard assets/*) $(wildcard assets/public/*) $(wildcard assets/src/*) $(wildcard assets/src/paste/*)
|
ASSETS=$(wildcard assets/*) $(wildcard assets/public/*) $(wildcard assets/src/*) $(wildcard assets/src/paste/*)
|
||||||
ASSET_FILE=assets/build/index.html
|
ASSET_FILE=assets/build/index.html
|
||||||
BINARY=sour.is-paste
|
BINARY=sour.is-paste
|
||||||
|
@ -30,7 +31,7 @@ ${ASSET_FILE}: $(ASSETS)
|
||||||
|
|
||||||
build: $(BINARY)
|
build: $(BINARY)
|
||||||
$(BINARY): $(SOURCE) $(ASSET_FILE)
|
$(BINARY): $(SOURCE) $(ASSET_FILE)
|
||||||
go build -o $(BINARY) ./v2
|
go build -o $(BINARY) .
|
||||||
|
|
||||||
.PHONEY: all clean build run setup
|
.PHONEY: all clean build run setup
|
||||||
# DO NOT DELETE
|
# DO NOT DELETE
|
||||||
|
|
|
@ -49,7 +49,7 @@ func New(store string, maxSize int64) (a *image, err error) {
|
||||||
func (a *image) RegisterHTTP(mux *http.ServeMux) {
|
func (a *image) RegisterHTTP(mux *http.ServeMux) {
|
||||||
mux.Handle("/i", http.StripPrefix("/i", a))
|
mux.Handle("/i", http.StripPrefix("/i", a))
|
||||||
mux.Handle("/i/", http.StripPrefix("/i/", a))
|
mux.Handle("/i/", http.StripPrefix("/i/", a))
|
||||||
mux.Handle("3/upload", http.StripPrefix("/3/upload", a))
|
mux.Handle("/3/upload", a)
|
||||||
|
|
||||||
}
|
}
|
||||||
func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -63,13 +63,23 @@ func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
a.get(ctx, w, name)
|
a.get(ctx, w, name)
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
|
var err error
|
||||||
|
var fd io.ReadCloser = r.Body
|
||||||
|
if r.URL.Path == "/3/upload" {
|
||||||
|
fd, _, err = r.FormFile("image")
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
length := 0
|
length := 0
|
||||||
if h := r.Header.Get("Content-Length"); h != "" {
|
if h := r.Header.Get("Content-Length"); h != "" {
|
||||||
if i, err := strconv.Atoi(h); err != nil {
|
if i, err := strconv.Atoi(h); err != nil {
|
||||||
length = i
|
length = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id, err := a.put(ctx, w, r.Body, length)
|
id, err := a.put(ctx, w, fd, length)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, ErrGone):
|
case errors.Is(err, ErrGone):
|
||||||
w.WriteHeader(http.StatusGone)
|
w.WriteHeader(http.StatusGone)
|
||||||
|
@ -91,7 +101,7 @@ func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
}{
|
}{
|
||||||
Data: data{
|
Data: data{
|
||||||
Link: fmt.Sprintf("https://%s/%s", r.Host, id),
|
Link: fmt.Sprintf("https://%s/i/%s", r.Host, id),
|
||||||
},
|
},
|
||||||
Success: true,
|
Success: true,
|
||||||
Status: 200,
|
Status: 200,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user