start on dedicated 'request' command
This commit is contained in:
		
							parent
							
								
									c965c578bf
								
							
						
					
					
						commit
						d29fabfa52
					
				
							
								
								
									
										87
									
								
								request/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								request/main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,87 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io/ioutil"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"os/user"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						//email "git.tilde.town/tildetown/town/email"
 | 
				
			||||||
 | 
						townUser "git.tilde.town/tildetown/town/user"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const requestPath = "/town/requests"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _main(args []string) error {
 | 
				
			||||||
 | 
						currentUser, err := user.Current()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ok, err := townUser.IsAdmin(currentUser)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return errors.New("must be a town admin")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						errs := []error{}
 | 
				
			||||||
 | 
						errs = append(errs, processGitea(requestPath))
 | 
				
			||||||
 | 
						errs = append(errs, processGemini(requestPath))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(errs) > 0 {
 | 
				
			||||||
 | 
							errMsg := "errors encountered during request processing: "
 | 
				
			||||||
 | 
							for _, e := range errs {
 | 
				
			||||||
 | 
								errMsg += e.Error() + " "
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return fmt.Errorf("errors encountered during request processing: %s", errMsg)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						retcode := 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err := _main(os.Args)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Fprintln(os.Stderr, err.Error())
 | 
				
			||||||
 | 
							retcode = 1
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						os.Exit(retcode)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func processGitea(rp string) error {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func processGemini(requestRootPath string) error {
 | 
				
			||||||
 | 
						rp := filepath.Join(requestRootPath, "gemini")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						files, err := ioutil.ReadDir(rp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to list directory %s: %w", rp, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						usernames := []string{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, file := range files {
 | 
				
			||||||
 | 
							usernames = append(usernames, file.Name())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(usernames) == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, username := range usernames {
 | 
				
			||||||
 | 
							// TODO check for public_gemini already in their home dir
 | 
				
			||||||
 | 
							// TODO create publiC_gemini
 | 
				
			||||||
 | 
							// TODO check for existing symlink
 | 
				
			||||||
 | 
							// TODO create symlink
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user