moved piwigo authentication
This commit is contained in:
parent
a194e2f5ae
commit
6064e94858
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure"
|
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure"
|
||||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo"
|
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo"
|
||||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo/authentication"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
@ -50,7 +49,7 @@ func Run() {
|
|||||||
logErrorAndExit(err, 6)
|
logErrorAndExit(err, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = authentication.Logout(context.Piwigo)
|
_ = piwigo.Logout(context.Piwigo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureContext() (*appContext, error) {
|
func configureContext() (*appContext, error) {
|
||||||
@ -81,7 +80,7 @@ func configureContext() (*appContext, error) {
|
|||||||
|
|
||||||
func loginToPiwigoAndConfigureContext(context *appContext) error {
|
func loginToPiwigoAndConfigureContext(context *appContext) error {
|
||||||
logrus.Infoln("Logging in to piwigo and getting chunk size configuration for uploads")
|
logrus.Infoln("Logging in to piwigo and getting chunk size configuration for uploads")
|
||||||
err := authentication.Login(context.Piwigo)
|
err := piwigo.Login(context.Piwigo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ func loginToPiwigoAndConfigureContext(context *appContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initializeUploadChunkSize(context *appContext) error {
|
func initializeUploadChunkSize(context *appContext) error {
|
||||||
userStatus, err := authentication.GetStatus(context.Piwigo)
|
userStatus, err := piwigo.GetStatus(context.Piwigo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,44 @@
|
|||||||
package authentication
|
package piwigo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Login(context *piwigo.PiwigoContext) error {
|
type LoginResponse struct {
|
||||||
|
Status string `json:"stat"`
|
||||||
|
Result bool `json:"result"`
|
||||||
|
ErrorNumber int `json:"err"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetStatusResponse struct {
|
||||||
|
Status string `json:"stat"`
|
||||||
|
Result struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Theme string `json:"theme"`
|
||||||
|
Language string `json:"language"`
|
||||||
|
PwgToken string `json:"pwg_token"`
|
||||||
|
Charset string `json:"charset"`
|
||||||
|
CurrentDatetime string `json:"current_datetime"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
AvailableSizes []string `json:"available_sizes"`
|
||||||
|
UploadFileTypes string `json:"upload_file_types"`
|
||||||
|
UploadFormChunkSize int `json:"upload_form_chunk_size"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LogoutResponse struct {
|
||||||
|
Status string `json:"stat"`
|
||||||
|
Result bool `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Login(context *PiwigoContext) error {
|
||||||
logrus.Debugf("Logging in to %s using user %s", context.Url, context.Username)
|
logrus.Debugf("Logging in to %s using user %s", context.Url, context.Username)
|
||||||
|
|
||||||
if !strings.HasPrefix(context.Url, "https") {
|
if !strings.HasPrefix(context.Url, "https") {
|
||||||
@ -44,7 +72,7 @@ func Login(context *piwigo.PiwigoContext) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Logout(context *piwigo.PiwigoContext) error {
|
func Logout(context *PiwigoContext) error {
|
||||||
logrus.Debugf("Logging out from %s", context.Url)
|
logrus.Debugf("Logging out from %s", context.Url)
|
||||||
|
|
||||||
formData := url.Values{}
|
formData := url.Values{}
|
||||||
@ -70,7 +98,7 @@ func Logout(context *piwigo.PiwigoContext) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStatus(context *piwigo.PiwigoContext) (*GetStatusResponse, error) {
|
func GetStatus(context *PiwigoContext) (*GetStatusResponse, error) {
|
||||||
logrus.Debugln("Getting current login state...")
|
logrus.Debugln("Getting current login state...")
|
||||||
|
|
||||||
formData := url.Values{}
|
formData := url.Values{}
|
@ -1,30 +0,0 @@
|
|||||||
package authentication
|
|
||||||
|
|
||||||
type LoginResponse struct {
|
|
||||||
Status string `json:"stat"`
|
|
||||||
Result bool `json:"result"`
|
|
||||||
ErrorNumber int `json:"err"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetStatusResponse struct {
|
|
||||||
Status string `json:"stat"`
|
|
||||||
Result struct {
|
|
||||||
Username string `json:"username"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Theme string `json:"theme"`
|
|
||||||
Language string `json:"language"`
|
|
||||||
PwgToken string `json:"pwg_token"`
|
|
||||||
Charset string `json:"charset"`
|
|
||||||
CurrentDatetime string `json:"current_datetime"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
AvailableSizes []string `json:"available_sizes"`
|
|
||||||
UploadFileTypes string `json:"upload_file_types"`
|
|
||||||
UploadFormChunkSize int `json:"upload_form_chunk_size"`
|
|
||||||
} `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type LogoutResponse struct {
|
|
||||||
Status string `json:"stat"`
|
|
||||||
Result bool `json:"result"`
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user