Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions plugin/httpgetter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package httpgetter
import (
"mime"
"net/http"
"net/url"
"strings"
)

func getMediatype(response *http.Response) (string, error) {
Expand All @@ -13,3 +15,24 @@ func getMediatype(response *http.Response) (string, error) {
}
return mediatype, nil
}

// NormalizeURLForCache normalizes a URL for use as a cache key.
// It removes fragments (hash) and trailing slashes (except root) to ensure
// that URLs like "https://example.com/" and "https://example.com" map to the same cache entry.
func NormalizeURLForCache(urlStr string) string {
parsed, err := url.Parse(urlStr)
if err != nil {
// If parsing fails, return original URL
return urlStr
}

// Remove fragment (hash)
parsed.Fragment = ""

// Remove trailing slash from pathname (except root)
if parsed.Path != "/" && strings.HasSuffix(parsed.Path, "/") {
parsed.Path = strings.TrimSuffix(parsed.Path, "/")
}

return parsed.String()
}
2 changes: 2 additions & 0 deletions proto/api/v1/instance_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ message InstanceSetting {
int32 content_length_limit = 3;
// enable_double_click_edit enables editing on double click.
bool enable_double_click_edit = 4;
// enable_opengraph_link_previews enables OpenGraph link previews for links in memos.
bool enable_opengraph_link_previews = 5;
// reactions is the list of reactions.
repeated string reactions = 7;
}
Expand Down
34 changes: 34 additions & 0 deletions proto/api/v1/link_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";

package memos.api.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";

option go_package = "gen/api/v1";

service LinkService {
// GetLinkMetadata fetches OpenGraph metadata for a given URL.
rpc GetLinkMetadata(GetLinkMetadataRequest) returns (LinkMetadata) {
option (google.api.http) = {get: "/api/v1/links/metadata"};
option (google.api.method_signature) = "url";
}
}

// Request message for GetLinkMetadata method.
message GetLinkMetadataRequest {
// The URL to fetch metadata for.
string url = 1 [(google.api.field_behavior) = REQUIRED];
}

// LinkMetadata contains OpenGraph metadata for a link.
message LinkMetadata {
// The title of the link (from og:title or <title> tag).
string title = 1;
// The description of the link (from og:description or <meta name="description">).
string description = 2;
// The preview image URL (from og:image).
string image = 3;
}

111 changes: 111 additions & 0 deletions proto/gen/api/v1/apiv1connect/link_service.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions proto/gen/api/v1/instance_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading