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