From ce3ed4bc2cc059d71a0935465ddfb70d0be3b70e Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Thu, 13 Jan 2022 10:06:19 -0800 Subject: [PATCH] adding forwarding address --- doc/api.oa3 | 85 +++++++++++++++++++-- net/server/internal/api_account.go | 6 ++ net/server/internal/api_admin.go | 10 +-- net/server/internal/model_account_status.go | 3 + net/server/internal/store/schema.go | 41 +++++----- net/server/main_test.go | 11 ++- 6 files changed, 121 insertions(+), 35 deletions(-) diff --git a/doc/api.oa3 b/doc/api.oa3 index 6f8ef714..26870699 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -61,8 +61,10 @@ paths: responses: '200': description: success - '406': - description: node already claimed + content: + application/json: + schema: + type: boolean '500': description: internal server error @@ -285,10 +287,10 @@ paths: responses: '200': description: success - '401': - description: permission denied - '406': - description: accounts not available + content: + application/json: + schema: + type: boolean '500': description: internal server error @@ -333,10 +335,12 @@ paths: responses: '200': description: success + content: + application/json: + schema: + type: boolean '401': description: permission denied - '406': - description: username already claimed '500': description: internal server error @@ -436,6 +440,20 @@ paths: description: permission denied '500': description: internal server error + delete: + tags: + - account + description: Delete account. Access granted to valid create account token. + operationId: remove-account + security: + - basicAuth: [] + responses: + '201': + description: successful operation + '401': + description: permission denied + '500': + description: internal server error /account/profile/image: get: @@ -460,6 +478,36 @@ paths: '500': description: internal server error + /account/assets/{assetId}: + get: + tags: + - account + description: Get asset assigned to an account. The endpoint supports byte-range requests and responds with the content-type set appropriatly. Access granted to the app tokens of the account holder and in the case of non-original assets, the contact token for accounts with which the article is shared. + operationId: get-account-asset + security: + - basicAuth: [] + parameters: + - name: assetId + in: path + description: specified asset id + required: true + schema: + type: string + responses: + '200': + description: success + content: + application/octet-stream: #asset specific + schema: + type: string + format: binary + '401': + description: permission denied + '404': + description: asset or article not found + '500': + description: internal server error + /account/auth: post: tags: @@ -495,6 +543,24 @@ paths: '500': description: internal server error + /account/node: + put: + tags: + - account + description: Set forwarding address after export/import has completed. Access granted to valid reset token. + operationId: set-account-node + security: + - basicAuth: [] + responses: + '201': + description: success + '401': + description: permission denied + '405': + description: failed to confirm + '500': + description: internal server error + /account/apps: get: tags: @@ -3877,6 +3943,7 @@ components: - disabled - storageUsed - storageAvailable + - forwardingAddress properties: disabled: type: boolean @@ -3886,6 +3953,8 @@ components: storageAvailable: type: number format: int64 + forwardingAddress: + type: string Profile: type: object diff --git a/net/server/internal/api_account.go b/net/server/internal/api_account.go index dc4cdfb0..03d089e2 100644 --- a/net/server/internal/api_account.go +++ b/net/server/internal/api_account.go @@ -102,3 +102,9 @@ func SetAccountExport(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) } + +func SetAccountNode(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + diff --git a/net/server/internal/api_admin.go b/net/server/internal/api_admin.go index 6a70a2e6..554c0f2c 100644 --- a/net/server/internal/api_admin.go +++ b/net/server/internal/api_admin.go @@ -56,12 +56,10 @@ func GetNodeAccounts(w http.ResponseWriter, r *http.Request) { func GetNodeClaimable(w http.ResponseWriter, r *http.Request) { - // check if has been configured - if _configured { - w.WriteHeader(http.StatusNotAcceptable) - } else { - w.WriteHeader(http.StatusOK) - } + body, _ := json.Marshal(!_configured); + w.Write(body); + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) } func GetNodeConfig(w http.ResponseWriter, r *http.Request) { diff --git a/net/server/internal/model_account_status.go b/net/server/internal/model_account_status.go index 916ed804..4effd0a9 100644 --- a/net/server/internal/model_account_status.go +++ b/net/server/internal/model_account_status.go @@ -16,4 +16,7 @@ type AccountStatus struct { StorageUsed float64 `json:"storageUsed"` StorageAvailable float64 `json:"storageAvailable"` + + ForwardingAddress string `json:"forwardingAddress"` } + diff --git a/net/server/internal/store/schema.go b/net/server/internal/store/schema.go index ff244a4a..43d9ac97 100644 --- a/net/server/internal/store/schema.go +++ b/net/server/internal/store/schema.go @@ -139,6 +139,21 @@ type LabelGroup struct { Group Group } +type Asset struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + AssetId string `gorm:"not null;index:asset,unique"` + AccountID uint `gorm:"not null;index:asset,unique"` + Status string `gorm:"not null;index"` + Size uint64 + Crc uint32 + Transform string + TransformId string + TransformData string + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Account Account +} + type Article struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` ArticleId string `gorm:"not null;index:article,unique"` @@ -156,17 +171,10 @@ type Article struct { type ArticleAsset struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - AssetId string `gorm:"not null;index:articleasset,unique"` - ArticleID uint `gorm:"not null;index:articleasset,unique"` - Status string `gorm:"not null;index"` - Size uint64 - Crc uint32 - Transform string - TransformId string - TransformData string - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` + AssetID uint + ArticleID uint Article Article + Asset Asset } type ArticleTag struct { @@ -253,17 +261,10 @@ type Topic struct { type TopicAsset struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - AssetId string `gorm:"not null;index:topicasset,unique"` - TopicID uint `gorm:"not null;index:topicasset,unique"` - Status string `gorm:"not null;index"` - Size uint64 - Crc uint32 - Transform string - TransformId string - TransformData string - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` + AssetID uint + TopicID uint Topic Topic + Asset Asset } type TopicTag struct { diff --git a/net/server/main_test.go b/net/server/main_test.go index e3d01691..9edefb27 100644 --- a/net/server/main_test.go +++ b/net/server/main_test.go @@ -23,7 +23,16 @@ func Claimable(t *testing.T) { r := httptest.NewRequest("GET", "/admin/claimable", nil) w := httptest.NewRecorder() app.GetNodeClaimable(w, r) - if w.Code != 200 { + + //body, _ := ioutil.ReadAll(resp.Body) + resp := w.Result() + dec := json.NewDecoder(resp.Body); + var res bool + err := dec.Decode(&res) + if err != nil { + t.Errorf("failed to get claimable response") + } + if resp.StatusCode != 200 { t.Errorf("server not initially claimable") } }