Dear Gitlab users, due to maintenance reasons, Gitlab will not be available on Thursday 30.09.2021 from 5:00 pm to approximately 5:30 pm.

Commit 95bafd7b authored by Andreas Wagner's avatar Andreas Wagner
Browse files

Add err msgs and ztoken rqmt to POST request path.

parent 998356ed
......@@ -64,6 +64,18 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
log.Tracef(" Request could not be parsed as multipart form. Maybe a raw upload?")
}
// Read zenodo token from Form field or Query parameter
ztoken := c.PostForm("ztoken")
if ztoken == "" {
ztoken = c.Query("ztoken")
}
if ztoken == "" {
log.Errorf("POST request without token submitted. Too insecure - ignoring...")
AbortMsg(401, tei2zenodo.NewError("errBadRequest", fmt.Sprintf("POST request without token submitted. Too insecure - ignoring..."), 401, nil), c)
return
}
conf.Zenodo.Token = ztoken
// Read filename from Form field, Query parameter or File field
filename := c.PostForm("filename")
if filename == "" {
......@@ -293,12 +305,14 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
// AbortMsg returns an error code and message.
func AbortMsg(code int, err *tei2zenodo.Error, c *gin.Context) {
c.String(code, "Something has gone wrong, causing a %v error.\n", code)
// A custom error page with HTML templates can be shown by c.HTML()
// A JSON object would be given like c.JSON(404, gin.H{"code": "PAGE_NOT_FOUND", "message": "Seite nicht gefunden"})
if err != nil {
c.Error(err)
}
/*
c.String(code, "Something has gone wrong, causing a %v error.\n", code)
if err != nil {
c.Error(err)
}
*/
c.JSON(code, gin.H{"type": err.Typ, "title": err.Message, "detail": err.ErrorVal, "status": code})
c.Abort()
}
......
......@@ -76,16 +76,14 @@
<p>Example for the form-style POST API.</p>
<form action="api/v1/file" method="post" enctype="multipart/form-data" style="background: #F5F5F5; padding: 1em; border: 1px solid #9F9F9F;">
<div class="control-group">
<!--
<div class="controls">
<label>
Filename: <input type="text" name="filename" value="filename"/>
Zenodo token: <input type="text" name="ztoken" value=""/>
</label>
</div>
-->
<div class="controls">
<label>
Publish zenodo deposit: <input type="checkbox" name="publish" value="doPublish"/>
Publish zenodo deposit: <input type="checkbox" name="doPublish"/>
</label>
</div>
<div class="controls">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment