mirror of https://github.com/usememos/memos
chore: implement storage service
parent
707e5caf89
commit
8f51529c78
@ -0,0 +1,109 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package memos.api.v2;
|
||||
|
||||
import "google/api/annotations.proto";
|
||||
import "google/api/client.proto";
|
||||
import "google/protobuf/field_mask.proto";
|
||||
|
||||
option go_package = "gen/api/v2";
|
||||
|
||||
service StorageService {
|
||||
// CreateStorage creates a new storage.
|
||||
rpc CreateStorage(CreateStorageRequest) returns (CreateStorageResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v2/storages"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// GetStorage returns a storage by id.
|
||||
rpc GetStorage(GetStorageRequest) returns (GetStorageResponse) {
|
||||
option (google.api.http) = {get: "/api/v2/storages/{id}"};
|
||||
option (google.api.method_signature) = "id";
|
||||
}
|
||||
// ListStorages returns a list of storages.
|
||||
rpc ListStorages(ListStoragesRequest) returns (ListStoragesResponse) {
|
||||
option (google.api.http) = {get: "/api/v2/storages"};
|
||||
}
|
||||
// UpdateStorage updates a storage.
|
||||
rpc UpdateStorage(UpdateStorageRequest) returns (UpdateStorageResponse) {
|
||||
option (google.api.http) = {
|
||||
patch: "/api/v2/storages/{storage.id}"
|
||||
body: "storage"
|
||||
};
|
||||
option (google.api.method_signature) = "storage,update_mask";
|
||||
}
|
||||
// DeleteStorage deletes a storage by id.
|
||||
rpc DeleteStorage(DeleteStorageRequest) returns (DeleteStorageResponse) {
|
||||
option (google.api.http) = {delete: "/api/v2/storages/{id}"};
|
||||
option (google.api.method_signature) = "id";
|
||||
}
|
||||
}
|
||||
|
||||
message Storage {
|
||||
int32 id = 1;
|
||||
string title = 2;
|
||||
|
||||
enum Type {
|
||||
TYPE_UNSPECIFIED = 0;
|
||||
S3 = 1;
|
||||
}
|
||||
Type type = 3;
|
||||
StorageConfig config = 4;
|
||||
}
|
||||
|
||||
message StorageConfig {
|
||||
oneof storage_config {
|
||||
S3Config s3_config = 1;
|
||||
}
|
||||
}
|
||||
|
||||
message S3Config {
|
||||
string end_point = 1;
|
||||
string path = 2;
|
||||
string region = 3;
|
||||
string access_key = 4;
|
||||
string secret_key = 5;
|
||||
string bucket = 6;
|
||||
string url_prefix = 7;
|
||||
string url_suffix = 8;
|
||||
bool pre_sign = 9;
|
||||
}
|
||||
|
||||
message CreateStorageRequest {
|
||||
Storage storage = 1;
|
||||
}
|
||||
|
||||
message CreateStorageResponse {
|
||||
Storage storage = 1;
|
||||
}
|
||||
|
||||
message GetStorageRequest {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
message GetStorageResponse {
|
||||
Storage storage = 1;
|
||||
}
|
||||
|
||||
message ListStoragesRequest {}
|
||||
|
||||
message ListStoragesResponse {
|
||||
repeated Storage storages = 1;
|
||||
}
|
||||
|
||||
message UpdateStorageRequest {
|
||||
Storage storage = 1;
|
||||
|
||||
google.protobuf.FieldMask update_mask = 2;
|
||||
}
|
||||
|
||||
message UpdateStorageResponse {
|
||||
Storage storage = 1;
|
||||
}
|
||||
|
||||
message DeleteStorageRequest {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
message DeleteStorageResponse {}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,597 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: api/v2/storage_service.proto
|
||||
|
||||
/*
|
||||
Package apiv2 is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package apiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = metadata.Join
|
||||
|
||||
func request_StorageService_CreateStorage_0(ctx context.Context, marshaler runtime.Marshaler, client StorageServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.CreateStorage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_StorageService_CreateStorage_0(ctx context.Context, marshaler runtime.Marshaler, server StorageServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.CreateStorage(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_StorageService_GetStorage_0(ctx context.Context, marshaler runtime.Marshaler, client StorageServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.Int32(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetStorage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_StorageService_GetStorage_0(ctx context.Context, marshaler runtime.Marshaler, server StorageServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.Int32(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetStorage(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_StorageService_ListStorages_0(ctx context.Context, marshaler runtime.Marshaler, client StorageServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListStoragesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.ListStorages(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_StorageService_ListStorages_0(ctx context.Context, marshaler runtime.Marshaler, server StorageServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListStoragesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.ListStorages(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_StorageService_UpdateStorage_0 = &utilities.DoubleArray{Encoding: map[string]int{"storage": 0, "id": 1}, Base: []int{1, 4, 5, 2, 0, 0, 0, 0}, Check: []int{0, 1, 1, 2, 4, 2, 2, 3}}
|
||||
)
|
||||
|
||||
func request_StorageService_UpdateStorage_0(ctx context.Context, marshaler runtime.Marshaler, client StorageServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq UpdateStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Storage); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
|
||||
if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Storage); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
} else {
|
||||
protoReq.UpdateMask = fieldMask
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["storage.id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "storage.id")
|
||||
}
|
||||
|
||||
err = runtime.PopulateFieldFromPath(&protoReq, "storage.id", val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "storage.id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_StorageService_UpdateStorage_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.UpdateStorage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_StorageService_UpdateStorage_0(ctx context.Context, marshaler runtime.Marshaler, server StorageServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq UpdateStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Storage); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
|
||||
if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Storage); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
} else {
|
||||
protoReq.UpdateMask = fieldMask
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["storage.id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "storage.id")
|
||||
}
|
||||
|
||||
err = runtime.PopulateFieldFromPath(&protoReq, "storage.id", val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "storage.id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_StorageService_UpdateStorage_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.UpdateStorage(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_StorageService_DeleteStorage_0(ctx context.Context, marshaler runtime.Marshaler, client StorageServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeleteStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.Int32(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
msg, err := client.DeleteStorage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_StorageService_DeleteStorage_0(ctx context.Context, marshaler runtime.Marshaler, server StorageServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeleteStorageRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.Int32(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
msg, err := server.DeleteStorage(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterStorageServiceHandlerServer registers the http handlers for service StorageService to "mux".
|
||||
// UnaryRPC :call StorageServiceServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterStorageServiceHandlerFromEndpoint instead.
|
||||
func RegisterStorageServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server StorageServiceServer) error {
|
||||
|
||||
mux.Handle("POST", pattern_StorageService_CreateStorage_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.v2.StorageService/CreateStorage", runtime.WithHTTPPathPattern("/api/v2/storages"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_StorageService_CreateStorage_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_StorageService_CreateStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_StorageService_GetStorage_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.v2.StorageService/GetStorage", runtime.WithHTTPPathPattern("/api/v2/storages/{id}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_StorageService_GetStorage_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_StorageService_GetStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_StorageService_ListStorages_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.v2.StorageService/ListStorages", runtime.WithHTTPPathPattern("/api/v2/storages"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_StorageService_ListStorages_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_StorageService_ListStorages_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("PATCH", pattern_StorageService_UpdateStorage_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.v2.StorageService/UpdateStorage", runtime.WithHTTPPathPattern("/api/v2/storages/{storage.id}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_StorageService_UpdateStorage_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_StorageService_UpdateStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_StorageService_DeleteStorage_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.v2.StorageService/DeleteStorage", runtime.WithHTTPPathPattern("/api/v2/storages/{id}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_StorageService_DeleteStorage_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_StorageService_DeleteStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterStorageServiceHandlerFromEndpoint is same as RegisterStorageServiceHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterStorageServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.DialContext(ctx, endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterStorageServiceHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterStorageServiceHandler registers the http handlers for service StorageService to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterStorageServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterStorageServiceHandlerClient(ctx, mux, NewStorageServiceClient(conn))
|
||||
}
|
||||
|
||||
// RegisterStorageServiceHandlerClient registers the http handlers for service StorageService
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "StorageServiceClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "StorageServiceClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "StorageServiceClient" to call the correct interceptors.
|
||||
func RegisterStorageServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client StorageServiceClient) error {
|
||||
|
||||
mux.Handle("POST", pattern_StorageService_CreateStorage_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.v2.StorageService/CreateStorage", runtime.WithHTTPPathPattern("/api/v2/storages"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_StorageService_CreateStorage_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_StorageService_CreateStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_StorageService_GetStorage_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.v2.StorageService/GetStorage", runtime.WithHTTPPathPattern("/api/v2/storages/{id}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_StorageService_GetStorage_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_StorageService_GetStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_StorageService_ListStorages_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.v2.StorageService/ListStorages", runtime.WithHTTPPathPattern("/api/v2/storages"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_StorageService_ListStorages_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_StorageService_ListStorages_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("PATCH", pattern_StorageService_UpdateStorage_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.v2.StorageService/UpdateStorage", runtime.WithHTTPPathPattern("/api/v2/storages/{storage.id}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_StorageService_UpdateStorage_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_StorageService_UpdateStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_StorageService_DeleteStorage_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.v2.StorageService/DeleteStorage", runtime.WithHTTPPathPattern("/api/v2/storages/{id}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_StorageService_DeleteStorage_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_StorageService_DeleteStorage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_StorageService_CreateStorage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "storages"}, ""))
|
||||
|
||||
pattern_StorageService_GetStorage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v2", "storages", "id"}, ""))
|
||||
|
||||
pattern_StorageService_ListStorages_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "storages"}, ""))
|
||||
|
||||
pattern_StorageService_UpdateStorage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v2", "storages", "storage.id"}, ""))
|
||||
|
||||
pattern_StorageService_DeleteStorage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v2", "storages", "id"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_StorageService_CreateStorage_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_StorageService_GetStorage_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_StorageService_ListStorages_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_StorageService_UpdateStorage_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_StorageService_DeleteStorage_0 = runtime.ForwardResponseMessage
|
||||
)
|
@ -0,0 +1,267 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.3.0
|
||||
// - protoc (unknown)
|
||||
// source: api/v2/storage_service.proto
|
||||
|
||||
package apiv2
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
const (
|
||||
StorageService_CreateStorage_FullMethodName = "/memos.api.v2.StorageService/CreateStorage"
|
||||
StorageService_GetStorage_FullMethodName = "/memos.api.v2.StorageService/GetStorage"
|
||||
StorageService_ListStorages_FullMethodName = "/memos.api.v2.StorageService/ListStorages"
|
||||
StorageService_UpdateStorage_FullMethodName = "/memos.api.v2.StorageService/UpdateStorage"
|
||||
StorageService_DeleteStorage_FullMethodName = "/memos.api.v2.StorageService/DeleteStorage"
|
||||
)
|
||||
|
||||
// StorageServiceClient is the client API for StorageService 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 StorageServiceClient interface {
|
||||
// CreateStorage creates a new storage.
|
||||
CreateStorage(ctx context.Context, in *CreateStorageRequest, opts ...grpc.CallOption) (*CreateStorageResponse, error)
|
||||
// GetStorage returns a storage by id.
|
||||
GetStorage(ctx context.Context, in *GetStorageRequest, opts ...grpc.CallOption) (*GetStorageResponse, error)
|
||||
// ListStorages returns a list of storages.
|
||||
ListStorages(ctx context.Context, in *ListStoragesRequest, opts ...grpc.CallOption) (*ListStoragesResponse, error)
|
||||
// UpdateStorage updates a storage.
|
||||
UpdateStorage(ctx context.Context, in *UpdateStorageRequest, opts ...grpc.CallOption) (*UpdateStorageResponse, error)
|
||||
// DeleteStorage deletes a storage by id.
|
||||
DeleteStorage(ctx context.Context, in *DeleteStorageRequest, opts ...grpc.CallOption) (*DeleteStorageResponse, error)
|
||||
}
|
||||
|
||||
type storageServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewStorageServiceClient(cc grpc.ClientConnInterface) StorageServiceClient {
|
||||
return &storageServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *storageServiceClient) CreateStorage(ctx context.Context, in *CreateStorageRequest, opts ...grpc.CallOption) (*CreateStorageResponse, error) {
|
||||
out := new(CreateStorageResponse)
|
||||
err := c.cc.Invoke(ctx, StorageService_CreateStorage_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *storageServiceClient) GetStorage(ctx context.Context, in *GetStorageRequest, opts ...grpc.CallOption) (*GetStorageResponse, error) {
|
||||
out := new(GetStorageResponse)
|
||||
err := c.cc.Invoke(ctx, StorageService_GetStorage_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *storageServiceClient) ListStorages(ctx context.Context, in *ListStoragesRequest, opts ...grpc.CallOption) (*ListStoragesResponse, error) {
|
||||
out := new(ListStoragesResponse)
|
||||
err := c.cc.Invoke(ctx, StorageService_ListStorages_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *storageServiceClient) UpdateStorage(ctx context.Context, in *UpdateStorageRequest, opts ...grpc.CallOption) (*UpdateStorageResponse, error) {
|
||||
out := new(UpdateStorageResponse)
|
||||
err := c.cc.Invoke(ctx, StorageService_UpdateStorage_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *storageServiceClient) DeleteStorage(ctx context.Context, in *DeleteStorageRequest, opts ...grpc.CallOption) (*DeleteStorageResponse, error) {
|
||||
out := new(DeleteStorageResponse)
|
||||
err := c.cc.Invoke(ctx, StorageService_DeleteStorage_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// StorageServiceServer is the server API for StorageService service.
|
||||
// All implementations must embed UnimplementedStorageServiceServer
|
||||
// for forward compatibility
|
||||
type StorageServiceServer interface {
|
||||
// CreateStorage creates a new storage.
|
||||
CreateStorage(context.Context, *CreateStorageRequest) (*CreateStorageResponse, error)
|
||||
// GetStorage returns a storage by id.
|
||||
GetStorage(context.Context, *GetStorageRequest) (*GetStorageResponse, error)
|
||||
// ListStorages returns a list of storages.
|
||||
ListStorages(context.Context, *ListStoragesRequest) (*ListStoragesResponse, error)
|
||||
// UpdateStorage updates a storage.
|
||||
UpdateStorage(context.Context, *UpdateStorageRequest) (*UpdateStorageResponse, error)
|
||||
// DeleteStorage deletes a storage by id.
|
||||
DeleteStorage(context.Context, *DeleteStorageRequest) (*DeleteStorageResponse, error)
|
||||
mustEmbedUnimplementedStorageServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedStorageServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedStorageServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedStorageServiceServer) CreateStorage(context.Context, *CreateStorageRequest) (*CreateStorageResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateStorage not implemented")
|
||||
}
|
||||
func (UnimplementedStorageServiceServer) GetStorage(context.Context, *GetStorageRequest) (*GetStorageResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetStorage not implemented")
|
||||
}
|
||||
func (UnimplementedStorageServiceServer) ListStorages(context.Context, *ListStoragesRequest) (*ListStoragesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListStorages not implemented")
|
||||
}
|
||||
func (UnimplementedStorageServiceServer) UpdateStorage(context.Context, *UpdateStorageRequest) (*UpdateStorageResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateStorage not implemented")
|
||||
}
|
||||
func (UnimplementedStorageServiceServer) DeleteStorage(context.Context, *DeleteStorageRequest) (*DeleteStorageResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteStorage not implemented")
|
||||
}
|
||||
func (UnimplementedStorageServiceServer) mustEmbedUnimplementedStorageServiceServer() {}
|
||||
|
||||
// UnsafeStorageServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to StorageServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeStorageServiceServer interface {
|
||||
mustEmbedUnimplementedStorageServiceServer()
|
||||
}
|
||||
|
||||
func RegisterStorageServiceServer(s grpc.ServiceRegistrar, srv StorageServiceServer) {
|
||||
s.RegisterService(&StorageService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _StorageService_CreateStorage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateStorageRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StorageServiceServer).CreateStorage(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StorageService_CreateStorage_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StorageServiceServer).CreateStorage(ctx, req.(*CreateStorageRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StorageService_GetStorage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetStorageRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StorageServiceServer).GetStorage(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StorageService_GetStorage_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StorageServiceServer).GetStorage(ctx, req.(*GetStorageRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StorageService_ListStorages_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListStoragesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StorageServiceServer).ListStorages(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StorageService_ListStorages_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StorageServiceServer).ListStorages(ctx, req.(*ListStoragesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StorageService_UpdateStorage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateStorageRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StorageServiceServer).UpdateStorage(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StorageService_UpdateStorage_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StorageServiceServer).UpdateStorage(ctx, req.(*UpdateStorageRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StorageService_DeleteStorage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteStorageRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StorageServiceServer).DeleteStorage(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StorageService_DeleteStorage_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StorageServiceServer).DeleteStorage(ctx, req.(*DeleteStorageRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// StorageService_ServiceDesc is the grpc.ServiceDesc for StorageService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var StorageService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "memos.api.v2.StorageService",
|
||||
HandlerType: (*StorageServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateStorage",
|
||||
Handler: _StorageService_CreateStorage_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetStorage",
|
||||
Handler: _StorageService_GetStorage_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListStorages",
|
||||
Handler: _StorageService_ListStorages_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateStorage",
|
||||
Handler: _StorageService_UpdateStorage_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteStorage",
|
||||
Handler: _StorageService_DeleteStorage_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "api/v2/storage_service.proto",
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
|
||||
storepb "github.com/usememos/memos/proto/gen/store"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
func (s *APIV2Service) CreateStorage(ctx context.Context, request *apiv2pb.CreateStorageRequest) (*apiv2pb.CreateStorageResponse, error) {
|
||||
currentUser, err := getCurrentUser(ctx, s.Store)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get user: %v", err)
|
||||
}
|
||||
if currentUser.Role != store.RoleHost {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
storage, err := s.Store.CreateStorageV1(ctx, convertStorageToStore(request.Storage))
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to create storage, error: %+v", err)
|
||||
}
|
||||
return &apiv2pb.CreateStorageResponse{
|
||||
Storage: convertStorageFromStore(storage),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *APIV2Service) ListStorages(ctx context.Context, _ *apiv2pb.ListStoragesRequest) (*apiv2pb.ListStoragesResponse, error) {
|
||||
storages, err := s.Store.ListStoragesV1(ctx, &store.FindStorage{})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list storages, error: %+v", err)
|
||||
}
|
||||
|
||||
response := &apiv2pb.ListStoragesResponse{
|
||||
Storages: []*apiv2pb.Storage{},
|
||||
}
|
||||
for _, storage := range storages {
|
||||
response.Storages = append(response.Storages, convertStorageFromStore(storage))
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *APIV2Service) GetStorage(ctx context.Context, request *apiv2pb.GetStorageRequest) (*apiv2pb.GetStorageResponse, error) {
|
||||
storage, err := s.Store.GetStorageV1(ctx, &store.FindStorage{
|
||||
ID: &request.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get storage, error: %+v", err)
|
||||
}
|
||||
if storage == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "storage not found")
|
||||
}
|
||||
return &apiv2pb.GetStorageResponse{
|
||||
Storage: convertStorageFromStore(storage),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *APIV2Service) UpdateStorage(ctx context.Context, request *apiv2pb.UpdateStorageRequest) (*apiv2pb.UpdateStorageResponse, error) {
|
||||
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "update_mask is required")
|
||||
}
|
||||
|
||||
update := &store.UpdateStorageV1{
|
||||
ID: request.Storage.Id,
|
||||
Type: storepb.Storage_Type(storepb.Storage_Type_value[request.Storage.Type.String()]),
|
||||
}
|
||||
for _, field := range request.UpdateMask.Paths {
|
||||
switch field {
|
||||
case "name":
|
||||
update.Name = &request.Storage.Title
|
||||
case "config":
|
||||
update.Config = convertStorageConfigToStore(request.Storage.Type, request.Storage.Config)
|
||||
}
|
||||
}
|
||||
|
||||
storage, err := s.Store.UpdateStorageV1(ctx, update)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to update storage, error: %+v", err)
|
||||
}
|
||||
return &apiv2pb.UpdateStorageResponse{
|
||||
Storage: convertStorageFromStore(storage),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *APIV2Service) DeleteStorage(ctx context.Context, request *apiv2pb.DeleteStorageRequest) (*apiv2pb.DeleteStorageResponse, error) {
|
||||
err := s.Store.DeleteStorage(ctx, &store.DeleteStorage{
|
||||
ID: request.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to delete storage, error: %+v", err)
|
||||
}
|
||||
return &apiv2pb.DeleteStorageResponse{}, nil
|
||||
}
|
||||
|
||||
func convertStorageFromStore(storage *storepb.Storage) *apiv2pb.Storage {
|
||||
temp := &apiv2pb.Storage{
|
||||
Id: storage.Id,
|
||||
Title: storage.Name,
|
||||
Type: apiv2pb.Storage_Type(apiv2pb.Storage_Type_value[storage.Type.String()]),
|
||||
}
|
||||
if storage.Type == storepb.Storage_S3 {
|
||||
s3Config := storage.Config.GetS3Config()
|
||||
temp.Config = &apiv2pb.StorageConfig{
|
||||
StorageConfig: &apiv2pb.StorageConfig_S3Config{
|
||||
S3Config: &apiv2pb.S3Config{
|
||||
EndPoint: s3Config.EndPoint,
|
||||
Path: s3Config.Path,
|
||||
Region: s3Config.Region,
|
||||
AccessKey: s3Config.AccessKey,
|
||||
SecretKey: s3Config.SecretKey,
|
||||
Bucket: s3Config.Bucket,
|
||||
UrlPrefix: s3Config.UrlPrefix,
|
||||
UrlSuffix: s3Config.UrlSuffix,
|
||||
PreSign: s3Config.PreSign,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return temp
|
||||
}
|
||||
|
||||
func convertStorageToStore(storage *apiv2pb.Storage) *storepb.Storage {
|
||||
temp := &storepb.Storage{
|
||||
Id: storage.Id,
|
||||
Name: storage.Title,
|
||||
Type: storepb.Storage_Type(storepb.Storage_Type_value[storage.Type.String()]),
|
||||
Config: convertStorageConfigToStore(storage.Type, storage.Config),
|
||||
}
|
||||
return temp
|
||||
}
|
||||
|
||||
func convertStorageConfigToStore(storageType apiv2pb.Storage_Type, config *apiv2pb.StorageConfig) *storepb.StorageConfig {
|
||||
if storageType == apiv2pb.Storage_S3 {
|
||||
s3Config := config.GetS3Config()
|
||||
return &storepb.StorageConfig{
|
||||
StorageConfig: &storepb.StorageConfig_S3Config{
|
||||
S3Config: &storepb.S3Config{
|
||||
EndPoint: s3Config.EndPoint,
|
||||
Path: s3Config.Path,
|
||||
Region: s3Config.Region,
|
||||
AccessKey: s3Config.AccessKey,
|
||||
SecretKey: s3Config.SecretKey,
|
||||
Bucket: s3Config.Bucket,
|
||||
UrlPrefix: s3Config.UrlPrefix,
|
||||
UrlSuffix: s3Config.UrlSuffix,
|
||||
PreSign: s3Config.PreSign,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
type StorageId = number;
|
||||
|
||||
type StorageType = "S3";
|
||||
|
||||
interface StorageS3Config {
|
||||
endPoint: string;
|
||||
region: string;
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
path: string;
|
||||
bucket: string;
|
||||
urlPrefix: string;
|
||||
urlSuffix: string;
|
||||
presign: boolean;
|
||||
}
|
||||
|
||||
interface StorageConfig {
|
||||
s3Config: StorageS3Config;
|
||||
}
|
||||
|
||||
// Note: Storage is a reserved word in TypeScript. So we use ObjectStorage instead.
|
||||
interface ObjectStorage {
|
||||
id: StorageId;
|
||||
name: string;
|
||||
type: StorageType;
|
||||
config: StorageConfig;
|
||||
}
|
||||
|
||||
interface StorageCreate {
|
||||
name: string;
|
||||
type: StorageType;
|
||||
config: StorageConfig;
|
||||
}
|
||||
|
||||
interface StoragePatch {
|
||||
id: StorageId;
|
||||
name: string;
|
||||
type: StorageType;
|
||||
config: StorageConfig;
|
||||
}
|
Loading…
Reference in New Issue