package api import ( "context" "net/http" "git.golem15.com/golem15/sm-seo-plugin/classes" ) // GetLinksInput is the query of GET /_seo/api/v1/links. type GetLinksInput struct { URL string `json:"url" query:"url" jsonschema:"the page: a path such as /blog/post or an absolute URL of the site"` } // Links serves GET /_seo/api/v1/links?url= (D-82, UI-SPEC C19): the // page's internal links from the last finished crawl, {crawledAt, // inbound, outbound, orphan, out [{phrase, title, url}], in [{phrase, // title, adminUrl}]}; before the first crawl crawledAt, inbound and // outbound are null and the lists empty. A url that is not a path or an // http(s) URL is 422. func Links(service func() *classes.Service) http.HandlerFunc { return manage(service, func(ctx context.Context, svc *classes.Service, r *http.Request) (int, any, error) { db, err := read(ctx, svc) if err != nil { return 0, nil, err } report, err := svc.LinksOfURL(ctx, db, r.URL.Query().Get("url")) if err != nil { return 0, nil, err } return http.StatusOK, report, nil }) }