diff --git a/README.md b/README.md index b1a2ba2..2678f5b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ LaTeX online compiler. More info at www.github.com/kpym/lol. Available options: -s, --service string Service can be laton or ytotex. + --url string The base url for the service. If empty, the default URL is used. -c, --compiler string One of pdflatex,xelatex or lualatex. For ytotex platex, uplatex and context are also available. (default "pdflatex") diff --git a/app/app.go b/app/app.go index 97df0fa..c06e131 100644 --- a/app/app.go +++ b/app/app.go @@ -50,6 +50,7 @@ func Help() { // InitFlag define the CLI flags. func InitFlags() { pflag.StringP("service", "s", "", "Service can be laton or ytotex.") + pflag.String("url", "", "The base url for the service. If empty, the default URL is used.") pflag.StringP("compiler", "c", "pdflatex", "One of pdflatex,xelatex or lualatex.\nFor ytotex platex, uplatex and context are also available.\n") pflag.BoolP("force", "f", false, "Do not use the laton cache. Force compile. Ignored by ytotech.") pflag.StringP("biblio", "b", "", "Can be bibtex or biber for ytotex. Not used by laton.") @@ -151,6 +152,14 @@ func GetParameters(params *builder.Parameters) error { // TODO : choose the fastest ? params.Service = "laton" } + if params.Url == "" { + switch params.Service { + case "laton": + params.Url = "https://texlive2020.latexonline.cc" + case "ytotech": + params.Url = "https://latex.ytotech.com" + } + } // check if the input is piped fi, err := os.Stdin.Stat() if err == nil { diff --git a/builder/builder.go b/builder/builder.go index 397ef96..e7e87c9 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -33,6 +33,7 @@ func (files *Files) String() string { type Parameters struct { Log log.Logger Service string + Url string Compiler string Force bool Biblio string @@ -46,6 +47,7 @@ type Parameters struct { func (p *Parameters) String() string { w := new(strings.Builder) fmt.Fprintln(w, "Service: ", p.Service) + fmt.Fprintln(w, "Url: ", p.Url) fmt.Fprintln(w, "Compiler: ", p.Compiler) if p.Force { fmt.Fprintln(w, "Force: ", p.Force) diff --git a/builder/laton/laton.go b/builder/laton/laton.go index 5926b93..13aa1f1 100644 --- a/builder/laton/laton.go +++ b/builder/laton/laton.go @@ -95,7 +95,7 @@ func newTarRequest(params builder.Parameters, tardata []byte) (*http.Request, er urlParams.Add("command", params.Compiler) // return the request - httpReq, err := http.NewRequest("POST", "https://texlive2020.latexonline.cc/data?"+urlParams.Encode(), body) + httpReq, err := http.NewRequest("POST", params.Url+"/data?"+urlParams.Encode(), body) if err != nil { return nil, err } diff --git a/builder/ytotech/ytotech.go b/builder/ytotech/ytotech.go index 30977f5..e70c1f5 100644 --- a/builder/ytotech/ytotech.go +++ b/builder/ytotech/ytotech.go @@ -1,19 +1,21 @@ // ytotech package provides a builder.Builder interface to latex.ytotech.com service. // The request send to latex.ytotech.com is a single json that looks like this // ```json -// { -// "compiler": "pdflatex", -// "resources": [ -// { -// "main": true, -// "file": "...base64 encoded file..." -// }, -// { -// "path": "logo.png", -// "file": "...base64 encoded file..." -// } -// ] -// } +// +// { +// "compiler": "pdflatex", +// "resources": [ +// { +// "main": true, +// "file": "...base64 encoded file..." +// }, +// { +// "path": "logo.png", +// "file": "...base64 encoded file..." +// } +// ] +// } +// // ``` package ytotech @@ -77,7 +79,7 @@ func (y *ytotech) BuildPDF(req builder.Request) ([]byte, error) { // prepare the json to submit body := strings.NewReader(reqToJson(req)) // send comile request - resp, err := http.Post("https://latex.ytotech.com/builds/sync", "application/json", body) + resp, err := http.Post(req.Parameters.Url+"/builds/sync", "application/json", body) if err != nil { return nil, err }