Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
335a0312
Commit
335a0312
authored
Mar 16, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: tweak link styles
parent
9c1e2f81
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
201 deletions
+166
-201
link_service.proto
proto/api/v2/link_service.proto
+8
-8
README.md
proto/gen/api/v2/README.md
+1
-1
link_service.pb.go
proto/gen/api/v2/link_service.pb.go
+96
-95
link_service.pb.gw.go
proto/gen/api/v2/link_service.pb.gw.go
+3
-3
apidocs.swagger.yaml
server/route/api/v2/apidocs.swagger.yaml
+20
-20
link_service.go
server/route/api/v2/link_service.go
+1
-1
Link.tsx
web/src/components/MemoContent/Link.tsx
+37
-73
No files found.
proto/api/v2/link_service.proto
View file @
335a0312
...
@@ -8,20 +8,20 @@ option go_package = "gen/api/v2";
...
@@ -8,20 +8,20 @@ option go_package = "gen/api/v2";
service
LinkService
{
service
LinkService
{
rpc
GetLinkMetadata
(
GetLinkMetadataRequest
)
returns
(
GetLinkMetadataResponse
)
{
rpc
GetLinkMetadata
(
GetLinkMetadataRequest
)
returns
(
GetLinkMetadataResponse
)
{
option
(
google.api.http
)
=
{
get
:
"/api/v2/metadata"
};
option
(
google.api.http
)
=
{
get
:
"/api/v2/
link_
metadata"
};
}
}
}
}
message
LinkMetadata
{
string
title
=
1
;
string
description
=
2
;
string
image
=
3
;
}
message
GetLinkMetadataRequest
{
message
GetLinkMetadataRequest
{
string
link
=
1
;
string
link
=
1
;
}
}
message
GetLinkMetadataResponse
{
message
GetLinkMetadataResponse
{
LinkMetadata
metadata
=
1
;
LinkMetadata
link_metadata
=
1
;
}
message
LinkMetadata
{
string
title
=
1
;
string
description
=
2
;
string
image
=
3
;
}
}
proto/gen/api/v2/README.md
View file @
335a0312
...
@@ -1135,7 +1135,7 @@ Used internally for obfuscating the page token.
...
@@ -1135,7 +1135,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ----- | ---- | ----- | ----------- |
| metadata |
[
LinkMetadata
](
#memos-api-v2-LinkMetadata
)
| | |
|
link_
metadata |
[
LinkMetadata
](
#memos-api-v2-LinkMetadata
)
| | |
...
...
proto/gen/api/v2/link_service.pb.go
View file @
335a0312
This diff is collapsed.
Click to expand it.
proto/gen/api/v2/link_service.pb.gw.go
View file @
335a0312
...
@@ -81,7 +81,7 @@ func RegisterLinkServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
...
@@ -81,7 +81,7 @@ func RegisterLinkServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
inboundMarshaler
,
outboundMarshaler
:=
runtime
.
MarshalerForRequest
(
mux
,
req
)
inboundMarshaler
,
outboundMarshaler
:=
runtime
.
MarshalerForRequest
(
mux
,
req
)
var
err
error
var
err
error
var
annotatedContext
context
.
Context
var
annotatedContext
context
.
Context
annotatedContext
,
err
=
runtime
.
AnnotateIncomingContext
(
ctx
,
mux
,
req
,
"/memos.api.v2.LinkService/GetLinkMetadata"
,
runtime
.
WithHTTPPathPattern
(
"/api/v2/metadata"
))
annotatedContext
,
err
=
runtime
.
AnnotateIncomingContext
(
ctx
,
mux
,
req
,
"/memos.api.v2.LinkService/GetLinkMetadata"
,
runtime
.
WithHTTPPathPattern
(
"/api/v2/
link_
metadata"
))
if
err
!=
nil
{
if
err
!=
nil
{
runtime
.
HTTPError
(
ctx
,
mux
,
outboundMarshaler
,
w
,
req
,
err
)
runtime
.
HTTPError
(
ctx
,
mux
,
outboundMarshaler
,
w
,
req
,
err
)
return
return
...
@@ -145,7 +145,7 @@ func RegisterLinkServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
...
@@ -145,7 +145,7 @@ func RegisterLinkServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
inboundMarshaler
,
outboundMarshaler
:=
runtime
.
MarshalerForRequest
(
mux
,
req
)
inboundMarshaler
,
outboundMarshaler
:=
runtime
.
MarshalerForRequest
(
mux
,
req
)
var
err
error
var
err
error
var
annotatedContext
context
.
Context
var
annotatedContext
context
.
Context
annotatedContext
,
err
=
runtime
.
AnnotateContext
(
ctx
,
mux
,
req
,
"/memos.api.v2.LinkService/GetLinkMetadata"
,
runtime
.
WithHTTPPathPattern
(
"/api/v2/metadata"
))
annotatedContext
,
err
=
runtime
.
AnnotateContext
(
ctx
,
mux
,
req
,
"/memos.api.v2.LinkService/GetLinkMetadata"
,
runtime
.
WithHTTPPathPattern
(
"/api/v2/
link_
metadata"
))
if
err
!=
nil
{
if
err
!=
nil
{
runtime
.
HTTPError
(
ctx
,
mux
,
outboundMarshaler
,
w
,
req
,
err
)
runtime
.
HTTPError
(
ctx
,
mux
,
outboundMarshaler
,
w
,
req
,
err
)
return
return
...
@@ -165,7 +165,7 @@ func RegisterLinkServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
...
@@ -165,7 +165,7 @@ func RegisterLinkServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
}
}
var
(
var
(
pattern_LinkService_GetLinkMetadata_0
=
runtime
.
MustPattern
(
runtime
.
NewPattern
(
1
,
[]
int
{
2
,
0
,
2
,
1
,
2
,
2
},
[]
string
{
"api"
,
"v2"
,
"metadata"
},
""
))
pattern_LinkService_GetLinkMetadata_0
=
runtime
.
MustPattern
(
runtime
.
NewPattern
(
1
,
[]
int
{
2
,
0
,
2
,
1
,
2
,
2
},
[]
string
{
"api"
,
"v2"
,
"
link_
metadata"
},
""
))
)
)
var
(
var
(
...
...
server/route/api/v2/apidocs.swagger.yaml
View file @
335a0312
...
@@ -151,6 +151,25 @@ paths:
...
@@ -151,6 +151,25 @@ paths:
type
:
string
type
:
string
tags
:
tags
:
-
InboxService
-
InboxService
/api/v2/link_metadata
:
get
:
operationId
:
LinkService_GetLinkMetadata
responses
:
"
200"
:
description
:
A successful response.
schema
:
$ref
:
'
#/definitions/v2GetLinkMetadataResponse'
default
:
description
:
An unexpected error response.
schema
:
$ref
:
'
#/definitions/googlerpcStatus'
parameters
:
-
name
:
link
in
:
query
required
:
false
type
:
string
tags
:
-
LinkService
/api/v2/memos
:
/api/v2/memos
:
get
:
get
:
summary
:
ListMemos lists memos with pagination and filter.
summary
:
ListMemos lists memos with pagination and filter.
...
@@ -650,25 +669,6 @@ paths:
...
@@ -650,25 +669,6 @@ paths:
type
:
string
type
:
string
tags
:
tags
:
-
MemoService
-
MemoService
/api/v2/metadata
:
get
:
operationId
:
LinkService_GetLinkMetadata
responses
:
"
200"
:
description
:
A successful response.
schema
:
$ref
:
'
#/definitions/v2GetLinkMetadataResponse'
default
:
description
:
An unexpected error response.
schema
:
$ref
:
'
#/definitions/googlerpcStatus'
parameters
:
-
name
:
link
in
:
query
required
:
false
type
:
string
tags
:
-
LinkService
/api/v2/resources
:
/api/v2/resources
:
get
:
get
:
summary
:
ListResources lists all resources.
summary
:
ListResources lists all resources.
...
@@ -1813,7 +1813,7 @@ definitions:
...
@@ -1813,7 +1813,7 @@ definitions:
v2GetLinkMetadataResponse
:
v2GetLinkMetadataResponse
:
type
:
object
type
:
object
properties
:
properties
:
m
etadata
:
linkM
etadata
:
$ref
:
'
#/definitions/v2LinkMetadata'
$ref
:
'
#/definitions/v2LinkMetadata'
v2GetMemoByNameResponse
:
v2GetMemoByNameResponse
:
type
:
object
type
:
object
...
...
server/route/api/v2/link_service.go
View file @
335a0312
...
@@ -14,7 +14,7 @@ func (*APIV2Service) GetLinkMetadata(_ context.Context, request *apiv2pb.GetLink
...
@@ -14,7 +14,7 @@ func (*APIV2Service) GetLinkMetadata(_ context.Context, request *apiv2pb.GetLink
}
}
return
&
apiv2pb
.
GetLinkMetadataResponse
{
return
&
apiv2pb
.
GetLinkMetadataResponse
{
Metadata
:
&
apiv2pb
.
LinkMetadata
{
Link
Metadata
:
&
apiv2pb
.
LinkMetadata
{
Title
:
htmlMeta
.
Title
,
Title
:
htmlMeta
.
Title
,
Description
:
htmlMeta
.
Description
,
Description
:
htmlMeta
.
Description
,
Image
:
htmlMeta
.
Image
,
Image
:
htmlMeta
.
Image
,
...
...
web/src/components/MemoContent/Link.tsx
View file @
335a0312
import
{
Tooltip
,
Card
,
AspectRatio
,
Box
}
from
"@mui/joy"
;
import
{
Link
as
MLink
,
Tooltip
}
from
"@mui/joy"
;
import
{
Link
as
MLink
}
from
"@mui/joy"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
linkServiceClient
}
from
"@/grpcweb"
;
import
{
linkServiceClient
}
from
"@/grpcweb"
;
import
useResponsiveWidth
from
"@/hooks/useResponsiveWidth"
;
import
{
LinkMetadata
}
from
"@/types/proto/api/v2/link_service"
;
import
{
LinkMetadata
}
from
"@/types/proto/api/v2/link_service"
;
interface
Props
{
interface
Props
{
...
@@ -10,83 +8,49 @@ interface Props {
...
@@ -10,83 +8,49 @@ interface Props {
text
?:
string
;
text
?:
string
;
}
}
const
getFaviconWithGoogleS2
=
(
url
:
string
)
=>
{
try
{
const
urlObject
=
new
URL
(
url
);
return
`https://www.google.com/s2/favicons?sz=128&domain=
${
urlObject
.
hostname
}
`
;
}
catch
(
error
)
{
return
undefined
;
}
};
const
Link
:
React
.
FC
<
Props
>
=
({
text
,
url
}:
Props
)
=>
{
const
Link
:
React
.
FC
<
Props
>
=
({
text
,
url
}:
Props
)
=>
{
const
[
linkMetadata
,
setLinkMetadata
]
=
useState
<
LinkMetadata
|
undefined
>
();
const
[
linkMetadata
,
setLinkMetadata
]
=
useState
<
LinkMetadata
|
undefined
>
();
const
{
md
}
=
useResponsiveWidth
();
const
fetchUrlMetadata
=
async
()
=>
{
useEffect
(()
=>
{
(
async
()
=>
{
try
{
try
{
const
response
=
await
linkServiceClient
.
getLinkMetadata
({
link
:
url
},
{});
const
{
linkMetadata
}
=
await
linkServiceClient
.
getLinkMetadata
({
link
:
url
},
{});
setLinkMetadata
(
response
.
m
etadata
);
setLinkMetadata
(
linkM
etadata
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
"Error fetching URL metadata:"
,
error
);
console
.
error
(
"Error fetching URL metadata:"
,
error
);
return
null
;
}
}
};
})();
useEffect
(()
=>
{
fetchUrlMetadata
();
},
[
url
]);
},
[
url
]);
return
(
return
linkMetadata
?
(
<>
{
md
?
(
<
div
>
<
Tooltip
<
Tooltip
placement=
"top-end"
variant=
"outlined"
variant=
"solid"
sx=
{
{}
}
title=
{
title=
{
<
Box
<
div
className=
"w-full max-w-64 sm:max-w-96 p-1 flex flex-col"
>
sx=
{
{
<
a
href=
{
url
}
target=
"_blank"
rel=
"noopener noreferrer"
className=
"group w-full flex flex-row justify-start items-center gap-1"
>
display
:
"flex"
,
<
img
className=
"w-5 h-5 pointer-events-none"
src=
{
getFaviconWithGoogleS2
(
url
)
}
alt=
{
linkMetadata
?.
title
}
/>
flexDirection
:
"row"
,
<
h3
className=
"text-base truncate dark:opacity-90 group-hover:opacity-80"
>
{
linkMetadata
?.
title
}
</
h3
>
maxWidth
:
450
,
maxHeight
:
300
,
}
}
>
{
linkMetadata
?.
image
?
(
<
a
href=
{
url
}
target=
"_blank"
rel=
"noopener noreferrer"
className=
"flex w-full"
>
<
Card
variant=
"outlined"
orientation=
"vertical"
sx=
{
{
width
:
"100%"
}
}
>
<
AspectRatio
ratio=
{
"21/9"
}
objectFit=
"cover"
variant=
"plain"
>
<
img
src=
{
linkMetadata
?.
image
}
alt=
{
linkMetadata
?.
title
}
className=
"pointer-events-none"
/>
</
AspectRatio
>
<
div
className=
"flex-1 overflow-auto w-full"
>
<
div
className=
"flex flex-col justify-between "
>
<
div
>
<
h3
className=
"text-2xl font-semibold tracking-tight truncate"
>
{
linkMetadata
?.
title
}
</
h3
>
{
linkMetadata
?.
description
&&
<
p
className=
"text-sm truncate"
>
{
linkMetadata
?.
description
}
</
p
>
}
</
div
>
</
div
>
</
div
>
</
Card
>
</
a
>
</
a
>
)
:
(
{
linkMetadata
.
description
&&
(
<
Card
variant=
"soft"
orientation=
"vertical"
sx=
{
{
width
:
"100%"
}
}
>
<
p
className=
"mt-1 w-full text-sm leading-snug opacity-80 line-clamp-2"
>
{
linkMetadata
.
description
}
</
p
>
<
div
className=
"flex-1 overflow-auto w-full"
>
<
div
className=
"flex flex-col justify-between "
>
<
div
>
<
h3
className=
"text-2xl font-semibold tracking-tight"
>
{
linkMetadata
?.
title
}
</
h3
>
<
p
className=
"text-sm text-black/50 dark:text-white/50"
>
No Preview
</
p
>
</
div
>
</
div
>
</
div
>
</
Card
>
)
}
)
}
</
Box
>
</
div
>
}
}
arrow
>
>
<
MLink
href=
{
url
}
underline=
"none"
sx=
{
{
fontWeight
:
"lg"
}
}
>
<
MLink
href=
{
url
}
>
{
url
||
text
}
</
MLink
>
{
url
||
text
}
</
MLink
>
</
Tooltip
>
</
Tooltip
>
</
div
>
)
:
(
)
:
(
<
MLink
href=
{
url
}
underline=
"none"
sx=
{
{
fontWeight
:
"lg"
}
}
>
<
MLink
href=
{
url
}
>
{
url
||
text
}
</
MLink
>
{
url
||
text
}
</
MLink
>
)
}
</>
);
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment