Feat/walt/api seaweedfs#20
Open
nakatashingo wants to merge 8 commits into
Open
Conversation
…image retrieval support
uchida189
reviewed
May 28, 2026
| PixelData []byte `gorm:"column:pixel_data"` // ピクセルデータ | ||
| gorm.Model | ||
| IsShareable bool `gorm:"column:is_shareable"` | ||
| PixelData []byte `gorm:"column:pixel_data"` // 旧レコード互換。新レコードは nil |
| # 再利用可能なコンポーネントを定義するセクション | ||
| description: "花火が削除されました" | ||
| content: {} | ||
| /fireworks/{id}/image: |
Contributor
There was a problem hiding this comment.
このAPIは現状では不要かもしれない。
/firewoksと/fireworks/{id}のレスポンスに含まれるimageURLが、/fireworks/{id}/imageで返されるURLと同じものなので。
| required: | ||
| - id | ||
| - isShareable | ||
| - pixelData |
Contributor
There was a problem hiding this comment.
pixelDataは不要で、
imageURLがrequireだと思います
| @@ -157,9 +186,10 @@ | |||
| items: | |||
| type: boolean | |||
| description: "各ピクセルの状態(点灯/消灯)" | |||
|
|
||
| // is_shareableの値を取得・変換 | ||
| isShareable := false | ||
| if values, exists := form.Value["is_shareable"]; exists && len(values) > 0 { |
Contributor
There was a problem hiding this comment.
ここ書いたの俺なんだけど、is_shareableじゃなくてisShareableに直しておいてほしいです!
ここのせいでisShareableが指定できなくなってた・・・
| volumes: | ||
| - ./api:/app | ||
| working_dir: /app | ||
| command: sh -c "go mod tidy && go run main.go" |
Contributor
There was a problem hiding this comment.
すみません、このcommandの行を削除して欲しいです。
ここのせいでGoのホットリロードが効かなくなってた
| file, err := req.Image.Bytes() | ||
| if err != nil { | ||
| return openapi.FireworkResponse{}, fmt.Errorf("failed to open image file: %w", err) | ||
| func (uc *fireworkUsecase) GetFireworkImageURL(ctx context.Context, id int64) (string, error) { |
Contributor
There was a problem hiding this comment.
これいらないと思った。
理由はopenapi.yamlにコメントした通りで/fireworks/{id}/imageがいらないと思うため
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[feat] 花火画像を SeaweedFS に保存する設計に変更
背景
これまで花火のバイナリデータ(pixel_data)を PostgreSQL
に直接保存していたが、画像ファイルをオブジェクトストレージ(SeaweedFS)
に保存する設計に変更した。
バイナリ変換処理はサーバーから削除し、各クライアント(モバイル・Unity)
が行う責務とする。
変更内容
インフラ
API の変更
にアップロード。pixel_data の生成処理を削除
to(日付)でフィルタリング可能に
を追加(現時点では将来拡張用)
レスポンスの変更
FireworkResponse に imageUrl フィールドを追加。
{
"id": 1,
"imageUrl": "http://localhost:8333/fireworks/images/xxx.jpg",
"isShareable": true,
"pixelData": [],
"createdAt": "...",
"updatedAt": "..."
}
要件外の改善
SeaweedFS の URL(http://seaweedfs:8333)は Docker
内部のホスト名のため、コンテナ外からアクセスできない問題を修正。
STORAGE_PUBLIC_URL 環境変数を追加し、S3 API 通信用エンドポイントと公開
URL を分離した。
動作確認手順
前提
/tmp に確認用の画像を用意しておく
cp /path/to/your/image.png /tmp/test.png
docker compose up --build
ログに Listening on :8080 が出たら準備完了。
curl -X POST http://localhost:8080/fireworks
-F "image=@/tmp/test.png"
-F "is_shareable=true"
期待するレスポンス(HTTP 201)
{
"id": 1,
"imageUrl": "http://localhost:8333/fireworks/images/xxxxxxxx.jpg",
"isShareable": true,
"pixelData": [],
"createdAt": "...",
"updatedAt": "..."
}
imageUrl が http://localhost:8333/... になっていることを確認する。
{id} は手順2のレスポンスの id に置き換える
curl -L http://localhost:8080/fireworks/{id}/image -o
/tmp/downloaded.jpg && open /tmp/downloaded.jpg
アップロードした画像が表示されれば成功。
全件取得
curl http://localhost:8080/fireworks | jq
日付フィルタ
curl "http://localhost:8080/fireworks?from=2026-05-01&to=2026-05-31" |
jq
curl http://localhost:8080/fireworks/{id} | jq
curl -X PUT http://localhost:8080/fireworks/{id}
-H "Content-Type: application/json"
-d '{"isShareable": false}'
curl -X DELETE http://localhost:8080/fireworks/{id}
削除後に再度取得して 404 Not Found が返ることを確認する。
curl -i http://localhost:8080/fireworks/{id}
→ HTTP/1.1 404 Not Found
変更ファイル一覧
バイナリ変換削除・ストレージ操作の追加
新エンドポイント・クエリパラメータの対応