fix: return external link directly (#1465)

* fix: return external link directly

* chore: update
pull/1475/head
boojack 2 years ago committed by GitHub
parent 5361f76b11
commit 6ff7cfddda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

@ -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 {

@ -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(
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)))
) as uuid
);

@ -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}`;
};

Loading…
Cancel
Save