forked from DokiDoki1103/tikuAdapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03f9500
commit 44fa60c
Showing
12 changed files
with
148 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package controller | ||
|
||
import ( | ||
"code.sajari.com/docconv/v2" | ||
"github.com/gin-gonic/gin" | ||
"github.com/itihey/tikuAdapter/pkg/global" | ||
"mime/multipart" | ||
"net/http" | ||
) | ||
|
||
// Parse 解析文件接口 | ||
func Parse(c *gin.Context) { | ||
file, err := c.FormFile("file") | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, global.ErrorParam) | ||
return | ||
|
||
} | ||
uploadedFile, err := file.Open() | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, global.ErrorParam) | ||
return | ||
} | ||
defer func(uploadedFile multipart.File) { | ||
err := uploadedFile.Close() | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, global.ErrorParam) | ||
return | ||
} | ||
}(uploadedFile) | ||
|
||
convert, err := docconv.Convert(uploadedFile, file.Header.Get("Content-Type"), true) | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, global.ErrorParseFile) | ||
return | ||
} | ||
|
||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, global.ErrorParseFile) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, convert) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package global | ||
|
||
var ( | ||
// ErrorParam 错误的参数 | ||
ErrorParam = NewError(400400, "错误的参数") | ||
|
||
// ErrorQuestionNotFound 题目未找到 | ||
ErrorQuestionNotFound = NewError(400404, "题目未找到") | ||
|
||
// ErrorParseFile 解析文件出错 | ||
ErrorParseFile = NewError(400500, "解析文件出错") | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package test | ||
|
||
import ( | ||
"code.sajari.com/docconv/v2" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestParseDoc(t *testing.T) { | ||
|
||
res, err := docconv.ConvertPath("test.pdf") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
fmt.Println(res) | ||
|
||
} |
Binary file not shown.
Binary file not shown.