mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-21 20:07:33 +00:00
feat: dimensions
This commit is contained in:
parent
578c7ca992
commit
2c20730aa5
11
Dockerfile
11
Dockerfile
@ -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"]
|
||||
|
@ -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,
|
||||
Width: width,
|
||||
Height: height,
|
||||
})
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ type UserProfileResponse struct {
|
||||
|
||||
type BlobResponse struct {
|
||||
ID string `json:"id"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
}
|
||||
|
||||
type PostPaginationResponse struct {
|
||||
|
Loading…
Reference in New Issue
Block a user