mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: return external link directly (#1465)
* fix: return external link directly * chore: update
This commit is contained in:
@ -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)
|
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
|
blob := resource.Blob
|
||||||
if resource.InternalPath != "" {
|
if resource.InternalPath != "" {
|
||||||
src, err := os.Open(resource.InternalPath)
|
src, err := os.Open(resource.InternalPath)
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/usememos/memos/api"
|
"github.com/usememos/memos/api"
|
||||||
"github.com/usememos/memos/common"
|
"github.com/usememos/memos/common"
|
||||||
|
"github.com/usememos/memos/common/log"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@ -67,7 +69,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
|
|||||||
var baseValue any
|
var baseValue any
|
||||||
err := json.Unmarshal([]byte(systemSetting.Value), &baseValue)
|
err := json.Unmarshal([]byte(systemSetting.Value), &baseValue)
|
||||||
if err != nil {
|
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 {
|
if systemSetting.Name == api.SystemSettingAllowSignUpName {
|
||||||
|
@ -3,19 +3,17 @@ ALTER TABLE
|
|||||||
ADD
|
ADD
|
||||||
COLUMN public_id TEXT NOT NULL DEFAULT '';
|
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);
|
CREATE UNIQUE INDEX resource_id_public_id_unique_index ON resource (id, public_id);
|
||||||
|
|
||||||
UPDATE
|
UPDATE
|
||||||
resource
|
resource
|
||||||
SET
|
SET
|
||||||
public_id = (
|
public_id = printf (
|
||||||
SELECT
|
'%s-%s-%s-%s-%s',
|
||||||
printf(
|
lower(hex(randomblob(4))),
|
||||||
'%s-%s-%s-%s-%s',
|
lower(hex(randomblob(2))),
|
||||||
lower(hex(randomblob(4))),
|
lower(hex(randomblob(2))),
|
||||||
lower(hex(randomblob(2))),
|
lower(hex(randomblob(2))),
|
||||||
lower(hex(randomblob(2))),
|
lower(hex(randomblob(6)))
|
||||||
lower(hex(randomblob(2))),
|
|
||||||
lower(hex(randomblob(6)))
|
|
||||||
) as uuid
|
|
||||||
);
|
);
|
@ -1,3 +1,7 @@
|
|||||||
export const getResourceUrl = (resource: Resource, withOrigin = true) => {
|
export const getResourceUrl = (resource: Resource, withOrigin = true) => {
|
||||||
|
if (resource.externalLink) {
|
||||||
|
return resource.externalLink;
|
||||||
|
}
|
||||||
|
|
||||||
return `${withOrigin ? window.location.origin : ""}/o/r/${resource.id}/${resource.publicId}`;
|
return `${withOrigin ? window.location.origin : ""}/o/r/${resource.id}/${resource.publicId}`;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user