Compare commits
2 Commits
324d6e0d50
...
0d976f0197
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d976f0197 | |||
| 3377e4a352 |
12
README.md
12
README.md
@@ -126,9 +126,14 @@ type Model struct {
|
|||||||
type Image struct {
|
type Image struct {
|
||||||
ID int `json:"id" gorm:"primary_key"`
|
ID int `json:"id" gorm:"primary_key"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Size int `json:"size"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
Prompt string `json:"prompt"`
|
Prompt string `json:"prompt"`
|
||||||
|
Format string `json:"format"`
|
||||||
NegativePrompt string `json:"negative_prompt"`
|
NegativePrompt string `json:"negative_prompt"`
|
||||||
NumInferenceSteps int `json:"num_inference_steps"` // Number of inference steps (minimum: 1; maximum: 500)
|
NumInferenceSteps int `json:"num_inference_steps"` // Number of inference steps (minimum: 1; maximum: 500)
|
||||||
GuidanceScale float32 `json:"guidance_scale"` // Scale for classifier-free guidance (minimum: 1; maximum: 20)
|
GuidanceScale float32 `json:"guidance_scale"` // Scale for classifier-free guidance (minimum: 1; maximum: 20)
|
||||||
@@ -144,8 +149,15 @@ type Image struct {
|
|||||||
- [x] GET [/api/images](/api/images) 圖片列表(全部)
|
- [x] GET [/api/images](/api/images) 圖片列表(全部)
|
||||||
- [x] GET [/api/images?user_id=xxx](/api/images?user_id=xxx) 圖片列表(指定用戶的)
|
- [x] GET [/api/images?user_id=xxx](/api/images?user_id=xxx) 圖片列表(指定用戶的)
|
||||||
- [x] GET [/api/images?tag=xxx](/api/images?tag=xxx) 圖片列表(指定標籤的)
|
- [x] GET [/api/images?tag=xxx](/api/images?tag=xxx) 圖片列表(指定標籤的)
|
||||||
|
- [x] POST [/api/images](/api/images) 上傳圖片(單張)
|
||||||
- [x] DELETE [/api/images/{id}](/api/images/{id}) 刪除指定圖像
|
- [x] DELETE [/api/images/{id}](/api/images/{id}) 刪除指定圖像
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 上傳圖片示例
|
||||||
|
response=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@./data/test.jpeg" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/images)
|
||||||
|
message "$response" "上傳圖片" true
|
||||||
|
```
|
||||||
|
|
||||||
任務:
|
任務:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|||||||
3
go.sum
3
go.sum
@@ -29,8 +29,6 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
|
|||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
|
|
||||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
|
||||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
||||||
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
@@ -53,7 +51,6 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
|
|||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ func ImagesGet(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
||||||
|
models.AccountRead(w, r, func(account *models.Account) {
|
||||||
// 接收上傳的圖片文件, 僅限一張
|
// 接收上傳的圖片文件, 僅限一張
|
||||||
file, file_header, err := r.FormFile("file")
|
file, file_header, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -76,9 +77,10 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
img.Hash = fmt.Sprintf("%x", md5.Sum(content)) // 计算哈希
|
img.Hash = fmt.Sprintf("%x", md5.Sum(content)) // 计算哈希
|
||||||
img.Type = file_header.Header.Get("Content-Type") // 文件類型
|
img.Type = file_header.Header.Get("Content-Type") // 文件類型
|
||||||
img.Path = fmt.Sprintf("data/images/%s.%s", img.Hash, format) // 存儲路徑
|
img.Path = fmt.Sprintf("data/images/%s.%s", img.Hash, format) // 存儲路徑
|
||||||
img.Width = imgData.Bounds().Dx()
|
img.Width = imgData.Bounds().Dx() // 圖片寬度
|
||||||
img.Height = imgData.Bounds().Dy()
|
img.Height = imgData.Bounds().Dy() // 圖片高度
|
||||||
img.Format = format
|
img.Format = format // 圖片格式
|
||||||
|
img.UserID = account.ID // 用戶ID
|
||||||
|
|
||||||
// 先檢查 data/images 目錄是否存在
|
// 先檢查 data/images 目錄是否存在
|
||||||
if _, err := ioutil.ReadDir("data/images"); err != nil {
|
if _, err := ioutil.ReadDir("data/images"); err != nil {
|
||||||
@@ -102,6 +104,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.Write(utils.ToJSON(img))
|
w.Write(utils.ToJSON(img))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImagesItemGet(w http.ResponseWriter, r *http.Request) {
|
func ImagesItemGet(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user