2017-06-28 13:42:38 +02:00
package controllers
2017-05-05 16:39:15 +02:00
2017-05-08 11:18:49 +02:00
import (
2017-05-05 16:39:15 +02:00
"html"
2017-05-08 11:18:49 +02:00
"net/http"
2017-05-05 16:39:15 +02:00
"strconv"
2017-05-11 05:04:11 +02:00
"strings"
2017-05-08 11:18:49 +02:00
"time"
2017-05-17 07:58:40 +02:00
"github.com/NyaaPantsu/nyaa/config"
2017-06-29 13:15:23 +02:00
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents"
2017-07-02 18:00:12 +02:00
"github.com/NyaaPantsu/nyaa/models/users"
2017-07-02 16:54:55 +02:00
"github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/utils/crypto"
"github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/search"
2017-07-02 18:00:12 +02:00
"github.com/NyaaPantsu/nyaa/utils/search/structs"
2017-07-02 16:54:55 +02:00
"github.com/NyaaPantsu/nyaa/utils/upload"
2017-07-02 18:00:12 +02:00
"github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
"github.com/NyaaPantsu/nyaa/utils/validator/user"
2017-06-28 13:42:38 +02:00
"github.com/gin-gonic/gin"
2017-05-05 16:39:15 +02:00
)
2017-05-25 21:54:58 +02:00
// APIHandler : Controller for api request on torrent list
2017-06-28 13:42:38 +02:00
func APIHandler ( c * gin . Context ) {
t := c . Query ( "t" )
2017-06-16 01:30:09 +02:00
if t != "" {
2017-06-28 13:42:38 +02:00
RSSTorznabHandler ( c )
2017-06-16 01:30:09 +02:00
} else {
2017-06-28 13:42:38 +02:00
page := c . Param ( "page" )
2017-07-02 18:00:12 +02:00
whereParams := structs . WhereParams { }
req := upload . TorrentsRequest { }
2017-05-09 17:09:45 +02:00
2017-06-28 13:42:38 +02:00
contentType := c . Request . Header . Get ( "Content-Type" )
2017-06-16 01:30:09 +02:00
if contentType == "application/json" {
2017-06-28 13:42:38 +02:00
c . Bind ( & req )
2017-05-09 18:54:12 +02:00
2017-06-16 01:30:09 +02:00
if req . MaxPerPage == 0 {
2017-05-31 04:21:57 +02:00
req . MaxPerPage = config . Conf . Navigation . TorrentsPerPage
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
}
2017-06-16 01:30:09 +02:00
if req . Page <= 0 {
req . Page = 1
}
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
2017-06-16 01:30:09 +02:00
whereParams = req . ToParams ( )
} else {
var err error
2017-06-28 13:42:38 +02:00
maxString := c . Query ( "max" )
2017-06-16 01:30:09 +02:00
if maxString != "" {
req . MaxPerPage , err = strconv . Atoi ( maxString )
if ! log . CheckError ( err ) {
req . MaxPerPage = config . Conf . Navigation . TorrentsPerPage
}
} else {
req . MaxPerPage = config . Conf . Navigation . TorrentsPerPage
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
}
2017-06-16 01:30:09 +02:00
req . Page = 1
if page != "" {
req . Page , err = strconv . Atoi ( html . EscapeString ( page ) )
if ! log . CheckError ( err ) {
2017-06-28 13:42:38 +02:00
c . AbortWithError ( http . StatusInternalServerError , err )
2017-06-16 01:30:09 +02:00
return
}
if req . Page <= 0 {
2017-06-28 13:42:38 +02:00
NotFoundHandler ( c )
2017-06-16 01:30:09 +02:00
return
}
2017-05-20 01:10:16 +02:00
}
2017-05-09 18:54:12 +02:00
}
2017-05-09 17:09:45 +02:00
2017-07-02 18:00:12 +02:00
torrents , nbTorrents , err := torrents . Find ( whereParams , req . MaxPerPage , req . MaxPerPage * ( req . Page - 1 ) )
2017-06-16 01:30:09 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
c . AbortWithError ( http . StatusInternalServerError , err )
2017-06-16 01:30:09 +02:00
return
}
2017-05-08 11:18:49 +02:00
2017-07-02 18:00:12 +02:00
b := upload . APIResultJSON {
2017-07-01 23:09:35 +02:00
Torrents : models . APITorrentsToJSON ( torrents ) ,
2017-06-16 01:30:09 +02:00
}
b . QueryRecordCount = req . MaxPerPage
b . TotalRecordCount = nbTorrents
2017-06-28 13:42:38 +02:00
c . Header ( "Content-Type" , "application/json" )
c . JSON ( http . StatusOK , b )
2017-06-16 01:30:09 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
c . AbortWithError ( http . StatusInternalServerError , err )
2017-06-16 01:30:09 +02:00
return
}
2017-05-05 16:39:15 +02:00
}
}
2017-05-25 21:54:58 +02:00
// APIViewHandler : Controller for viewing a torrent by its ID
2017-06-28 13:42:38 +02:00
func APIViewHandler ( c * gin . Context ) {
2017-07-02 18:00:12 +02:00
id , _ := strconv . ParseInt ( c . Param ( "id" ) , 10 , 32 )
2017-05-05 16:39:15 +02:00
2017-07-02 18:00:12 +02:00
torrent , err := torrents . FindByID ( uint ( id ) )
2017-05-23 05:18:25 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
c . AbortWithError ( http . StatusNotFound , err )
2017-05-23 05:18:25 +02:00
return
}
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
b := torrent . ToJSON ( )
2017-06-28 13:42:38 +02:00
c . Header ( "Content-Type" , "application/json" )
c . JSON ( http . StatusOK , b )
2017-05-06 23:46:53 +02:00
}
2017-05-08 11:18:49 +02:00
2017-05-25 21:54:58 +02:00
// APIViewHeadHandler : Controller for checking a torrent by its ID
2017-06-28 13:42:38 +02:00
func APIViewHeadHandler ( c * gin . Context ) {
id , err := strconv . ParseInt ( c . Param ( "id" ) , 10 , 32 )
2017-05-23 05:18:19 +02:00
if err != nil {
return
}
2017-07-02 18:00:12 +02:00
_ , err = torrents . FindRawByID ( uint ( id ) )
2017-05-23 05:18:19 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
NotFoundHandler ( c )
2017-05-23 05:18:19 +02:00
return
}
2017-06-28 13:42:38 +02:00
c . Writer . Write ( nil )
2017-05-23 05:18:19 +02:00
}
2017-05-25 21:54:58 +02:00
// APIUploadHandler : Controller for uploading a torrent with api
2017-06-28 13:42:38 +02:00
func APIUploadHandler ( c * gin . Context ) {
token := c . Request . Header . Get ( "Authorization" )
username := c . PostForm ( "username" )
2017-07-02 18:00:12 +02:00
user , _ , _ , _ , err := users . FindByAPITokenAndName ( token , username )
2017-06-28 13:42:38 +02:00
messages := msg . GetMessages ( c )
2017-05-20 01:10:16 +02:00
2017-06-05 15:19:25 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_api_token" )
2017-06-05 15:19:25 +02:00
}
2017-07-02 18:00:12 +02:00
if ! user . CanUpload ( ) {
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "uploads_disabled" )
2017-05-08 11:18:49 +02:00
}
2017-05-20 01:10:16 +02:00
2017-05-11 05:04:11 +02:00
if user . ID == 0 {
2017-07-02 18:00:12 +02:00
messages . AddErrorT ( "errors" , "error_api_token" )
2017-06-05 15:19:25 +02:00
}
2017-05-28 06:22:39 +02:00
2017-06-13 08:01:57 +02:00
if ! messages . HasErrors ( ) {
2017-07-02 18:00:12 +02:00
uploadForm := torrentValidator . TorrentRequest { }
2017-06-28 13:42:38 +02:00
contentType := c . Request . Header . Get ( "Content-Type" )
if contentType != "application/json" && ! strings . HasPrefix ( contentType , "multipart/form-data" ) && contentType != "application/x-www-form-urlencoded" {
2017-07-02 18:00:12 +02:00
// TODO What should we do here ? uploadForm is empty so we shouldn't
2017-06-13 08:01:57 +02:00
// create a torrent from it
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_content_type_post" )
2017-06-13 08:01:57 +02:00
}
// As long as the right content-type is sent, formValue is smart enough to parse it
2017-07-02 18:00:12 +02:00
err = upload . ExtractInfo ( c , & uploadForm )
2017-06-13 08:01:57 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . Error ( err )
2017-06-05 15:19:25 +02:00
}
2017-05-26 01:48:14 +02:00
2017-06-13 08:01:57 +02:00
if ! messages . HasErrors ( ) {
2017-07-02 18:00:12 +02:00
uploadForm . Status = models . TorrentStatusNormal
if uploadForm . Remake { // overrides trusted
uploadForm . Status = models . TorrentStatusRemake
2017-06-13 08:01:57 +02:00
} else if user . IsTrusted ( ) {
2017-07-02 18:00:12 +02:00
uploadForm . Status = models . TorrentStatusTrusted
2017-06-13 08:01:57 +02:00
}
2017-07-02 18:00:12 +02:00
err = torrents . ExistOrDelete ( uploadForm . Infohash , user )
2017-06-05 15:19:25 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . Error ( err )
2017-06-13 08:01:57 +02:00
}
if ! messages . HasErrors ( ) {
2017-07-02 18:00:12 +02:00
torrent , err := torrents . Create ( user , & uploadForm )
if err != nil {
messages . Error ( err )
2017-06-13 08:01:57 +02:00
}
messages . AddInfoT ( "infos" , "torrent_uploaded" )
2017-07-02 18:00:12 +02:00
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c , torrent . ToJSON ( ) )
2017-06-05 15:19:25 +02:00
return
2017-05-26 01:48:14 +02:00
}
}
2017-05-11 05:25:41 +02:00
}
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c )
2017-05-08 11:18:49 +02:00
}
2017-05-09 19:37:39 +02:00
2017-05-25 21:54:58 +02:00
// APIUpdateHandler : Controller for updating a torrent with api
2017-05-19 04:55:59 +02:00
// FIXME Impossible to update a torrent uploaded by user 0
2017-06-28 13:42:38 +02:00
func APIUpdateHandler ( c * gin . Context ) {
token := c . Request . Header . Get ( "Authorization" )
username := c . PostForm ( "username" )
2017-07-02 18:00:12 +02:00
user , _ , _ , _ , err := users . FindByAPITokenAndName ( token , username )
2017-06-28 13:42:38 +02:00
messages := msg . GetMessages ( c )
2017-05-20 01:10:16 +02:00
2017-06-05 15:19:25 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_api_token" )
2017-06-05 15:19:25 +02:00
}
2017-07-02 18:00:12 +02:00
if ! user . CanUpload ( ) {
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "uploads_disabled" )
2017-05-09 20:54:50 +02:00
}
2017-06-05 15:19:25 +02:00
if user . ID == 0 {
2017-07-02 18:00:12 +02:00
messages . AddErrorT ( "errors" , "error_api_token" )
2017-06-05 15:19:25 +02:00
}
2017-06-28 13:42:38 +02:00
contentType := c . Request . Header . Get ( "Content-Type" )
if contentType != "application/json" && ! strings . HasPrefix ( contentType , "multipart/form-data" ) && contentType != "application/x-www-form-urlencoded" {
2017-06-05 15:19:25 +02:00
// TODO What should we do here ? upload is empty so we shouldn't
// create a torrent from it
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_content_type_post" )
2017-06-05 15:19:25 +02:00
}
2017-07-02 18:00:12 +02:00
update := torrentValidator . UpdateRequest { }
err = upload . ExtractEditInfo ( c , & update . Update )
2017-06-05 15:19:25 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . Error ( err )
2017-06-05 15:19:25 +02:00
}
2017-06-13 08:01:57 +02:00
if ! messages . HasErrors ( ) {
2017-07-02 18:00:12 +02:00
c . Bind ( & update )
torrent , err := torrents . FindByID ( update . ID )
if err != nil {
messages . AddErrorTf ( "errors" , "torrent_not_exist" , strconv . Itoa ( int ( update . ID ) ) )
2017-06-13 08:01:57 +02:00
}
if torrent . UploaderID != 0 && torrent . UploaderID != user . ID { //&& user.Status != mod
2017-07-02 18:00:12 +02:00
messages . AddErrorT ( "errors" , "fail_torrent_update" )
2017-06-13 08:01:57 +02:00
}
2017-07-02 18:00:12 +02:00
upload . UpdateTorrent ( & update , & torrent , user ) . Update ( false )
2017-05-09 20:54:50 +02:00
}
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c )
2017-05-09 19:58:35 +02:00
}
2017-05-25 21:54:58 +02:00
// APISearchHandler : Controller for searching with api
2017-06-28 13:42:38 +02:00
func APISearchHandler ( c * gin . Context ) {
page := c . Param ( "page" )
2017-05-25 02:42:35 +02:00
// db params url
var err error
pagenum := 1
if page != "" {
pagenum , err = strconv . Atoi ( html . EscapeString ( page ) )
if ! log . CheckError ( err ) {
2017-06-28 13:42:38 +02:00
c . AbortWithError ( http . StatusInternalServerError , err )
2017-05-25 02:42:35 +02:00
return
}
if pagenum <= 0 {
2017-06-28 13:42:38 +02:00
NotFoundHandler ( c )
2017-05-25 02:42:35 +02:00
return
}
}
2017-06-28 13:42:38 +02:00
_ , torrents , _ , err := search . SearchByQueryWithUser ( c , pagenum )
2017-05-25 02:42:35 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
c . AbortWithError ( http . StatusInternalServerError , err )
2017-05-25 02:42:35 +02:00
return
}
2017-07-01 23:09:35 +02:00
b := models . APITorrentsToJSON ( torrents )
2017-06-28 13:42:38 +02:00
c . JSON ( http . StatusOK , b )
2017-05-25 02:42:35 +02:00
}
2017-06-13 08:01:57 +02:00
// APILoginHandler : Login with API
// This is not an OAuth api like and shouldn't be used for anything except getting the API Token in order to not store a password
2017-06-28 13:42:38 +02:00
func APILoginHandler ( c * gin . Context ) {
2017-07-02 18:00:12 +02:00
b := userValidator . LoginForm { }
2017-06-28 13:42:38 +02:00
messages := msg . GetMessages ( c )
contentType := c . Request . Header . Get ( "Content-type" )
2017-06-13 08:01:57 +02:00
if ! strings . HasPrefix ( contentType , "application/json" ) && ! strings . HasPrefix ( contentType , "multipart/form-data" ) && ! strings . HasPrefix ( contentType , "application/x-www-form-urlencoded" ) {
// TODO What should we do here ? upload is empty so we shouldn't
// create a torrent from it
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_content_type_post" )
2017-06-13 08:01:57 +02:00
}
2017-06-28 13:42:38 +02:00
c . Bind ( & b )
2017-07-02 18:00:12 +02:00
validator . ValidateForm ( & b , messages )
2017-06-13 08:01:57 +02:00
if ! messages . HasErrors ( ) {
2017-07-02 18:00:12 +02:00
user , _ , errorUser := cookies . CreateUserAuthentication ( c , & b )
2017-06-13 08:01:57 +02:00
if errorUser == nil {
messages . AddInfo ( "infos" , "Logged" )
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c , user . ToJSON ( ) )
2017-06-13 08:01:57 +02:00
return
}
2017-06-28 13:42:38 +02:00
messages . Error ( errorUser )
2017-06-13 08:01:57 +02:00
}
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c )
2017-06-13 08:01:57 +02:00
}
// APIRefreshTokenHandler : Refresh Token with API
2017-06-28 13:42:38 +02:00
func APIRefreshTokenHandler ( c * gin . Context ) {
token := c . Request . Header . Get ( "Authorization" )
username := c . PostForm ( "username" )
2017-07-02 18:00:12 +02:00
user , _ , _ , _ , err := users . FindByAPITokenAndName ( token , username )
2017-06-28 13:42:38 +02:00
messages := msg . GetMessages ( c )
2017-06-13 08:01:57 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_api_token" )
2017-06-13 08:01:57 +02:00
}
if ! messages . HasErrors ( ) {
user . APIToken , _ = crypto . GenerateRandomToken32 ( )
user . APITokenExpiry = time . Unix ( 0 , 0 )
2017-07-02 18:00:12 +02:00
_ , errorUser := user . UpdateRaw ( )
2017-06-13 08:01:57 +02:00
if errorUser == nil {
messages . AddInfoT ( "infos" , "profile_updated" )
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c , user . ToJSON ( ) )
2017-06-13 08:01:57 +02:00
return
}
2017-06-28 13:42:38 +02:00
messages . Error ( errorUser )
2017-06-13 08:01:57 +02:00
}
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c )
2017-06-13 08:01:57 +02:00
}
// APICheckTokenHandler : Check Token with API
2017-06-28 13:42:38 +02:00
func APICheckTokenHandler ( c * gin . Context ) {
token := c . Request . Header . Get ( "Authorization" )
username := c . PostForm ( "username" )
2017-07-02 18:00:12 +02:00
user , _ , _ , _ , err := users . FindByAPITokenAndName ( token , username )
2017-06-28 13:42:38 +02:00
messages := msg . GetMessages ( c )
2017-06-13 08:01:57 +02:00
if err != nil {
2017-06-28 13:42:38 +02:00
messages . AddErrorT ( "errors" , "error_api_token" )
2017-06-13 08:01:57 +02:00
} else {
messages . AddInfo ( "infos" , "Logged" )
}
2017-06-28 13:42:38 +02:00
apiResponseHandler ( c , user . ToJSON ( ) )
2017-06-13 08:01:57 +02:00
}
// This function is the global response for every simple Post Request API
// Please use it. Responses are of the type:
// {ok: bool, [errors | infos]: ArrayOfString [, data: ArrayOfObjects, all_errors: ArrayOfObjects]}
// To send errors or infos, you just need to use the Messages Util
2017-06-28 13:42:38 +02:00
func apiResponseHandler ( c * gin . Context , obj ... interface { } ) {
messages := msg . GetMessages ( c )
c . Header ( "Content-Type" , "application/json" )
2017-06-13 08:01:57 +02:00
2017-06-28 13:42:38 +02:00
var mapOk map [ string ] interface { }
2017-06-13 08:01:57 +02:00
if ! messages . HasErrors ( ) {
2017-06-28 13:42:38 +02:00
mapOk = map [ string ] interface { } { "ok" : true , "infos" : messages . GetInfos ( "infos" ) }
2017-06-13 08:01:57 +02:00
if len ( obj ) > 0 {
mapOk [ "data" ] = obj
if len ( obj ) == 1 {
mapOk [ "data" ] = obj [ 0 ]
}
}
} else { // We need to show error messages
2017-06-28 13:42:38 +02:00
mapOk := map [ string ] interface { } { "ok" : false , "errors" : messages . GetErrors ( "errors" ) , "all_errors" : messages . GetAllErrors ( ) }
2017-06-13 08:01:57 +02:00
if len ( obj ) > 0 {
2017-06-28 13:42:38 +02:00
mapOk [ "data" ] = obj
2017-06-13 08:01:57 +02:00
if len ( obj ) == 1 {
2017-06-28 13:42:38 +02:00
mapOk [ "data" ] = obj [ 0 ]
2017-06-13 08:01:57 +02:00
}
}
if len ( messages . GetAllErrors ( ) ) > 0 && len ( messages . GetErrors ( "errors" ) ) == 0 {
2017-06-28 13:42:38 +02:00
mapOk [ "errors" ] = "errors"
2017-06-13 08:01:57 +02:00
}
}
2017-06-28 13:42:38 +02:00
c . JSON ( http . StatusOK , mapOk )
2017-06-13 08:01:57 +02:00
}