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

Code before:
				}
				defer resp.Body.Close()

				blob, err := io.ReadAll(resp.Body)
				if err != nil {
					return echo.NewHTTPError(http.StatusBadRequest, "Failed to read "+resourceCreate.ExternalLink)
				}
				resourceCreate.Blob = blob

				mediaType, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
				if err != nil {
					return echo.NewHTTPError(http.StatusBadRequest, "Failed to read mime from "+resourceCreate.ExternalLink)
				}
				resourceCreate.Type = mediaType

				filename := path.Base(linkURL.Path)
				if path.Ext(filename) == "" {
					extensions, _ := mime.ExtensionsByType(mediaType)
					if len(extensions) > 0 {
						filename += extensions[0]
					}
				}
				resourceCreate.Filename = filename

				resourceCreate.PublicID = common.GenUUID()
				resourceCreate.ExternalLink = ""
			}
		}

		resource, err := s.Store.CreateResource(ctx, resourceCreate)
		if err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
		}
		if err := createResourceCreateActivity(c.Request().Context(), s.Store, resource); err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
		}
		return c.JSON(http.StatusOK, composeResponse(resource))
	})

	g.POST("/resource/blob", func(c echo.Context) error {
		ctx := c.Request().Context()
		userID, ok := c.Get(getUserIDContextKey()).(int)
		if !ok {
			return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
		}

		// This is the backend default max upload size limit.
		maxUploadSetting := s.Store.GetSystemSettingValueOrDefault(&ctx, api.SystemSettingMaxUploadSizeMiBName, "32")
		var settingMaxUploadSizeBytes int
		if settingMaxUploadSizeMiB, err := strconv.Atoi(maxUploadSetting); err == nil {
			settingMaxUploadSizeBytes = settingMaxUploadSizeMiB * MebiByte

Review comment (suggestion):
```suggestion
				resourceCreate.Filename = filename
				resourceCreate.PublicID = common.GenUUID()
				resourceCreate.ExternalLink = ""
```

Code after:
				}
				defer resp.Body.Close()

				blob, err := io.ReadAll(resp.Body)
				if err != nil {
					return echo.NewHTTPError(http.StatusBadRequest, "Failed to read "+resourceCreate.ExternalLink)
				}
				resourceCreate.Blob = blob

				mediaType, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
				if err != nil {
					return echo.NewHTTPError(http.StatusBadRequest, "Failed to read mime from "+resourceCreate.ExternalLink)
				}
				resourceCreate.Type = mediaType

				filename := path.Base(linkURL.Path)
				if path.Ext(filename) == "" {
					extensions, _ := mime.ExtensionsByType(mediaType)
					if len(extensions) > 0 {
						filename += extensions[0]
					}
				}
				resourceCreate.Filename = filename
				resourceCreate.PublicID = common.GenUUID()
				resourceCreate.ExternalLink = ""
			}
		}

		resource, err := s.Store.CreateResource(ctx, resourceCreate)
		if err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
		}
		if err := createResourceCreateActivity(c.Request().Context(), s.Store, resource); err != nil {
			return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
		}
		return c.JSON(http.StatusOK, composeResponse(resource))
	})

	g.POST("/resource/blob", func(c echo.Context) error {
		ctx := c.Request().Context()
		userID, ok := c.Get(getUserIDContextKey()).(int)
		if !ok {
			return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
		}

		// This is the backend default max upload size limit.
		maxUploadSetting := s.Store.GetSystemSettingValueOrDefault(&ctx, api.SystemSettingMaxUploadSizeMiBName, "32")
		var settingMaxUploadSizeBytes int
		if settingMaxUploadSizeMiB, err := strconv.Atoi(maxUploadSetting); err == nil {
			settingMaxUploadSizeBytes = settingMaxUploadSizeMiB * MebiByte
		} else {