Files
frp-panel/services/workerd/file.go
2025-05-06 02:08:59 +00:00

45 lines
1.1 KiB
Go

package workerd
import (
"context"
"path/filepath"
"github.com/VaalaCat/frp-panel/defs"
"github.com/VaalaCat/frp-panel/pb"
"github.com/VaalaCat/frp-panel/utils"
)
func WriteWorkerCodeToFile(ctx context.Context, worker *pb.Worker, workerdCWD string) error {
return utils.WriteFile(
CodeFilePath(ctx, worker, workerdCWD),
string(worker.GetCode()))
}
func CodeFilePath(ctx context.Context, worker *pb.Worker, workerdCWD string) string {
return filepath.Join(
WorkerCWDPath(ctx, worker, workerdCWD),
defs.WorkerCodePath,
worker.GetCodeEntry())
}
func WorkerCodeRootPath(ctx context.Context, worker *pb.Worker, workerdCWD string) string {
return filepath.Join(
WorkerCWDPath(ctx, worker, workerdCWD),
defs.WorkerCodePath)
}
func WorkerCWDPath(ctx context.Context, worker *pb.Worker, workerdCWD string) string {
return filepath.Join(
workerdCWD,
defs.WorkerInfoPath,
worker.GetWorkerId(),
)
}
func ConfigFilePath(ctx context.Context, worker *pb.Worker, workerdCWD string) string {
return filepath.Join(
WorkerCWDPath(ctx, worker, workerdCWD),
defs.CapFileName,
)
}