mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
client,bridgev2/matrix: fix context used for async uploads
This commit is contained in:
parent
f32af79d20
commit
a55693bbd7
2 changed files with 10 additions and 2 deletions
|
|
@ -403,6 +403,7 @@ func (as *ASIntent) UploadMediaStream(
|
|||
removeAndClose(replFile)
|
||||
removeAndClose(tempFile)
|
||||
}
|
||||
req.AsyncContext = zerolog.Ctx(ctx).WithContext(as.Connector.Bridge.BackgroundCtx)
|
||||
startedAsyncUpload = true
|
||||
var resp *mautrix.RespCreateMXC
|
||||
resp, err = as.Matrix.UploadAsync(ctx, req)
|
||||
|
|
@ -435,6 +436,7 @@ func (as *ASIntent) doUploadReq(ctx context.Context, file *event.EncryptedFileIn
|
|||
as.Connector.uploadSema.Release(int64(len(req.ContentBytes)))
|
||||
}
|
||||
}
|
||||
req.AsyncContext = zerolog.Ctx(ctx).WithContext(as.Connector.Bridge.BackgroundCtx)
|
||||
var resp *mautrix.RespCreateMXC
|
||||
resp, err = as.Matrix.UploadAsync(ctx, req)
|
||||
if resp != nil {
|
||||
|
|
|
|||
10
client.go
10
client.go
|
|
@ -1933,10 +1933,15 @@ func (cli *Client) UploadAsync(ctx context.Context, req ReqUploadMedia) (*RespCr
|
|||
}
|
||||
req.MXC = resp.ContentURI
|
||||
req.UnstableUploadURL = resp.UnstableUploadURL
|
||||
if req.AsyncContext == nil {
|
||||
req.AsyncContext = cli.cliOrContextLog(ctx).WithContext(context.Background())
|
||||
}
|
||||
go func() {
|
||||
_, err = cli.UploadMedia(ctx, req)
|
||||
_, err = cli.UploadMedia(req.AsyncContext, req)
|
||||
if err != nil {
|
||||
cli.Log.Error().Stringer("mxc", req.MXC).Err(err).Msg("Async upload of media failed")
|
||||
zerolog.Ctx(req.AsyncContext).Err(err).
|
||||
Stringer("mxc", req.MXC).
|
||||
Msg("Async upload of media failed")
|
||||
}
|
||||
}()
|
||||
return resp, nil
|
||||
|
|
@ -1972,6 +1977,7 @@ type ReqUploadMedia struct {
|
|||
ContentType string
|
||||
FileName string
|
||||
|
||||
AsyncContext context.Context
|
||||
DoneCallback func()
|
||||
|
||||
// MXC specifies an existing MXC URI which doesn't have content yet to upload into.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue