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:
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>
|
<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
|
## Legal
|
||||||
|
|
||||||
https://documize.com
|
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 ignoreErrs = flag.Bool("e", false, "report errors on individual files, but continue")
|
||||||
var version = flag.Bool("version", false, "display the version of this code")
|
var version = flag.Bool("version", false, "display the version of this code")
|
||||||
|
|
||||||
|
// does the file have a valid extension
|
||||||
func validXtn(fn string) bool {
|
func validXtn(fn string) bool {
|
||||||
lcfn := strings.ToLower(fn)
|
lcfn := strings.ToLower(fn)
|
||||||
for _, xtn := range []string{".doc", ".docx", ".pdf"} {
|
for _, xtn := range []string{".doc", ".docx", ".pdf"} {
|
||||||
|
@ -50,6 +51,7 @@ func validXtn(fn string) bool {
|
||||||
return false
|
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 {
|
func errCanContinue(can bool, err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -95,7 +97,9 @@ func main() {
|
||||||
func processFiles(hclient *http.Client) {
|
func processFiles(hclient *http.Client) {
|
||||||
|
|
||||||
for _, fileName := range flag.Args() {
|
for _, fileName := range flag.Args() {
|
||||||
|
|
||||||
if validXtn(fileName) {
|
if validXtn(fileName) {
|
||||||
|
|
||||||
if *verbose {
|
if *verbose {
|
||||||
fmt.Println("processing", fileName)
|
fmt.Println("processing", fileName)
|
||||||
}
|
}
|
||||||
|
@ -109,7 +113,7 @@ func processFiles(hclient *http.Client) {
|
||||||
bodyWriter := multipart.NewWriter(bodyBuf)
|
bodyWriter := multipart.NewWriter(bodyBuf)
|
||||||
|
|
||||||
_, fn := path.Split(fileName)
|
_, 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) {
|
if errCanContinue(true, err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -127,7 +131,7 @@ func processFiles(hclient *http.Client) {
|
||||||
|
|
||||||
target := fmt.Sprintf(serverURLfmt, *server)
|
target := fmt.Sprintf(serverURLfmt, *server)
|
||||||
if *token != "" {
|
if *token != "" {
|
||||||
target += "?token=" + *token
|
target += "?token=" + *token // NOTE: after the preview phase, token will not be optional
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST",
|
req, err := http.NewRequest("POST",
|
||||||
|
@ -168,21 +172,26 @@ func processFiles(hclient *http.Client) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if *verbose {
|
if *verbose {
|
||||||
fmt.Println("ignored", fileName)
|
fmt.Println("ignored", fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simple unzip
|
||||||
func unzipFiles(zipdata []byte, targetDir string) error {
|
func unzipFiles(zipdata []byte, targetDir string) error {
|
||||||
|
|
||||||
rdr, err := zip.NewReader(bytes.NewReader(zipdata), int64(len(zipdata)))
|
rdr, err := zip.NewReader(bytes.NewReader(zipdata), int64(len(zipdata)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue