1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00

tidy code, link to wordconvert from README.md

This commit is contained in:
Elliott Stoneham 2016-09-23 15:31:42 +01:00
parent 788437ff64
commit a8a0ee7c6f
2 changed files with 16 additions and 3 deletions

View file

@ -36,6 +36,10 @@ Documize is compatible with Auth0 identity as a service.
<a width="150" height="50" href="https://auth0.com/?utm_source=oss&utm_medium=gp&utm_campaign=oss" target="_blank" alt="Single Sign On & Token Based Authentication - Auth0"><img width="150" height="50" alt="JWT Auth for open source projects" src="https://cdn.auth0.com/oss/badges/a0-badge-dark.png"/></a>
## Word Conversion to HTML
* [Code for ```wordconvert``` utility](https://github.com/documize/community/tree/master/cmd/wordconvert)
## Legal
https://documize.com

View file

@ -40,6 +40,7 @@ var token = flag.String("t", "", "authorization token (if you use your e-mail ad
var ignoreErrs = flag.Bool("e", false, "report errors on individual files, but continue")
var version = flag.Bool("version", false, "display the version of this code")
// does the file have a valid extension
func validXtn(fn string) bool {
lcfn := strings.ToLower(fn)
for _, xtn := range []string{".doc", ".docx", ".pdf"} {
@ -50,6 +51,7 @@ func validXtn(fn string) bool {
return false
}
// errCanContinue is the mechanism to print errors yet continue, if that command line option is chosen
func errCanContinue(can bool, err error) bool {
if err == nil {
return false
@ -95,7 +97,9 @@ func main() {
func processFiles(hclient *http.Client) {
for _, fileName := range flag.Args() {
if validXtn(fileName) {
if *verbose {
fmt.Println("processing", fileName)
}
@ -109,7 +113,7 @@ func processFiles(hclient *http.Client) {
bodyWriter := multipart.NewWriter(bodyBuf)
_, fn := path.Split(fileName)
fileWriter, err := bodyWriter.CreateFormFile("wordfile", fn)
fileWriter, err := bodyWriter.CreateFormFile("wordfile", fn) // name as expected by the API
if errCanContinue(true, err) {
continue
}
@ -127,7 +131,7 @@ func processFiles(hclient *http.Client) {
target := fmt.Sprintf(serverURLfmt, *server)
if *token != "" {
target += "?token=" + *token
target += "?token=" + *token // NOTE: after the preview phase, token will not be optional
}
req, err := http.NewRequest("POST",
@ -168,21 +172,26 @@ func processFiles(hclient *http.Client) {
continue
}
}
} else {
if *verbose {
fmt.Println("ignored", fileName)
}
}
}
}
// simple unzip
func unzipFiles(zipdata []byte, targetDir string) error {
rdr, err := zip.NewReader(bytes.NewReader(zipdata), int64(len(zipdata)))
if err != nil {
return err
}
if err := os.Mkdir(targetDir, 0777); err != nil && !os.IsExist(err) {
if err := os.Mkdir(targetDir, 0777); err != nil && !os.IsExist(err) { // make sure the target directory exists
return err
}