-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misc fixes #560
base: main
Are you sure you want to change the base?
Misc fixes #560
Changes from all commits
9498f39
8b0a8e6
6dd81b1
3e03f07
ef35ac7
9518366
87964bb
186f1c9
c518070
cc20a34
f81662d
682b41f
edd19b2
ca68585
fadeb9a
8515e0b
a6b6598
6fc49c2
dc277e9
1f3380e
a31465b
0c957d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package _apimeta | ||
package apimeta | ||
|
||
import ( | ||
"net/http" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert a6b6598 - the package naming is deliberate |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert 87964bb - this is not a change I'm looking to support at the moment, for reasons discussed over chat. Primarily, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,60 @@ | ||
package custom | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/getsentry/sentry-go" | ||
"github.com/t2bot/matrix-media-repo/api/_apimeta" | ||
"github.com/t2bot/matrix-media-repo/api/_responses" | ||
"github.com/t2bot/matrix-media-repo/api/_routers" | ||
"github.com/t2bot/matrix-media-repo/api/apimeta" | ||
"github.com/t2bot/matrix-media-repo/api/responses" | ||
"github.com/t2bot/matrix-media-repo/api/routers" | ||
"github.com/t2bot/matrix-media-repo/common/config" | ||
"github.com/t2bot/matrix-media-repo/datastores" | ||
"github.com/t2bot/matrix-media-repo/tasks" | ||
|
||
"net/http" | ||
"strconv" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/t2bot/matrix-media-repo/common/rcontext" | ||
"github.com/t2bot/matrix-media-repo/util" | ||
) | ||
|
||
type DatastoreMigration struct { | ||
*datastores.SizeEstimate | ||
TaskID int `json:"task_id"` | ||
} | ||
|
||
func GetDatastores(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} { | ||
func GetDatastores(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} { | ||
response := make(map[string]interface{}) | ||
for _, ds := range config.UniqueDatastores() { | ||
uri, err := datastores.GetUri(ds) | ||
for _, store := range config.UniqueDatastores() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's |
||
uri, err := datastores.GetUri(store) | ||
if err != nil { | ||
sentry.CaptureException(err) | ||
rctx.Log.Error("Error getting datastore URI: ", err) | ||
return _responses.InternalServerError("unexpected error getting datastore information") | ||
return responses.InternalServerError(errors.New("unexpected error getting datastore information")) | ||
} | ||
dsMap := make(map[string]interface{}) | ||
dsMap["type"] = ds.Type | ||
dsMap["uri"] = uri | ||
response[ds.Id] = dsMap | ||
dataStoreMap := make(map[string]interface{}) | ||
dataStoreMap["type"] = store.Type | ||
dataStoreMap["uri"] = uri | ||
response[store.Id] = dataStoreMap | ||
} | ||
|
||
return &_responses.DoNotCacheResponse{Payload: response} | ||
return &responses.DoNotCacheResponse{Payload: response} | ||
} | ||
|
||
func MigrateBetweenDatastores(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} { | ||
func MigrateBetweenDatastores(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} { | ||
beforeTsStr := r.URL.Query().Get("before_ts") | ||
beforeTs := util.NowMillis() | ||
beforeTs := time.Now().UnixMilli() | ||
var err error | ||
if beforeTsStr != "" { | ||
beforeTs, err = strconv.ParseInt(beforeTsStr, 10, 64) | ||
if err != nil { | ||
return _responses.BadRequest("Error parsing before_ts: " + err.Error()) | ||
return responses.BadRequest(fmt.Errorf("Error parsing before_ts: %w", err)) | ||
} | ||
} | ||
|
||
sourceDsId := _routers.GetParam("sourceDsId", r) | ||
targetDsId := _routers.GetParam("targetDsId", r) | ||
sourceDsId := routers.GetParam("sourceDsId", r) | ||
targetDsId := routers.GetParam("targetDsId", r) | ||
|
||
rctx = rctx.LogWithFields(logrus.Fields{ | ||
"beforeTs": beforeTs, | ||
|
@@ -61,50 +63,50 @@ func MigrateBetweenDatastores(r *http.Request, rctx rcontext.RequestContext, use | |
}) | ||
|
||
if sourceDsId == targetDsId { | ||
return _responses.BadRequest("Source and target datastore cannot be the same") | ||
return responses.BadRequest(errors.New("Source and target datastore cannot be the same")) | ||
} | ||
if _, ok := datastores.Get(rctx, sourceDsId); !ok { | ||
return _responses.BadRequest("Source datastore does not appear to exist") | ||
return responses.BadRequest(errors.New("Source datastore does not appear to exist")) | ||
} | ||
if _, ok := datastores.Get(rctx, targetDsId); !ok { | ||
return _responses.BadRequest("Target datastore does not appear to exist") | ||
return responses.BadRequest(errors.New("Target datastore does not appear to exist")) | ||
} | ||
|
||
estimate, err := datastores.SizeOfDsIdWithAge(rctx, sourceDsId, beforeTs) | ||
if err != nil { | ||
rctx.Log.Error(err) | ||
sentry.CaptureException(err) | ||
return _responses.InternalServerError("Unexpected error getting storage estimate") | ||
return responses.InternalServerError(errors.New("Unexpected error getting storage estimate")) | ||
} | ||
|
||
rctx.Log.Infof("User %s has started a datastore media transfer", user.UserId) | ||
task, err := tasks.RunDatastoreMigration(rctx, sourceDsId, targetDsId, beforeTs) | ||
if err != nil { | ||
rctx.Log.Error(err) | ||
sentry.CaptureException(err) | ||
return _responses.InternalServerError("Unexpected error starting migration") | ||
return responses.InternalServerError(errors.New("Unexpected error starting migration")) | ||
} | ||
|
||
migration := &DatastoreMigration{ | ||
SizeEstimate: estimate, | ||
TaskID: task.TaskId, | ||
} | ||
|
||
return &_responses.DoNotCacheResponse{Payload: migration} | ||
return &responses.DoNotCacheResponse{Payload: migration} | ||
} | ||
|
||
func GetDatastoreStorageEstimate(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} { | ||
func GetDatastoreStorageEstimate(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} { | ||
beforeTsStr := r.URL.Query().Get("before_ts") | ||
beforeTs := util.NowMillis() | ||
beforeTs := time.Now().UnixMilli() | ||
var err error | ||
if beforeTsStr != "" { | ||
beforeTs, err = strconv.ParseInt(beforeTsStr, 10, 64) | ||
if err != nil { | ||
return _responses.BadRequest("Error parsing before_ts: " + err.Error()) | ||
return responses.BadRequest(fmt.Errorf("Error parsing before_ts: %w", err)) | ||
} | ||
} | ||
|
||
datastoreId := _routers.GetParam("datastoreId", r) | ||
datastoreId := routers.GetParam("datastoreId", r) | ||
|
||
rctx = rctx.LogWithFields(logrus.Fields{ | ||
"beforeTs": beforeTs, | ||
|
@@ -115,7 +117,7 @@ func GetDatastoreStorageEstimate(r *http.Request, rctx rcontext.RequestContext, | |
if err != nil { | ||
rctx.Log.Error(err) | ||
sentry.CaptureException(err) | ||
return _responses.InternalServerError("Unexpected error getting storage estimate") | ||
return responses.InternalServerError(errors.New("Unexpected error getting storage estimate")) | ||
} | ||
return &_responses.DoNotCacheResponse{Payload: result} | ||
return &responses.DoNotCacheResponse{Payload: result} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert 6fc49c2 - the package naming is deliberate