mirror of
https://github.com/documize/community.git
synced 2025-07-18 20:59:43 +02:00
tidy code, link to wordconvert from README.md
This commit is contained in:
parent
788437ff64
commit
a8a0ee7c6f
2 changed files with 16 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue