mirror of
https://github.com/usememos/memos.git
synced 2024-09-11 03:55:30 +03:00
chore: implement stringify markdown nodes endpoint (#3688)
This commit is contained in:
parent
7c9e54afbd
commit
bcb8843245
@ -238,9 +238,51 @@ paths:
|
||||
type: string
|
||||
tags:
|
||||
- MarkdownService
|
||||
/api/v1/markdown/parse:
|
||||
/api/v1/markdown/node:restore:
|
||||
post:
|
||||
summary: Parses the given markdown content and returns a list of nodes.
|
||||
summary: RestoreMarkdownNodes restores the given nodes to markdown content.
|
||||
operationId: MarkdownService_RestoreMarkdownNodes
|
||||
responses:
|
||||
"200":
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: '#/definitions/v1RestoreMarkdownNodesResponse'
|
||||
default:
|
||||
description: An unexpected error response.
|
||||
schema:
|
||||
$ref: '#/definitions/googlerpcStatus'
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/v1RestoreMarkdownNodesRequest'
|
||||
tags:
|
||||
- MarkdownService
|
||||
/api/v1/markdown/node:stringify:
|
||||
post:
|
||||
summary: StringifyMarkdownNodes stringify the given nodes to plain text content.
|
||||
operationId: MarkdownService_StringifyMarkdownNodes
|
||||
responses:
|
||||
"200":
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: '#/definitions/v1StringifyMarkdownNodesResponse'
|
||||
default:
|
||||
description: An unexpected error response.
|
||||
schema:
|
||||
$ref: '#/definitions/googlerpcStatus'
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/v1StringifyMarkdownNodesRequest'
|
||||
tags:
|
||||
- MarkdownService
|
||||
/api/v1/markdown:parse:
|
||||
post:
|
||||
summary: ParseMarkdown parses the given markdown content and returns a list of nodes.
|
||||
operationId: MarkdownService_ParseMarkdown
|
||||
responses:
|
||||
"200":
|
||||
@ -259,27 +301,6 @@ paths:
|
||||
$ref: '#/definitions/v1ParseMarkdownRequest'
|
||||
tags:
|
||||
- MarkdownService
|
||||
/api/v1/markdown:restore:
|
||||
post:
|
||||
summary: Restores the given nodes to markdown content.
|
||||
operationId: MarkdownService_RestoreMarkdown
|
||||
responses:
|
||||
"200":
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: '#/definitions/v1RestoreMarkdownResponse'
|
||||
default:
|
||||
description: An unexpected error response.
|
||||
schema:
|
||||
$ref: '#/definitions/googlerpcStatus'
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/v1RestoreMarkdownRequest'
|
||||
tags:
|
||||
- MarkdownService
|
||||
/api/v1/memos:
|
||||
get:
|
||||
summary: ListMemos lists memos with pagination and filter.
|
||||
@ -2855,7 +2876,7 @@ definitions:
|
||||
memo:
|
||||
type: string
|
||||
title: "The related memo.\r\nFormat: memos/{id}"
|
||||
v1RestoreMarkdownRequest:
|
||||
v1RestoreMarkdownNodesRequest:
|
||||
type: object
|
||||
properties:
|
||||
nodes:
|
||||
@ -2863,7 +2884,7 @@ definitions:
|
||||
items:
|
||||
type: object
|
||||
$ref: '#/definitions/v1Node'
|
||||
v1RestoreMarkdownResponse:
|
||||
v1RestoreMarkdownNodesResponse:
|
||||
type: object
|
||||
properties:
|
||||
markdown:
|
||||
@ -2909,6 +2930,19 @@ definitions:
|
||||
properties:
|
||||
content:
|
||||
type: string
|
||||
v1StringifyMarkdownNodesRequest:
|
||||
type: object
|
||||
properties:
|
||||
nodes:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
$ref: '#/definitions/v1Node'
|
||||
v1StringifyMarkdownNodesResponse:
|
||||
type: object
|
||||
properties:
|
||||
plainText:
|
||||
type: string
|
||||
v1SubscriptNode:
|
||||
type: object
|
||||
properties:
|
||||
|
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/viper v1.19.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/usememos/gomark v0.0.0-20240713015837-e5b687d3d637
|
||||
github.com/usememos/gomark v0.0.0-20240714122951-35ed01b21822
|
||||
golang.org/x/crypto v0.25.0
|
||||
golang.org/x/mod v0.19.0
|
||||
golang.org/x/net v0.27.0
|
||||
|
4
go.sum
4
go.sum
@ -441,8 +441,8 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/usememos/gomark v0.0.0-20240713015837-e5b687d3d637 h1:DTSf/z7oXyAJXk9bYaTHnRiLlHynWJ/ate9VKJn2awc=
|
||||
github.com/usememos/gomark v0.0.0-20240713015837-e5b687d3d637/go.mod h1:7CZRoYFQyyljzplOTeyODFR26O+wr0BbnpTWVLGfKJA=
|
||||
github.com/usememos/gomark v0.0.0-20240714122951-35ed01b21822 h1:4DQs0DJGaXLq+1eP6QfMkvcunyTVJ5OR7LK1cOm2imE=
|
||||
github.com/usememos/gomark v0.0.0-20240714122951-35ed01b21822/go.mod h1:7CZRoYFQyyljzplOTeyODFR26O+wr0BbnpTWVLGfKJA=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
|
@ -7,17 +7,24 @@ import "google/api/annotations.proto";
|
||||
option go_package = "gen/api/v1";
|
||||
|
||||
service MarkdownService {
|
||||
// Parses the given markdown content and returns a list of nodes.
|
||||
// ParseMarkdown parses the given markdown content and returns a list of nodes.
|
||||
rpc ParseMarkdown(ParseMarkdownRequest) returns (ParseMarkdownResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v1/markdown/parse"
|
||||
post: "/api/v1/markdown:parse"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Restores the given nodes to markdown content.
|
||||
rpc RestoreMarkdown(RestoreMarkdownRequest) returns (RestoreMarkdownResponse) {
|
||||
// RestoreMarkdownNodes restores the given nodes to markdown content.
|
||||
rpc RestoreMarkdownNodes(RestoreMarkdownNodesRequest) returns (RestoreMarkdownNodesResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v1/markdown:restore"
|
||||
post: "/api/v1/markdown/node:restore"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// StringifyMarkdownNodes stringify the given nodes to plain text content.
|
||||
rpc StringifyMarkdownNodes(StringifyMarkdownNodesRequest) returns (StringifyMarkdownNodesResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v1/markdown/node:stringify"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
@ -35,14 +42,22 @@ message ParseMarkdownResponse {
|
||||
repeated Node nodes = 1;
|
||||
}
|
||||
|
||||
message RestoreMarkdownRequest {
|
||||
message RestoreMarkdownNodesRequest {
|
||||
repeated Node nodes = 1;
|
||||
}
|
||||
|
||||
message RestoreMarkdownResponse {
|
||||
message RestoreMarkdownNodesResponse {
|
||||
string markdown = 1;
|
||||
}
|
||||
|
||||
message StringifyMarkdownNodesRequest {
|
||||
repeated Node nodes = 1;
|
||||
}
|
||||
|
||||
message StringifyMarkdownNodesResponse {
|
||||
string plain_text = 1;
|
||||
}
|
||||
|
||||
message GetLinkMetadataRequest {
|
||||
string link = 1;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -57,28 +57,54 @@ func local_request_MarkdownService_ParseMarkdown_0(ctx context.Context, marshale
|
||||
|
||||
}
|
||||
|
||||
func request_MarkdownService_RestoreMarkdown_0(ctx context.Context, marshaler runtime.Marshaler, client MarkdownServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RestoreMarkdownRequest
|
||||
func request_MarkdownService_RestoreMarkdownNodes_0(ctx context.Context, marshaler runtime.Marshaler, client MarkdownServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RestoreMarkdownNodesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.RestoreMarkdown(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
msg, err := client.RestoreMarkdownNodes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_MarkdownService_RestoreMarkdown_0(ctx context.Context, marshaler runtime.Marshaler, server MarkdownServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RestoreMarkdownRequest
|
||||
func local_request_MarkdownService_RestoreMarkdownNodes_0(ctx context.Context, marshaler runtime.Marshaler, server MarkdownServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RestoreMarkdownNodesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.RestoreMarkdown(ctx, &protoReq)
|
||||
msg, err := server.RestoreMarkdownNodes(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_MarkdownService_StringifyMarkdownNodes_0(ctx context.Context, marshaler runtime.Marshaler, client MarkdownServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq StringifyMarkdownNodesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.StringifyMarkdownNodes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_MarkdownService_StringifyMarkdownNodes_0(ctx context.Context, marshaler runtime.Marshaler, server MarkdownServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq StringifyMarkdownNodesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.StringifyMarkdownNodes(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
@ -133,7 +159,7 @@ func RegisterMarkdownServiceHandlerServer(ctx context.Context, mux *runtime.Serv
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MarkdownService/ParseMarkdown", runtime.WithHTTPPathPattern("/api/v1/markdown/parse"))
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MarkdownService/ParseMarkdown", runtime.WithHTTPPathPattern("/api/v1/markdown:parse"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
@ -150,7 +176,7 @@ func RegisterMarkdownServiceHandlerServer(ctx context.Context, mux *runtime.Serv
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_MarkdownService_RestoreMarkdown_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
mux.Handle("POST", pattern_MarkdownService_RestoreMarkdownNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
@ -158,12 +184,12 @@ func RegisterMarkdownServiceHandlerServer(ctx context.Context, mux *runtime.Serv
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MarkdownService/RestoreMarkdown", runtime.WithHTTPPathPattern("/api/v1/markdown:restore"))
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MarkdownService/RestoreMarkdownNodes", runtime.WithHTTPPathPattern("/api/v1/markdown/node:restore"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_MarkdownService_RestoreMarkdown_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||
resp, md, err := local_request_MarkdownService_RestoreMarkdownNodes_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
@ -171,7 +197,32 @@ func RegisterMarkdownServiceHandlerServer(ctx context.Context, mux *runtime.Serv
|
||||
return
|
||||
}
|
||||
|
||||
forward_MarkdownService_RestoreMarkdown_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
forward_MarkdownService_RestoreMarkdownNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_MarkdownService_StringifyMarkdownNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MarkdownService/StringifyMarkdownNodes", runtime.WithHTTPPathPattern("/api/v1/markdown/node:stringify"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_MarkdownService_StringifyMarkdownNodes_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_MarkdownService_StringifyMarkdownNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
@ -247,7 +298,7 @@ func RegisterMarkdownServiceHandlerClient(ctx context.Context, mux *runtime.Serv
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MarkdownService/ParseMarkdown", runtime.WithHTTPPathPattern("/api/v1/markdown/parse"))
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MarkdownService/ParseMarkdown", runtime.WithHTTPPathPattern("/api/v1/markdown:parse"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
@ -263,25 +314,47 @@ func RegisterMarkdownServiceHandlerClient(ctx context.Context, mux *runtime.Serv
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_MarkdownService_RestoreMarkdown_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
mux.Handle("POST", pattern_MarkdownService_RestoreMarkdownNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MarkdownService/RestoreMarkdown", runtime.WithHTTPPathPattern("/api/v1/markdown:restore"))
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MarkdownService/RestoreMarkdownNodes", runtime.WithHTTPPathPattern("/api/v1/markdown/node:restore"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_MarkdownService_RestoreMarkdown_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
resp, md, err := request_MarkdownService_RestoreMarkdownNodes_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_MarkdownService_RestoreMarkdown_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
forward_MarkdownService_RestoreMarkdownNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_MarkdownService_StringifyMarkdownNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MarkdownService/StringifyMarkdownNodes", runtime.WithHTTPPathPattern("/api/v1/markdown/node:stringify"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_MarkdownService_StringifyMarkdownNodes_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_MarkdownService_StringifyMarkdownNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
@ -311,9 +384,11 @@ func RegisterMarkdownServiceHandlerClient(ctx context.Context, mux *runtime.Serv
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_MarkdownService_ParseMarkdown_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "markdown", "parse"}, ""))
|
||||
pattern_MarkdownService_ParseMarkdown_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "markdown"}, "parse"))
|
||||
|
||||
pattern_MarkdownService_RestoreMarkdown_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "markdown"}, "restore"))
|
||||
pattern_MarkdownService_RestoreMarkdownNodes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "markdown", "node"}, "restore"))
|
||||
|
||||
pattern_MarkdownService_StringifyMarkdownNodes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "markdown", "node"}, "stringify"))
|
||||
|
||||
pattern_MarkdownService_GetLinkMetadata_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "markdown", "link"}, "metadata"))
|
||||
)
|
||||
@ -321,7 +396,9 @@ var (
|
||||
var (
|
||||
forward_MarkdownService_ParseMarkdown_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_MarkdownService_RestoreMarkdown_0 = runtime.ForwardResponseMessage
|
||||
forward_MarkdownService_RestoreMarkdownNodes_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_MarkdownService_StringifyMarkdownNodes_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_MarkdownService_GetLinkMetadata_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
@ -19,19 +19,22 @@ import (
|
||||
const _ = grpc.SupportPackageIsVersion8
|
||||
|
||||
const (
|
||||
MarkdownService_ParseMarkdown_FullMethodName = "/memos.api.v1.MarkdownService/ParseMarkdown"
|
||||
MarkdownService_RestoreMarkdown_FullMethodName = "/memos.api.v1.MarkdownService/RestoreMarkdown"
|
||||
MarkdownService_GetLinkMetadata_FullMethodName = "/memos.api.v1.MarkdownService/GetLinkMetadata"
|
||||
MarkdownService_ParseMarkdown_FullMethodName = "/memos.api.v1.MarkdownService/ParseMarkdown"
|
||||
MarkdownService_RestoreMarkdownNodes_FullMethodName = "/memos.api.v1.MarkdownService/RestoreMarkdownNodes"
|
||||
MarkdownService_StringifyMarkdownNodes_FullMethodName = "/memos.api.v1.MarkdownService/StringifyMarkdownNodes"
|
||||
MarkdownService_GetLinkMetadata_FullMethodName = "/memos.api.v1.MarkdownService/GetLinkMetadata"
|
||||
)
|
||||
|
||||
// MarkdownServiceClient is the client API for MarkdownService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type MarkdownServiceClient interface {
|
||||
// Parses the given markdown content and returns a list of nodes.
|
||||
// ParseMarkdown parses the given markdown content and returns a list of nodes.
|
||||
ParseMarkdown(ctx context.Context, in *ParseMarkdownRequest, opts ...grpc.CallOption) (*ParseMarkdownResponse, error)
|
||||
// Restores the given nodes to markdown content.
|
||||
RestoreMarkdown(ctx context.Context, in *RestoreMarkdownRequest, opts ...grpc.CallOption) (*RestoreMarkdownResponse, error)
|
||||
// RestoreMarkdownNodes restores the given nodes to markdown content.
|
||||
RestoreMarkdownNodes(ctx context.Context, in *RestoreMarkdownNodesRequest, opts ...grpc.CallOption) (*RestoreMarkdownNodesResponse, error)
|
||||
// StringifyMarkdownNodes stringify the given nodes to plain text content.
|
||||
StringifyMarkdownNodes(ctx context.Context, in *StringifyMarkdownNodesRequest, opts ...grpc.CallOption) (*StringifyMarkdownNodesResponse, error)
|
||||
// GetLinkMetadata returns metadata for a given link.
|
||||
GetLinkMetadata(ctx context.Context, in *GetLinkMetadataRequest, opts ...grpc.CallOption) (*LinkMetadata, error)
|
||||
}
|
||||
@ -54,10 +57,20 @@ func (c *markdownServiceClient) ParseMarkdown(ctx context.Context, in *ParseMark
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *markdownServiceClient) RestoreMarkdown(ctx context.Context, in *RestoreMarkdownRequest, opts ...grpc.CallOption) (*RestoreMarkdownResponse, error) {
|
||||
func (c *markdownServiceClient) RestoreMarkdownNodes(ctx context.Context, in *RestoreMarkdownNodesRequest, opts ...grpc.CallOption) (*RestoreMarkdownNodesResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(RestoreMarkdownResponse)
|
||||
err := c.cc.Invoke(ctx, MarkdownService_RestoreMarkdown_FullMethodName, in, out, cOpts...)
|
||||
out := new(RestoreMarkdownNodesResponse)
|
||||
err := c.cc.Invoke(ctx, MarkdownService_RestoreMarkdownNodes_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *markdownServiceClient) StringifyMarkdownNodes(ctx context.Context, in *StringifyMarkdownNodesRequest, opts ...grpc.CallOption) (*StringifyMarkdownNodesResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(StringifyMarkdownNodesResponse)
|
||||
err := c.cc.Invoke(ctx, MarkdownService_StringifyMarkdownNodes_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -78,10 +91,12 @@ func (c *markdownServiceClient) GetLinkMetadata(ctx context.Context, in *GetLink
|
||||
// All implementations must embed UnimplementedMarkdownServiceServer
|
||||
// for forward compatibility
|
||||
type MarkdownServiceServer interface {
|
||||
// Parses the given markdown content and returns a list of nodes.
|
||||
// ParseMarkdown parses the given markdown content and returns a list of nodes.
|
||||
ParseMarkdown(context.Context, *ParseMarkdownRequest) (*ParseMarkdownResponse, error)
|
||||
// Restores the given nodes to markdown content.
|
||||
RestoreMarkdown(context.Context, *RestoreMarkdownRequest) (*RestoreMarkdownResponse, error)
|
||||
// RestoreMarkdownNodes restores the given nodes to markdown content.
|
||||
RestoreMarkdownNodes(context.Context, *RestoreMarkdownNodesRequest) (*RestoreMarkdownNodesResponse, error)
|
||||
// StringifyMarkdownNodes stringify the given nodes to plain text content.
|
||||
StringifyMarkdownNodes(context.Context, *StringifyMarkdownNodesRequest) (*StringifyMarkdownNodesResponse, error)
|
||||
// GetLinkMetadata returns metadata for a given link.
|
||||
GetLinkMetadata(context.Context, *GetLinkMetadataRequest) (*LinkMetadata, error)
|
||||
mustEmbedUnimplementedMarkdownServiceServer()
|
||||
@ -94,8 +109,11 @@ type UnimplementedMarkdownServiceServer struct {
|
||||
func (UnimplementedMarkdownServiceServer) ParseMarkdown(context.Context, *ParseMarkdownRequest) (*ParseMarkdownResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ParseMarkdown not implemented")
|
||||
}
|
||||
func (UnimplementedMarkdownServiceServer) RestoreMarkdown(context.Context, *RestoreMarkdownRequest) (*RestoreMarkdownResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RestoreMarkdown not implemented")
|
||||
func (UnimplementedMarkdownServiceServer) RestoreMarkdownNodes(context.Context, *RestoreMarkdownNodesRequest) (*RestoreMarkdownNodesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RestoreMarkdownNodes not implemented")
|
||||
}
|
||||
func (UnimplementedMarkdownServiceServer) StringifyMarkdownNodes(context.Context, *StringifyMarkdownNodesRequest) (*StringifyMarkdownNodesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method StringifyMarkdownNodes not implemented")
|
||||
}
|
||||
func (UnimplementedMarkdownServiceServer) GetLinkMetadata(context.Context, *GetLinkMetadataRequest) (*LinkMetadata, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetLinkMetadata not implemented")
|
||||
@ -131,20 +149,38 @@ func _MarkdownService_ParseMarkdown_Handler(srv interface{}, ctx context.Context
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _MarkdownService_RestoreMarkdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RestoreMarkdownRequest)
|
||||
func _MarkdownService_RestoreMarkdownNodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RestoreMarkdownNodesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(MarkdownServiceServer).RestoreMarkdown(ctx, in)
|
||||
return srv.(MarkdownServiceServer).RestoreMarkdownNodes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: MarkdownService_RestoreMarkdown_FullMethodName,
|
||||
FullMethod: MarkdownService_RestoreMarkdownNodes_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MarkdownServiceServer).RestoreMarkdown(ctx, req.(*RestoreMarkdownRequest))
|
||||
return srv.(MarkdownServiceServer).RestoreMarkdownNodes(ctx, req.(*RestoreMarkdownNodesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _MarkdownService_StringifyMarkdownNodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(StringifyMarkdownNodesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(MarkdownServiceServer).StringifyMarkdownNodes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: MarkdownService_StringifyMarkdownNodes_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MarkdownServiceServer).StringifyMarkdownNodes(ctx, req.(*StringifyMarkdownNodesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
@ -179,8 +215,12 @@ var MarkdownService_ServiceDesc = grpc.ServiceDesc{
|
||||
Handler: _MarkdownService_ParseMarkdown_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "RestoreMarkdown",
|
||||
Handler: _MarkdownService_RestoreMarkdown_Handler,
|
||||
MethodName: "RestoreMarkdownNodes",
|
||||
Handler: _MarkdownService_RestoreMarkdownNodes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "StringifyMarkdownNodes",
|
||||
Handler: _MarkdownService_StringifyMarkdownNodes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetLinkMetadata",
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/usememos/gomark/ast"
|
||||
"github.com/usememos/gomark/parser"
|
||||
"github.com/usememos/gomark/parser/tokenizer"
|
||||
"github.com/usememos/gomark/renderer"
|
||||
"github.com/usememos/gomark/restore"
|
||||
|
||||
"github.com/usememos/memos/plugin/httpgetter"
|
||||
@ -25,13 +26,21 @@ func (*APIV1Service) ParseMarkdown(_ context.Context, request *v1pb.ParseMarkdow
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (*APIV1Service) RestoreMarkdown(_ context.Context, request *v1pb.RestoreMarkdownRequest) (*v1pb.RestoreMarkdownResponse, error) {
|
||||
func (*APIV1Service) RestoreMarkdownNodes(_ context.Context, request *v1pb.RestoreMarkdownNodesRequest) (*v1pb.RestoreMarkdownNodesResponse, error) {
|
||||
markdown := restore.Restore(convertToASTNodes(request.Nodes))
|
||||
return &v1pb.RestoreMarkdownResponse{
|
||||
return &v1pb.RestoreMarkdownNodesResponse{
|
||||
Markdown: markdown,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (*APIV1Service) StringifyMarkdownNodes(_ context.Context, request *v1pb.StringifyMarkdownNodesRequest) (*v1pb.StringifyMarkdownNodesResponse, error) {
|
||||
stringRenderer := renderer.NewStringRenderer()
|
||||
plainText := stringRenderer.Render(convertToASTNodes(request.Nodes))
|
||||
return &v1pb.StringifyMarkdownNodesResponse{
|
||||
PlainText: plainText,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (*APIV1Service) GetLinkMetadata(_ context.Context, request *v1pb.GetLinkMetadataRequest) (*v1pb.LinkMetadata, error) {
|
||||
htmlMeta, err := httpgetter.GetHTMLMeta(request.Link)
|
||||
if err != nil {
|
||||
|
@ -37,7 +37,7 @@ const TaskList: React.FC<Props> = ({ index, indent, complete, children }: Props)
|
||||
}
|
||||
|
||||
(node.taskListNode as TaskListNode)!.complete = on;
|
||||
const { markdown } = await markdownServiceClient.restoreMarkdown({ nodes: context.nodes });
|
||||
const { markdown } = await markdownServiceClient.restoreMarkdownNodes({ nodes: context.nodes });
|
||||
await memoStore.updateMemo(
|
||||
{
|
||||
name: context.memoName,
|
||||
|
Loading…
Reference in New Issue
Block a user