mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-06-22 02:39:55 -04:00
Add WebUI Support for V2Ray (#3284)
* Add support for web based grpc * Avoid panic in observatory command: incorrect tag * Add WebCommander app for web based client * Add WebCommander app for web based client * Add urlline subscription container format support * avoid panic when serving user request * refine subscription info api * fix start consistency issue in web commander * fix webcommander import style * fix urlline parsing * fix crash in subscription commander * add webroot file serving at webcommmander * fix crash when observatory is not found * add autogenerated subscriptionmgr err
This commit is contained in:
committed by
GitHub
parent
4adda5806a
commit
69b09074f8
78
app/subscription/subscriptionmanager/command/command.go
Normal file
78
app/subscription/subscriptionmanager/command/command.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v5"
|
||||
"github.com/v2fly/v2ray-core/v5/app/subscription"
|
||||
"github.com/v2fly/v2ray-core/v5/common"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
||||
|
||||
type SubscriptionManagerService struct {
|
||||
UnimplementedSubscriptionManagerServiceServer
|
||||
manager subscription.SubscriptionManager
|
||||
}
|
||||
|
||||
func NewSubscriptionManagerService(manager subscription.SubscriptionManager) *SubscriptionManagerService {
|
||||
return &SubscriptionManagerService{manager: manager}
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerService) ListTrackedSubscription(ctx context.Context, req *ListTrackedSubscriptionRequest) (*ListTrackedSubscriptionResponse, error) {
|
||||
if s.manager == nil {
|
||||
return nil, newError("subscription manager is not available")
|
||||
}
|
||||
names := s.manager.ListTrackedSubscriptions()
|
||||
return &ListTrackedSubscriptionResponse{Names: names}, nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerService) AddTrackedSubscription(ctx context.Context, req *AddTrackedSubscriptionRequest) (*AddTrackedSubscriptionResponse, error) {
|
||||
if s.manager == nil {
|
||||
return nil, newError("subscription manager is not available")
|
||||
}
|
||||
err := s.manager.AddTrackedSubscriptionFromImportSource(req.Source)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AddTrackedSubscriptionResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerService) RemoveTrackedSubscription(ctx context.Context, req *RemoveTrackedSubscriptionRequest) (*RemoveTrackedSubscriptionResponse, error) {
|
||||
if s.manager == nil {
|
||||
return nil, newError("subscription manager is not available")
|
||||
}
|
||||
err := s.manager.RemoveTrackedSubscription(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RemoveTrackedSubscriptionResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerService) GetTrackedSubscriptionStatus(ctx context.Context, req *GetTrackedSubscriptionStatusRequest) (*GetTrackedSubscriptionStatusResponse, error) {
|
||||
if s.manager == nil {
|
||||
return nil, newError("subscription manager is not available")
|
||||
}
|
||||
status, err := s.manager.GetTrackedSubscriptionStatus(req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &GetTrackedSubscriptionStatusResponse{Status: status}, nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerService) Register(server *grpc.Server) {
|
||||
RegisterSubscriptionManagerServiceServer(server, s)
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
|
||||
var manager subscription.SubscriptionManager
|
||||
common.Must(core.RequireFeatures(ctx, func(m subscription.SubscriptionManager) {
|
||||
manager = m
|
||||
}))
|
||||
service := NewSubscriptionManagerService(manager)
|
||||
return service, nil
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user