Repository: usememos/memos
File: server/resource.go (Go)

Code before:
		}

		file, err := c.FormFile("file")
		if err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get uploading file").SetInternal(err)
		}
		if file == nil {
			return echo.NewHTTPError(http.StatusBadRequest, "Upload file not found").SetInternal(err)
		}

		filename := file.Filename
		filetype := file.Header.Get("Content-Type")
		size := file.Size
		src, err := file.Open()
		if err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to open file").SetInternal(err)
		}
		defer src.Close()

		var resourceCreate *api.ResourceCreate
		systemSettingStorageServiceName := api.SystemSettingStorageServiceName
		systemSetting, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{Name: &systemSettingStorageServiceName})
		if err != nil && common.ErrorCode(err) != common.NotFound {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
		}
		if common.ErrorCode(err) == common.NotFound || systemSetting.Value == "Database" {
			fileBytes, err := io.ReadAll(src)
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read file").SetInternal(err)
			}
			resourceCreate = &api.ResourceCreate{
				CreatorID: userID,
				Filename:  filename,
				Type:      filetype,
				Size:      size,
				Blob:      fileBytes,
			}
		} else {
			storage, err := s.Store.FindStorage(ctx, &api.StorageFind{Name: &systemSetting.Value})
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
			}

			s3client, err := s3.NewClient(ctx, storage)
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to new s3 client").SetInternal(err)
			}

			link, err := s3.UploadFile(ctx, s3client, filename, filetype, src, storage)
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upload via s3 client").SetInternal(err)

Review comment (suggestion):
* empty string: store into database
* others: find storage table

```suggestion
		if common.ErrorCode(err) == common.NotFound || systemSetting.Value == "" {
```

Code after:
		}

		file, err := c.FormFile("file")
		if err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get uploading file").SetInternal(err)
		}
		if file == nil {
			return echo.NewHTTPError(http.StatusBadRequest, "Upload file not found").SetInternal(err)
		}

		filename := file.Filename
		filetype := file.Header.Get("Content-Type")
		size := file.Size
		src, err := file.Open()
		if err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to open file").SetInternal(err)
		}
		defer src.Close()

		var resourceCreate *api.ResourceCreate
		systemSettingStorageServiceName := api.SystemSettingStorageServiceName
		systemSetting, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{Name: &systemSettingStorageServiceName})
		if err != nil && common.ErrorCode(err) != common.NotFound {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
		}
		if common.ErrorCode(err) == common.NotFound || systemSetting.Value == "" {
			fileBytes, err := io.ReadAll(src)
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read file").SetInternal(err)
			}
			resourceCreate = &api.ResourceCreate{
				CreatorID: userID,
				Filename:  filename,
				Type:      filetype,
				Size:      size,
				Blob:      fileBytes,
			}
		} else {
			storage, err := s.Store.FindStorage(ctx, &api.StorageFind{Name: &systemSetting.Value})
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find storage").SetInternal(err)
			}

			s3client, err := s3.NewClient(ctx, storage)
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to new s3 client").SetInternal(err)
			}

			link, err := s3client.UploadFile(ctx, filename, filetype, src, storage)
			if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upload via s3 client").SetInternal(err)