From 6ff7cfddda660e506e5afedf8d0334efc9cb750e Mon Sep 17 00:00:00 2001 From: boojack Date: Tue, 4 Apr 2023 08:31:11 +0800 Subject: [PATCH] fix: return external link directly (#1465) * fix: return external link directly * chore: update --- server/resource.go | 4 ---- server/system.go | 5 ++++- .../prod/0.12/04__resource_public_id.sql | 18 ++++++++---------- web/src/utils/resource.ts | 4 ++++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/server/resource.go b/server/resource.go index 96795048b..da69e132a 100644 --- a/server/resource.go +++ b/server/resource.go @@ -334,10 +334,6 @@ func (s *Server) registerResourcePublicRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find resource by ID: %v", resourceID)).SetInternal(err) } - if resource.ExternalLink != "" { - return c.Redirect(http.StatusSeeOther, resource.ExternalLink) - } - blob := resource.Blob if resource.InternalPath != "" { src, err := os.Open(resource.InternalPath) diff --git a/server/system.go b/server/system.go index 0ec1824c1..a047e90c5 100644 --- a/server/system.go +++ b/server/system.go @@ -9,6 +9,8 @@ import ( "github.com/google/uuid" "github.com/usememos/memos/api" "github.com/usememos/memos/common" + "github.com/usememos/memos/common/log" + "go.uber.org/zap" "github.com/labstack/echo/v4" ) @@ -67,7 +69,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) { var baseValue any err := json.Unmarshal([]byte(systemSetting.Value), &baseValue) if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting value").SetInternal(err) + log.Warn("Failed to unmarshal system setting value", zap.String("setting name", systemSetting.Name.String())) + continue } if systemSetting.Name == api.SystemSettingAllowSignUpName { diff --git a/store/db/migration/prod/0.12/04__resource_public_id.sql b/store/db/migration/prod/0.12/04__resource_public_id.sql index 3d54e5b76..4a30f2cde 100644 --- a/store/db/migration/prod/0.12/04__resource_public_id.sql +++ b/store/db/migration/prod/0.12/04__resource_public_id.sql @@ -3,19 +3,17 @@ ALTER TABLE ADD COLUMN public_id TEXT NOT NULL DEFAULT ''; +-- TODO(steven): remove this in next release. CREATE UNIQUE INDEX resource_id_public_id_unique_index ON resource (id, public_id); UPDATE resource SET - public_id = ( - SELECT - printf( - '%s-%s-%s-%s-%s', - lower(hex(randomblob(4))), - lower(hex(randomblob(2))), - lower(hex(randomblob(2))), - lower(hex(randomblob(2))), - lower(hex(randomblob(6))) - ) as uuid + public_id = printf ( + '%s-%s-%s-%s-%s', + lower(hex(randomblob(4))), + lower(hex(randomblob(2))), + lower(hex(randomblob(2))), + lower(hex(randomblob(2))), + lower(hex(randomblob(6))) ); \ No newline at end of file diff --git a/web/src/utils/resource.ts b/web/src/utils/resource.ts index 831fba4c9..1148b77ab 100644 --- a/web/src/utils/resource.ts +++ b/web/src/utils/resource.ts @@ -1,3 +1,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => { + if (resource.externalLink) { + return resource.externalLink; + } + return `${withOrigin ? window.location.origin : ""}/o/r/${resource.id}/${resource.publicId}`; };