package server import ( "net/http" "time" ) func (s *Server) handlePeriodicalNew(w http.ResponseWriter, r *http.Request, kind string) { if r.Method != http.MethodGet { w.Header().Set("Allow", "GET") http.Error(w, "method not allowed", 405) return } w.Header().Set("Cache-Control", "private, no-store") domain := s.domainUUIDForRequest(r) if _, err := s.store.PrincipalForSession(domain, s.authTokenFromRequest(r)); err != nil { s.authRequired(w, r) return } enabled, err := s.store.PeriodicalEnabled(r.Context(), domain, kind) if err != nil { http.Error(w, "extension unavailable", 503) return } if !enabled { http.NotFound(w, r) return } projection, err := s.store.PeriodicalProjection(r.Context(), domain, kind) if err != nil { http.Error(w, "projection unavailable", 503) return } if projection != nil { host, err := s.store.GetDomainEffectiveHost(projection.Source) if err != nil || host == "" { http.Error(w, "projection unavailable", 503) return } http.Redirect(w, r, "//"+host+"/v/"+kind+"/-/new", http.StatusSeeOther) return } prefix, err := s.store.PeriodicalPrefix(r.Context(), domain, kind) if err != nil { http.Error(w, "extension unavailable", 503) return } editType := s.getEditorFormat(domain) if requested := r.URL.Query().Get("edittype"); requested == "markdown" || requested == "html" { editType = requested } s.renderWithContext(w, r, "periodical_new.gohtml", map[string]any{ "Kind": kind, "Title": translate(s.getLocale(domain), "periodical.compose") + " ยท " + translate(s.getLocale(domain), "periodical."+kind), "Prefix": prefix, "Today": time.Now().In(s.getLocation(domain)).Format("2006-01-02"), "EditType": editType, "EditorKeymap": s.getEditorKeymap(domain), "EditorSyntax": s.getEditorSyntaxHighlight(domain), "EditorAutocomplete": s.getEditorAutocomplete(domain), "EditorPreviewDefault": s.getEditorPreviewDefault(domain), }) }