🐛 Provide a way to bypass nexus and serving content to prevent nexus reverse proxy issue

This commit is contained in:
2024-11-06 23:01:29 +08:00
parent 2f99ac7b6e
commit c41f8b77ce
9 changed files with 6460 additions and 636 deletions

View File

@ -26,12 +26,7 @@ func openAttachment(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusNotFound, "file is in uploading progress, please wait until all chunk uploaded")
}
var destMap map[string]any
if metadata.Destination == models.AttachmentDstTemporary {
destMap = viper.GetStringMap("destinations.temporary")
} else {
destMap = viper.GetStringMap("destinations.permanent")
}
destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", metadata.Destination))
var dest models.BaseDestination
rawDest, _ := jsoniter.Marshal(destMap)
@ -41,10 +36,19 @@ func openAttachment(c *fiber.Ctx) error {
case models.DestinationTypeLocal:
var destConfigured models.LocalDestination
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
if len(destConfigured.AccessBaseURL) > 0 && !c.QueryBool("direct", false) {
// This will drop all query parameters,
// for not it's okay because the openAttachment api won't take any query parameters
return c.Redirect(fmt.Sprintf(
"%s%s?direct=true",
destConfigured.AccessBaseURL,
c.Path(),
), fiber.StatusMovedPermanently)
}
if len(metadata.MimeType) > 0 {
c.Set(fiber.HeaderContentType, metadata.MimeType)
}
return c.SendFile(filepath.Join(destConfigured.Path, metadata.Uuid), false)
return c.SendFile(filepath.Join(destConfigured.Path, metadata.Uuid))
case models.DestinationTypeS3:
var destConfigured models.S3Destination
_ = jsoniter.Unmarshal(rawDest, &destConfigured)