package runner import ( "fmt" "git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/pkg/file" "go.uber.org/zap" "os" "path" "path/filepath" ) var ( Prefix = "./resource/runner" ProblemDir = "./problem/" UserDir = "./user/" TmpDir = "./tmp/" ) const ( ContainerImageFull = "git.0x7f.app/woj/ubuntu-full:latest" ContainerImageRun = "git.0x7f.app/woj/ubuntu-run:latest" ) type JudgeMeta struct { Version uint User string Lang string } func init() { wd, err := os.Getwd() if err != nil { panic(err) } Prefix = path.Join(wd, Prefix) ProblemDir = path.Join(Prefix, ProblemDir) UserDir = path.Join(Prefix, UserDir) TmpDir = path.Join(Prefix, TmpDir) } func (s *service) ProblemExists(meta *JudgeMeta) bool { problemPath := filepath.Join(ProblemDir, fmt.Sprintf("%d", meta.Version)) return file.Exist(problemPath) } func (s *service) ValidatePath(meta *JudgeMeta) e.Status { if !s.ProblemExists(meta) { s.log.Info("problem not exists", zap.Uint("version", meta.Version)) return e.RunnerProblemNotExist } userPath := filepath.Join(UserDir, meta.User, fmt.Sprintf("%s.%s", meta.User, meta.Lang)) if !file.Exist(userPath) { s.log.Info("user program not exists", zap.String("user", meta.User), zap.String("lang", meta.Lang)) return e.RunnerUserNotExist } return e.Success } func (s *service) GetConfig(meta *JudgeMeta, skipCheck bool) (*Config, *ConfigLanguage, e.Status) { config, err := s.ParseConfig(meta, skipCheck) if err != nil { return nil, nil, e.RunnerProblemParseFailed } cLang, ok := config.FilterLanguage(meta.Lang) if !ok { return nil, nil, e.RunnerLanguageNotSupported } return config, cLang, e.Success }