Skip to content

Commit

Permalink
feat(server): asset gzip upload (#1363)
Browse files Browse the repository at this point in the history
* feat(server): asset gzip upload

* update

* fix

* fix
  • Loading branch information
rot1024 authored Jan 22, 2025
1 parent ed5b3f1 commit 815601f
Show file tree
Hide file tree
Showing 28 changed files with 626 additions and 285 deletions.
1 change: 0 additions & 1 deletion server/e2e/integration_asset_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func TestIntegrationCreateAssetAPI(t *testing.T) {
Status(http.StatusOK).
JSON().
Object().
// HasValue("id", aid1.String()).
HasValue("projectId", pid).
HasValue("name", "testFile.jpg").
HasValue("contentType", "image/jpeg").
Expand Down
15 changes: 0 additions & 15 deletions server/e2e/integration_asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@ package e2e

import (
"net/http"
"strings"
"testing"

"github.com/gavv/httpexpect/v2"
"github.com/reearth/reearth-cms/server/internal/app"
"github.com/reearth/reearth-cms/server/pkg/id"
)

func UploadAsset(e *httpexpect.Expect, pId string, path string, content string) *httpexpect.Value {
res := e.POST("/api/projects/{projectId}/assets", pId).
WithHeader("X-Reearth-Debug-User", uId1.String()).
WithMultipart().
WithFile("file", path, strings.NewReader(content)).
WithForm(map[string]any{"skipDecompression": true}).
Expect().
Status(http.StatusOK).
JSON()

return res
}

// GET /assets/{assetId}
func TestIntegrationGetAssetAPI(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeeder)
Expand Down
19 changes: 16 additions & 3 deletions server/e2e/integration_item_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestIntegrationModelImportJSONWithGeoJsonInput(t *testing.T) {

// strategy="insert" and mutateSchema=false
fileContent1 := `{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [139.28179282584915,36.58570985749664]}, "properties": {"text": "test2"}}]}`
aId := UploadAsset(e, pId, "./test1.geojson", fileContent1).Object().Value("id").String().Raw()
aId := uploadAsset(e, pId, "./test1.geojson", fileContent1).Object().Value("id").String().Raw()
res := IntegrationModelImportJSON(e, mId, aId, "geoJson", "insert", false, &fids.geometryObjectFid)
res.Object().Value("modelId").String().IsEqual(mId)
res.Object().IsEqual(map[string]any{
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestIntegrationModelImportJSONWithJsonInput1(t *testing.T) {
createFieldOfEachType(t, e, mId)

jsonContent := `[{"text": "test1", "bool": true, "number": 1.1},{"text": "test2", "bool": false, "number": 2},{"text": "test3", "bool": null, "number": null}]`
aId := UploadAsset(e, pId, "./test1.json", jsonContent).Object().Value("id").String().Raw()
aId := uploadAsset(e, pId, "./test1.json", jsonContent).Object().Value("id").String().Raw()
res := IntegrationModelImportJSON(e, mId, aId, "json", "insert", false, nil)
res.Object().IsEqual(map[string]any{
"modelId": mId,
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestIntegrationModelImportJSONWithJsonInput2(t *testing.T) {
iId := r.Value("id").String().Raw()

jsonContent := `[{"id": "` + iId + `","text": "test1", "bool": true, "number": 1.1},{"text": "test2", "bool": false, "number": 2},{"text": "test3", "bool": null, "number": null}]`
aId := UploadAsset(e, pId, "./test1.json", jsonContent).Object().Value("id").String().Raw()
aId := uploadAsset(e, pId, "./test1.json", jsonContent).Object().Value("id").String().Raw()
res := IntegrationModelImportJSON(e, mId, aId, "json", "upsert", true, nil)
res.Object().IsEqual(map[string]any{
"modelId": mId,
Expand Down Expand Up @@ -310,3 +310,16 @@ func TestIntegrationModelImportJSONWithJsonInput2(t *testing.T) {
i.Value("fields").Array().Length().IsEqual(1)
// endregion
}

func uploadAsset(e *httpexpect.Expect, pId string, path string, content string) *httpexpect.Value {
res := e.POST("/api/projects/{projectId}/assets", pId).
WithHeader("X-Reearth-Debug-User", uId1.String()).
WithMultipart().
WithFile("file", path, strings.NewReader(content)).
WithForm(map[string]any{"skipDecompression": true}).
Expect().
Status(http.StatusOK).
JSON()

return res
}
1 change: 1 addition & 0 deletions server/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ reviewer should be owner or maintainer: ""
thread is required: ""
title cannot be empty: ""
unauthorized: ""
unsupported content encoding: ""
unsupported entity: ""
unsupported geometry type: ""
unsupported operation: ""
Expand Down
5 changes: 3 additions & 2 deletions server/i18n/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ reviewer should be owner or maintainer: レビュワーはオーナーもしく
thread is required: スレッドは必須です。
title cannot be empty: タイトルは必須です。
unauthorized: 未認証
unsupported entity: サポートされていないエンティティ
unsupported geometry type: サポートされていないジオメトリタイプ
unsupported content encoding: サポートされていないContent-Encodingです。
unsupported entity: サポートされていないエンティティです。
unsupported geometry type: サポートされていないジオメトリタイプです。
unsupported operation: サポートされていない処理です。
uuid is required: UUIDは必須です。
value is required: 値は必須です。
Expand Down
Loading

0 comments on commit 815601f

Please sign in to comment.