feat: dimensions

This commit is contained in:
Damillora 2021-05-11 17:33:22 +07:00
parent 578c7ca992
commit 2c20730aa5
6 changed files with 46 additions and 8 deletions

View File

@ -4,7 +4,7 @@ WORKDIR /go/src/shioriko
COPY . .
RUN go get -d -v ./...
RUN go build -o /shioriko
RUN CGO_ENABLED=0 GOOS=linux go build -o /shioriko
RUN mkdir -p /web && cp -r web/static web/template /web
FROM node:14-alpine AS node_build
@ -13,12 +13,11 @@ COPY . .
WORKDIR /src/web/app
RUN yarn install && yarn build
FROM alpine AS runtime
FROM scratch AS runtime
RUN mkdir -p /app/web
WORKDIR /app
COPY --from=build /shioriko /app
COPY --from=node_build /src/web/static /app/web/static
COPY --from=node_build /src/web/template /app/web/template
COPY --from=build /shioriko /app/
COPY --from=node_build /src/web/static/ /app/web/static/
COPY --from=node_build /src/web/template/ /app/web/template/
ENTRYPOINT ["/app/shioriko"]

View File

@ -1,6 +1,10 @@
package app
import (
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"net/http"
"os"
"path/filepath"
@ -31,7 +35,30 @@ func uploadBlob(c *gin.Context) {
Code: http.StatusBadRequest,
Message: err.Error(),
})
return
}
fileObj, err := file.Open()
if err != nil {
c.JSON(http.StatusBadRequest, models.ErrorResponse{
Code: http.StatusBadRequest,
Message: err.Error(),
})
return
}
image, _, err := image.Decode(fileObj)
if err != nil {
c.JSON(http.StatusBadRequest, models.ErrorResponse{
Code: http.StatusBadRequest,
Message: err.Error(),
})
return
}
width := image.Bounds().Dx()
height := image.Bounds().Dy()
id := uuid.NewString()
folder1 := id[0:2]
if _, err := os.Stat(filepath.Join(dataDir, folder1)); os.IsNotExist(err) {
@ -55,10 +82,14 @@ func uploadBlob(c *gin.Context) {
blob := database.Blob{
ID: id,
FilePath: filepath.Join(folder1, folder2, filename),
Width: width,
Height: height,
}
database.DB.Create(&blob)
c.JSON(http.StatusOK, models.BlobResponse{
ID: id,
ID: id,
Width: width,
Height: height,
})
}

View File

@ -86,6 +86,8 @@ func postGetOne(c *gin.Context) {
ImagePath: "/data/" + post.Blob.FilePath,
SourceURL: post.SourceURL,
Tags: tagStrings,
Width: post.Blob.Width,
Height: post.Blob.Height,
})
}

View File

@ -7,6 +7,8 @@ import (
type Blob struct {
ID string `gorm:"size:36"`
FilePath string
Width int
Height int
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@ -5,4 +5,6 @@ type PostReadModel struct {
ImagePath string `json:"image_path"`
SourceURL string `json:"source_url"`
Tags []string `json:"tags"`
Width int `json:"width"`
Height int `json:"height"`
}

View File

@ -15,7 +15,9 @@ type UserProfileResponse struct {
}
type BlobResponse struct {
ID string `json:"id"`
ID string `json:"id"`
Width int `json:"width"`
Height int `json:"height"`
}
type PostPaginationResponse struct {