mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-28 19:49:54 +02:00
add category for file upload
This commit is contained in:
parent
f55505babb
commit
9f3d9a0f0c
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
@ -27,7 +28,7 @@ func (p *Piwigo) FileExists(md5 string) bool {
|
|||||||
return resp[md5] != nil
|
return resp[md5] != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piwigo) UploadChunks(filename string, nbJobs int) (*FileUploadResult, error) {
|
func (p *Piwigo) UploadChunks(filename string, nbJobs int, categoryId int) (*FileUploadResult, error) {
|
||||||
md5, err := Md5File(filename)
|
md5, err := Md5File(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -71,11 +72,14 @@ func (p *Piwigo) UploadChunks(filename string, nbJobs int) (*FileUploadResult, e
|
|||||||
var resp *FileUploadResult
|
var resp *FileUploadResult
|
||||||
data := &url.Values{}
|
data := &url.Values{}
|
||||||
data.Set("original_sum", md5)
|
data.Set("original_sum", md5)
|
||||||
data.Set("original_filename", filename)
|
data.Set("original_filename", filepath.Base(filename))
|
||||||
data.Set("check_uniqueness", "true")
|
data.Set("check_uniqueness", "true")
|
||||||
if exif != nil && exif.CreatedAt != nil {
|
if exif != nil && exif.CreatedAt != nil {
|
||||||
data.Set("date_creation", exif.CreatedAt.String())
|
data.Set("date_creation", exif.CreatedAt.String())
|
||||||
}
|
}
|
||||||
|
if categoryId > 0 {
|
||||||
|
data.Set("categories", fmt.Sprint(categoryId))
|
||||||
|
}
|
||||||
err = p.Post("pwg.images.add", data, &resp)
|
err = p.Post("pwg.images.add", data, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -10,8 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ImagesUploadCommand struct {
|
type ImagesUploadCommand struct {
|
||||||
Filename string `short:"f" long:"filename" description:"File to upload"`
|
Filename string `short:"f" long:"filename" description:"File to upload"`
|
||||||
NBJobs int `short:"j" long:"jobs" description:"Number of jobs" default:"1"`
|
NbJobs int `short:"j" long:"jobs" description:"Number of jobs" default:"1"`
|
||||||
|
CategoryId int `short:"c" long:"category" description:"Category to upload the file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ImagesUploadCommand) Execute(args []string) error {
|
func (c *ImagesUploadCommand) Execute(args []string) error {
|
||||||
@ -30,7 +31,7 @@ func (c *ImagesUploadCommand) Execute(args []string) error {
|
|||||||
return errors.New("unsupported file extension")
|
return errors.New("unsupported file extension")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := p.UploadChunks(c.Filename, c.NBJobs)
|
resp, err := p.UploadChunks(c.Filename, c.NbJobs, c.CategoryId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user