okami.mom/web-extract-go
git clone https://git.nkp.pet/okami.mom/web-extract-go
5a90548
main
1package app 2 3import ( 4"context" 5"strings" 6) 7 8// Old single-page names use the current contents pipeline and response contract. 9func (s * Service )pageAlias (ctx context.Context ,name string ,body []byte ) (ResultsResponse ,error ) { 10var q struct { 11URL string `json:"url"` 12Query string `json:"query"` 13Instructions string `json:"instructions"` 14IncludeMarkdown bool `json:"include_markdown"` 15MaxChars int `json:"max_chars"` 16 } 17if err := decodeRequest (body ,& q );err != nil { 18return ResultsResponse {},err 19 } 20q .Query = strings .TrimSpace (q .Query ) 21if name == "preview" && q .Query == "" { 22return ResultsResponse {},failure (400 ,"INVALID_REQUEST" ,"preview requires query" ) 23 } 24if len (q .Query )> 4000 || len (q .Instructions )> 4000 || q .MaxChars < 0 || q .MaxChars > 10000 { 25return ResultsResponse {},failure (400 ,"INVALID_REQUEST" ,"query/instructions must be at most 4000 bytes; max_chars must be 0–10000" ) 26 } 27if q .Query == "" { 28q .Query = strings .TrimSpace (q .Instructions ) 29 } 30return s .contents (ctx ,ContentsRequest { 31URLs : []string {q .URL }, 32ContentsOptions :ContentsOptions { 33Text :Feature {Set :true ,Enabled :name == "extract" || q .IncludeMarkdown ,MaxCharacters :q .MaxChars }, 34Summary :Feature {Set :true ,Enabled :name != "extract" ,Query :q .Query }, 35 }, 36 }) 37}