DownloadAttachment
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Arnas Udovic 2023-06-27 16:57:39 +03:00
parent 9affd9cf44
commit 0c5412c069
5 changed files with 302 additions and 53 deletions

View file

@ -30,7 +30,11 @@ func (fileContent *FileContent) FormatContent() string {
for i, match := range re.FindAllSubmatch(data, -1) { for i, match := range re.FindAllSubmatch(data, -1) {
if "!" == string(match[0][0:1]) { if "!" == string(match[0][0:1]) {
link := fmt.Sprintf("=> %s %s\n", match[2], match[1]) uPath := string(match[2][:])
if strings.HasPrefix(uPath, "__a") {
uPath = "/" + uPath
}
link := fmt.Sprintf("=> %s %s\n", uPath, match[1])
data = bytes.Replace(data, match[0], []byte(link), 1) data = bytes.Replace(data, match[0], []byte(link), 1)
} else { } else {
replaceWithIndex := append(match[1], fmt.Sprintf("[%d]", i+1)...) replaceWithIndex := append(match[1], fmt.Sprintf("[%d]", i+1)...)

62
main.go
View file

@ -5,6 +5,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
"io"
"log" "log"
"regexp" "regexp"
"strings" "strings"
@ -26,6 +27,10 @@ var (
key = "WgiPGpt5wM6SVEWo5iqI" key = "WgiPGpt5wM6SVEWo5iqI"
) )
const DefaultLang = "sgs"
var SupportedLang = []string{"en", "sgs", "lt", "prg", "eo"}
func init() { func init() {
flag.StringVar(&hostname, "hostname", "", "capsule hostname") flag.StringVar(&hostname, "hostname", "", "capsule hostname")
flag.StringVar(&port, "port", "1965", "capsule port") flag.StringVar(&port, "port", "1965", "capsule port")
@ -109,6 +114,8 @@ func process(_ context.Context, w gemini.ResponseWriter, r *gemini.Request) {
lang := regexp.MustCompile(`^/(sgs|en)`).FindString(r.URL.Path) lang := regexp.MustCompile(`^/(sgs|en)`).FindString(r.URL.Path)
if lang != "" { if lang != "" {
lang = lang[1:] lang = lang[1:]
} else {
lang = DefaultLang
} }
conn, err := grpc.Dial(fileSrvHost+":"+fileSrvPort, grpc.WithTransportCredentials(insecure.NewCredentials())) conn, err := grpc.Dial(fileSrvHost+":"+fileSrvPort, grpc.WithTransportCredentials(insecure.NewCredentials()))
@ -120,35 +127,68 @@ func process(_ context.Context, w gemini.ResponseWriter, r *gemini.Request) {
defer conn.Close() defer conn.Close()
client := NewTreeManagerClient(conn) client := NewTreeManagerClient(conn)
langs := strings.Join(SupportedLang, "|")
switch { switch {
case "/" == r.URL.Path: case "/" == r.URL.Path:
w.WriteHeader(gemini.StatusPermanentRedirect, "/sgs") w.WriteHeader(gemini.StatusPermanentRedirect, "/"+DefaultLang)
case regexp.MustCompile(`^/(sgs|en)/?$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/?$`).MatchString(r.URL.Path):
renderIndex(lang, w, client) renderIndex(lang, w, client)
case regexp.MustCompile(`^/(sgs|en)/atom.xml$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/atom.xml$`).MatchString(r.URL.Path):
renderFeed(lang, w, r, client) renderFeed(lang, w, r, client)
case regexp.MustCompile(`^/(sgs|en)/a/?$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/a/?$`).MatchString(r.URL.Path):
renderAbout(lang, w) renderAbout(lang, w)
case regexp.MustCompile(`^/(sgs|en)/s/?$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/s/?$`).MatchString(r.URL.Path):
renderSearch(lang, w, r, client) renderSearch(lang, w, r, client)
case regexp.MustCompile(`^/(sgs|en)/f/?$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/f/?$`).MatchString(r.URL.Path):
renderAllFiles(lang, w, client) renderAllFiles(lang, w, client)
case regexp.MustCompile(`^/(sgs|en)/f/([\p{L}\d_+.]+/)+[\d\w]+/index.gmi$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/f/([\p{L}\d_+.]+/)+[\d\w]+/index.gmi$`).MatchString(r.URL.Path):
urlParts := strings.Split(r.URL.Path, "/") urlParts := strings.Split(r.URL.Path, "/")
w.WriteHeader(gemini.StatusPermanentRedirect, strings.Join(urlParts[:(len(urlParts)-2)], "/")) w.WriteHeader(gemini.StatusPermanentRedirect, strings.Join(urlParts[:(len(urlParts)-2)], "/"))
case regexp.MustCompile(`^/(sgs|en)/f/([\p{L}\d_+.]+/)+[\d\w]+/[\p{L}\d_+.]+.gmi$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/f/([\p{L}\d_+.]+/)+[\d\w]+/[\p{L}\d_+.]+.gmi$`).MatchString(r.URL.Path):
renderFile(lang, w, r, client) renderFile(lang, w, r, client)
case regexp.MustCompile(`^/(sgs|en)/f/[\p{L}\d_+.]+(/[\p{L}\d_+.]+)*/?$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/f/[\p{L}\d_+.]+(/[\p{L}\d_+.]+)*/?$`).MatchString(r.URL.Path):
renderCategory(lang, w, r, client) renderCategory(lang, w, r, client)
case regexp.MustCompile(`^/(sgs|en)/t/[\p{L}\d_+.]+/?$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/(` + langs + `)/t/[\p{L}\d_+.]+/?$`).MatchString(r.URL.Path):
renderTag(lang, w, r, client) renderTag(lang, w, r, client)
// case abruozdelee case regexp.MustCompile(`^/__a/`).MatchString(r.URL.Path):
downloadAttachment(w, r, client)
default: default:
w.WriteHeader(gemini.StatusNotFound, "Out of space") w.WriteHeader(gemini.StatusNotFound, "Out of space")
} }
} }
func downloadAttachment(w gemini.ResponseWriter, r *gemini.Request, client TreeManagerClient) {
urlParts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
filePath := urlParts[len(urlParts)-1]
ar := AttachmentRequest{Path: filePath}
response, err := client.DownloadAttachment(context.Background(), &ar)
if err != nil {
log.Fatalf("client.DownloadAttachment failed: %v", err)
w.WriteHeader(gemini.StatusNotFound, "We lost it!")
return
}
//w.SetMediaType(http.DetectContentType([]byte(response.Content)))
w.SetMediaType("image/png")
for {
chunkResponse, err := response.Recv()
if err == io.EOF {
log.Println("received all chunks")
break
}
if err != nil {
log.Println("err receiving chunk:", err)
break
}
_, err = w.Write(chunkResponse.Chunk)
if err != nil {
w.WriteHeader(gemini.StatusTemporaryFailure, "Internal server error")
return
}
}
}
func renderIndex(lang string, w gemini.ResponseWriter, client TreeManagerClient) { func renderIndex(lang string, w gemini.ResponseWriter, client TreeManagerClient) {
filters := []*TreeRequest_Filter{{Key: "lang", Value: lang}} filters := []*TreeRequest_Filter{{Key: "lang", Value: lang}}
if lang == "sgs" { if lang == "sgs" {

View file

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.28.0 // protoc-gen-go v1.30.0
// protoc v3.21.4 // protoc v3.21.12
// source: tree.proto // source: tree.proto
package main package main
@ -461,6 +461,100 @@ func (x *FileContent) GetContent() string {
return "" return ""
} }
type AttachmentRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
}
func (x *AttachmentRequest) Reset() {
*x = AttachmentRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_tree_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AttachmentRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AttachmentRequest) ProtoMessage() {}
func (x *AttachmentRequest) ProtoReflect() protoreflect.Message {
mi := &file_tree_proto_msgTypes[7]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AttachmentRequest.ProtoReflect.Descriptor instead.
func (*AttachmentRequest) Descriptor() ([]byte, []int) {
return file_tree_proto_rawDescGZIP(), []int{7}
}
func (x *AttachmentRequest) GetPath() string {
if x != nil {
return x.Path
}
return ""
}
type AttachmentResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Chunk []byte `protobuf:"bytes,1,opt,name=chunk,proto3" json:"chunk,omitempty"`
}
func (x *AttachmentResponse) Reset() {
*x = AttachmentResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_tree_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AttachmentResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AttachmentResponse) ProtoMessage() {}
func (x *AttachmentResponse) ProtoReflect() protoreflect.Message {
mi := &file_tree_proto_msgTypes[8]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AttachmentResponse.ProtoReflect.Descriptor instead.
func (*AttachmentResponse) Descriptor() ([]byte, []int) {
return file_tree_proto_rawDescGZIP(), []int{8}
}
func (x *AttachmentResponse) GetChunk() []byte {
if x != nil {
return x.Chunk
}
return nil
}
type TreeRequest_Filter struct { type TreeRequest_Filter struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -473,7 +567,7 @@ type TreeRequest_Filter struct {
func (x *TreeRequest_Filter) Reset() { func (x *TreeRequest_Filter) Reset() {
*x = TreeRequest_Filter{} *x = TreeRequest_Filter{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_tree_proto_msgTypes[7] mi := &file_tree_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -486,7 +580,7 @@ func (x *TreeRequest_Filter) String() string {
func (*TreeRequest_Filter) ProtoMessage() {} func (*TreeRequest_Filter) ProtoMessage() {}
func (x *TreeRequest_Filter) ProtoReflect() protoreflect.Message { func (x *TreeRequest_Filter) ProtoReflect() protoreflect.Message {
mi := &file_tree_proto_msgTypes[7] mi := &file_tree_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -576,19 +670,29 @@ var file_tree_proto_rawDesc = []byte{
0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6d, 0x61, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6d, 0x61,
0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x04, 0x66, 0x69, 0x6c,
0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x32, 0xa9, 0x01, 0x0a, 0x0b, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x27, 0x0a, 0x11, 0x41,
0x54, 0x72, 0x65, 0x65, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x2d, 0x0a, 0x0a, 0x47, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x65, 0x74, 0x53, 0x75, 0x6d, 0x6d, 0x65, 0x72, 0x79, 0x12, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x2e, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0a, 0x2e, 0x6d, 0x70, 0x61, 0x74, 0x68, 0x22, 0x2a, 0x0a, 0x12, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65,
0x61, 0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x07, 0x47, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x68,
0x74, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x46, 0x69, 0x6c, 0x75, 0x6e, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x63, 0x68, 0x75, 0x6e, 0x6b,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x32, 0xf6, 0x01, 0x0a, 0x0b, 0x54, 0x72, 0x65, 0x65, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72,
0x46, 0x69, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x12, 0x2d, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x75, 0x6d, 0x6d, 0x65, 0x72, 0x79, 0x12, 0x11,
0x0b, 0x52, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x54, 0x72, 0x65, 0x65, 0x12, 0x10, 0x2e, 0x6d, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x61, 0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x1a, 0x15, 0x74, 0x1a, 0x0a, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x22, 0x00, 0x12,
0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x52, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x73, 0x31, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x11, 0x2e, 0x6d, 0x61, 0x69,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x03, 0x5a, 0x01, 0x2e, 0x62, 0x06, 0x70, 0x72, 0x6e, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e,
0x6f, 0x74, 0x6f, 0x33, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x22, 0x00, 0x12, 0x38, 0x0a, 0x0b, 0x52, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x54, 0x72, 0x65,
0x65, 0x12, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x53, 0x65, 0x63,
0x72, 0x65, 0x74, 0x1a, 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x52, 0x65, 0x62, 0x75, 0x69,
0x6c, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4b, 0x0a, 0x12,
0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65,
0x6e, 0x74, 0x12, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68,
0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x6d, 0x61,
0x69, 0x6e, 0x2e, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x42, 0x03, 0x5a, 0x01, 0x2e, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -603,7 +707,7 @@ func file_tree_proto_rawDescGZIP() []byte {
return file_tree_proto_rawDescData return file_tree_proto_rawDescData
} }
var file_tree_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_tree_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_tree_proto_goTypes = []interface{}{ var file_tree_proto_goTypes = []interface{}{
(*TreeSecret)(nil), // 0: main.TreeSecret (*TreeSecret)(nil), // 0: main.TreeSecret
(*RebuildResponse)(nil), // 1: main.RebuildResponse (*RebuildResponse)(nil), // 1: main.RebuildResponse
@ -612,25 +716,29 @@ var file_tree_proto_goTypes = []interface{}{
(*TreeFile)(nil), // 4: main.TreeFile (*TreeFile)(nil), // 4: main.TreeFile
(*Tree)(nil), // 5: main.Tree (*Tree)(nil), // 5: main.Tree
(*FileContent)(nil), // 6: main.FileContent (*FileContent)(nil), // 6: main.FileContent
(*TreeRequest_Filter)(nil), // 7: main.TreeRequest.Filter (*AttachmentRequest)(nil), // 7: main.AttachmentRequest
nil, // 8: main.Tree.TagsEntry (*AttachmentResponse)(nil), // 8: main.AttachmentResponse
nil, // 9: main.Tree.CategoriesEntry (*TreeRequest_Filter)(nil), // 9: main.TreeRequest.Filter
nil, // 10: main.Tree.TagsEntry
nil, // 11: main.Tree.CategoriesEntry
} }
var file_tree_proto_depIdxs = []int32{ var file_tree_proto_depIdxs = []int32{
7, // 0: main.TreeRequest.filter:type_name -> main.TreeRequest.Filter 9, // 0: main.TreeRequest.filter:type_name -> main.TreeRequest.Filter
4, // 1: main.Tree.files:type_name -> main.TreeFile 4, // 1: main.Tree.files:type_name -> main.TreeFile
4, // 2: main.Tree.rootFiles:type_name -> main.TreeFile 4, // 2: main.Tree.rootFiles:type_name -> main.TreeFile
8, // 3: main.Tree.tags:type_name -> main.Tree.TagsEntry 10, // 3: main.Tree.tags:type_name -> main.Tree.TagsEntry
9, // 4: main.Tree.categories:type_name -> main.Tree.CategoriesEntry 11, // 4: main.Tree.categories:type_name -> main.Tree.CategoriesEntry
4, // 5: main.FileContent.file:type_name -> main.TreeFile 4, // 5: main.FileContent.file:type_name -> main.TreeFile
3, // 6: main.TreeManager.GetSummery:input_type -> main.TreeRequest 3, // 6: main.TreeManager.GetSummery:input_type -> main.TreeRequest
2, // 7: main.TreeManager.GetFile:input_type -> main.FileRequest 2, // 7: main.TreeManager.GetFile:input_type -> main.FileRequest
0, // 8: main.TreeManager.RebuildTree:input_type -> main.TreeSecret 0, // 8: main.TreeManager.RebuildTree:input_type -> main.TreeSecret
5, // 9: main.TreeManager.GetSummery:output_type -> main.Tree 7, // 9: main.TreeManager.DownloadAttachment:input_type -> main.AttachmentRequest
6, // 10: main.TreeManager.GetFile:output_type -> main.FileContent 5, // 10: main.TreeManager.GetSummery:output_type -> main.Tree
1, // 11: main.TreeManager.RebuildTree:output_type -> main.RebuildResponse 6, // 11: main.TreeManager.GetFile:output_type -> main.FileContent
9, // [9:12] is the sub-list for method output_type 1, // 12: main.TreeManager.RebuildTree:output_type -> main.RebuildResponse
6, // [6:9] is the sub-list for method input_type 8, // 13: main.TreeManager.DownloadAttachment:output_type -> main.AttachmentResponse
10, // [10:14] is the sub-list for method output_type
6, // [6:10] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name 6, // [6:6] is the sub-list for extension type_name
6, // [6:6] is the sub-list for extension extendee 6, // [6:6] is the sub-list for extension extendee
0, // [0:6] is the sub-list for field type_name 0, // [0:6] is the sub-list for field type_name
@ -727,6 +835,30 @@ func file_tree_proto_init() {
} }
} }
file_tree_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { file_tree_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AttachmentRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_tree_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AttachmentResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_tree_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*TreeRequest_Filter); i { switch v := v.(*TreeRequest_Filter); i {
case 0: case 0:
return &v.state return &v.state
@ -746,7 +878,7 @@ func file_tree_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_tree_proto_rawDesc, RawDescriptor: file_tree_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 10, NumMessages: 12,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View file

@ -11,6 +11,7 @@ service TreeManager {
rpc GetSummery(TreeRequest) returns (Tree) {} rpc GetSummery(TreeRequest) returns (Tree) {}
rpc GetFile(FileRequest) returns (FileContent) {} rpc GetFile(FileRequest) returns (FileContent) {}
rpc RebuildTree(TreeSecret) returns (RebuildResponse) {} rpc RebuildTree(TreeSecret) returns (RebuildResponse) {}
rpc DownloadAttachment(AttachmentRequest) returns (stream AttachmentResponse) {}
} }
message TreeSecret { message TreeSecret {
@ -59,3 +60,11 @@ message FileContent {
TreeFile file = 1; TreeFile file = 1;
string content = 2; string content = 2;
} }
message AttachmentRequest {
string path = 1;
}
message AttachmentResponse {
bytes chunk = 1;
}

View file

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT. // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-grpc v1.2.0 // - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.4 // - protoc v3.21.12
// source: tree.proto // source: tree.proto
package main package main
@ -25,6 +25,7 @@ type TreeManagerClient interface {
GetSummery(ctx context.Context, in *TreeRequest, opts ...grpc.CallOption) (*Tree, error) GetSummery(ctx context.Context, in *TreeRequest, opts ...grpc.CallOption) (*Tree, error)
GetFile(ctx context.Context, in *FileRequest, opts ...grpc.CallOption) (*FileContent, error) GetFile(ctx context.Context, in *FileRequest, opts ...grpc.CallOption) (*FileContent, error)
RebuildTree(ctx context.Context, in *TreeSecret, opts ...grpc.CallOption) (*RebuildResponse, error) RebuildTree(ctx context.Context, in *TreeSecret, opts ...grpc.CallOption) (*RebuildResponse, error)
DownloadAttachment(ctx context.Context, in *AttachmentRequest, opts ...grpc.CallOption) (TreeManager_DownloadAttachmentClient, error)
} }
type treeManagerClient struct { type treeManagerClient struct {
@ -62,6 +63,38 @@ func (c *treeManagerClient) RebuildTree(ctx context.Context, in *TreeSecret, opt
return out, nil return out, nil
} }
func (c *treeManagerClient) DownloadAttachment(ctx context.Context, in *AttachmentRequest, opts ...grpc.CallOption) (TreeManager_DownloadAttachmentClient, error) {
stream, err := c.cc.NewStream(ctx, &TreeManager_ServiceDesc.Streams[0], "/main.TreeManager/DownloadAttachment", opts...)
if err != nil {
return nil, err
}
x := &treeManagerDownloadAttachmentClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type TreeManager_DownloadAttachmentClient interface {
Recv() (*AttachmentResponse, error)
grpc.ClientStream
}
type treeManagerDownloadAttachmentClient struct {
grpc.ClientStream
}
func (x *treeManagerDownloadAttachmentClient) Recv() (*AttachmentResponse, error) {
m := new(AttachmentResponse)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// TreeManagerServer is the server API for TreeManager service. // TreeManagerServer is the server API for TreeManager service.
// All implementations must embed UnimplementedTreeManagerServer // All implementations must embed UnimplementedTreeManagerServer
// for forward compatibility // for forward compatibility
@ -69,6 +102,7 @@ type TreeManagerServer interface {
GetSummery(context.Context, *TreeRequest) (*Tree, error) GetSummery(context.Context, *TreeRequest) (*Tree, error)
GetFile(context.Context, *FileRequest) (*FileContent, error) GetFile(context.Context, *FileRequest) (*FileContent, error)
RebuildTree(context.Context, *TreeSecret) (*RebuildResponse, error) RebuildTree(context.Context, *TreeSecret) (*RebuildResponse, error)
DownloadAttachment(*AttachmentRequest, TreeManager_DownloadAttachmentServer) error
mustEmbedUnimplementedTreeManagerServer() mustEmbedUnimplementedTreeManagerServer()
} }
@ -85,6 +119,9 @@ func (UnimplementedTreeManagerServer) GetFile(context.Context, *FileRequest) (*F
func (UnimplementedTreeManagerServer) RebuildTree(context.Context, *TreeSecret) (*RebuildResponse, error) { func (UnimplementedTreeManagerServer) RebuildTree(context.Context, *TreeSecret) (*RebuildResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method RebuildTree not implemented") return nil, status.Errorf(codes.Unimplemented, "method RebuildTree not implemented")
} }
func (UnimplementedTreeManagerServer) DownloadAttachment(*AttachmentRequest, TreeManager_DownloadAttachmentServer) error {
return status.Errorf(codes.Unimplemented, "method DownloadAttachment not implemented")
}
func (UnimplementedTreeManagerServer) mustEmbedUnimplementedTreeManagerServer() {} func (UnimplementedTreeManagerServer) mustEmbedUnimplementedTreeManagerServer() {}
// UnsafeTreeManagerServer may be embedded to opt out of forward compatibility for this service. // UnsafeTreeManagerServer may be embedded to opt out of forward compatibility for this service.
@ -152,6 +189,27 @@ func _TreeManager_RebuildTree_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _TreeManager_DownloadAttachment_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(AttachmentRequest)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(TreeManagerServer).DownloadAttachment(m, &treeManagerDownloadAttachmentServer{stream})
}
type TreeManager_DownloadAttachmentServer interface {
Send(*AttachmentResponse) error
grpc.ServerStream
}
type treeManagerDownloadAttachmentServer struct {
grpc.ServerStream
}
func (x *treeManagerDownloadAttachmentServer) Send(m *AttachmentResponse) error {
return x.ServerStream.SendMsg(m)
}
// TreeManager_ServiceDesc is the grpc.ServiceDesc for TreeManager service. // TreeManager_ServiceDesc is the grpc.ServiceDesc for TreeManager service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -172,6 +230,12 @@ var TreeManager_ServiceDesc = grpc.ServiceDesc{
Handler: _TreeManager_RebuildTree_Handler, Handler: _TreeManager_RebuildTree_Handler,
}, },
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{
{
StreamName: "DownloadAttachment",
Handler: _TreeManager_DownloadAttachment_Handler,
ServerStreams: true,
},
},
Metadata: "tree.proto", Metadata: "tree.proto",
} }