gitea源码

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. type AttachmentSettingType struct {
  5. Storage *Storage
  6. AllowedTypes string
  7. MaxSize int64
  8. MaxFiles int
  9. Enabled bool
  10. }
  11. var Attachment AttachmentSettingType
  12. func loadAttachmentFrom(rootCfg ConfigProvider) (err error) {
  13. Attachment = AttachmentSettingType{
  14. AllowedTypes: ".avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip",
  15. MaxSize: 2048,
  16. MaxFiles: 5,
  17. Enabled: true,
  18. }
  19. sec, _ := rootCfg.GetSection("attachment")
  20. if sec == nil {
  21. Attachment.Storage, err = getStorage(rootCfg, "attachments", "", nil)
  22. return err
  23. }
  24. Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(Attachment.AllowedTypes)
  25. Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(Attachment.MaxSize)
  26. Attachment.MaxFiles = sec.Key("MAX_FILES").MustInt(Attachment.MaxFiles)
  27. Attachment.Enabled = sec.Key("ENABLED").MustBool(Attachment.Enabled)
  28. Attachment.Storage, err = getStorage(rootCfg, "attachments", "", sec)
  29. return err
  30. }