mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-02-25 14:03:09 -06:00
mediaapi/writers/download: Improve logging
This commit is contained in:
parent
391a1be69f
commit
619a77e187
|
|
@ -175,10 +175,6 @@ func Download(w http.ResponseWriter, req *http.Request, origin types.ServerName,
|
||||||
logger.WithFields(log.Fields{
|
logger.WithFields(log.Fields{
|
||||||
"MediaID": r.MediaMetadata.MediaID,
|
"MediaID": r.MediaMetadata.MediaID,
|
||||||
"Origin": r.MediaMetadata.Origin,
|
"Origin": r.MediaMetadata.Origin,
|
||||||
"UploadName": r.MediaMetadata.UploadName,
|
|
||||||
"Content-Length": r.MediaMetadata.ContentLength,
|
|
||||||
"Content-Type": r.MediaMetadata.ContentType,
|
|
||||||
"Content-Disposition": r.MediaMetadata.ContentDisposition,
|
|
||||||
}).Infof("Fetching remote file")
|
}).Infof("Fetching remote file")
|
||||||
|
|
||||||
// TODO: lock request in hash set
|
// TODO: lock request in hash set
|
||||||
|
|
@ -234,6 +230,11 @@ func Download(w http.ResponseWriter, req *http.Request, origin types.ServerName,
|
||||||
}
|
}
|
||||||
r.MediaMetadata.ContentLength = types.ContentLength(contentLength)
|
r.MediaMetadata.ContentLength = types.ContentLength(contentLength)
|
||||||
|
|
||||||
|
logger.WithFields(log.Fields{
|
||||||
|
"MediaID": r.MediaMetadata.MediaID,
|
||||||
|
"Origin": r.MediaMetadata.Origin,
|
||||||
|
}).Infof("Connected to remote")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", string(r.MediaMetadata.ContentType))
|
w.Header().Set("Content-Type", string(r.MediaMetadata.ContentType))
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(int64(r.MediaMetadata.ContentLength), 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(int64(r.MediaMetadata.ContentLength), 10))
|
||||||
contentSecurityPolicy := "default-src 'none';" +
|
contentSecurityPolicy := "default-src 'none';" +
|
||||||
|
|
@ -263,6 +264,11 @@ func Download(w http.ResponseWriter, req *http.Request, origin types.ServerName,
|
||||||
}
|
}
|
||||||
defer tmpFile.Close()
|
defer tmpFile.Close()
|
||||||
|
|
||||||
|
logger.WithFields(log.Fields{
|
||||||
|
"MediaID": r.MediaMetadata.MediaID,
|
||||||
|
"Origin": r.MediaMetadata.Origin,
|
||||||
|
}).Infof("Proxying and caching remote file")
|
||||||
|
|
||||||
// bytesResponded is the total number of bytes written to the response to the client request
|
// bytesResponded is the total number of bytes written to the response to the client request
|
||||||
// bytesWritten is the total number of bytes written to disk
|
// bytesWritten is the total number of bytes written to disk
|
||||||
var bytesResponded, bytesWritten int64 = 0, 0
|
var bytesResponded, bytesWritten int64 = 0, 0
|
||||||
|
|
@ -349,6 +355,15 @@ func Download(w http.ResponseWriter, req *http.Request, origin types.ServerName,
|
||||||
// Note: After this point we have responded to the client's request and are just dealing with local caching.
|
// Note: After this point we have responded to the client's request and are just dealing with local caching.
|
||||||
// As we have responded with 200 OK, any errors are ineffectual to the client request and so we just log and return.
|
// As we have responded with 200 OK, any errors are ineffectual to the client request and so we just log and return.
|
||||||
|
|
||||||
|
logger.WithFields(log.Fields{
|
||||||
|
"MediaID": r.MediaMetadata.MediaID,
|
||||||
|
"Origin": r.MediaMetadata.Origin,
|
||||||
|
"UploadName": r.MediaMetadata.UploadName,
|
||||||
|
"Content-Length": r.MediaMetadata.ContentLength,
|
||||||
|
"Content-Type": r.MediaMetadata.ContentType,
|
||||||
|
"Content-Disposition": r.MediaMetadata.ContentDisposition,
|
||||||
|
}).Infof("Storing file metadata to media repository database")
|
||||||
|
|
||||||
// if written to disk, add to db
|
// if written to disk, add to db
|
||||||
err = db.StoreMediaMetadata(r.MediaMetadata)
|
err = db.StoreMediaMetadata(r.MediaMetadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -374,6 +389,15 @@ func Download(w http.ResponseWriter, req *http.Request, origin types.ServerName,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.WithFields(log.Fields{
|
||||||
|
"MediaID": r.MediaMetadata.MediaID,
|
||||||
|
"Origin": r.MediaMetadata.Origin,
|
||||||
|
"UploadName": r.MediaMetadata.UploadName,
|
||||||
|
"Content-Length": r.MediaMetadata.ContentLength,
|
||||||
|
"Content-Type": r.MediaMetadata.ContentType,
|
||||||
|
"Content-Disposition": r.MediaMetadata.ContentDisposition,
|
||||||
|
}).Infof("Remote file cached")
|
||||||
} else {
|
} else {
|
||||||
// TODO: If we do not have a record and the origin is local, or if we have another error from the database, the file is not found
|
// TODO: If we do not have a record and the origin is local, or if we have another error from the database, the file is not found
|
||||||
jsonErrorResponse(w, util.JSONResponse{
|
jsonErrorResponse(w, util.JSONResponse{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue