From d40577efcbb5c607d96cba97e89c4a37d5514796 Mon Sep 17 00:00:00 2001 From: Junpei Kawamoto Date: Sat, 15 Apr 2023 00:55:25 -0600 Subject: [PATCH] add GET /api/v1/images --- README.md | 23 ++ client/operations/get_images_parameters.go | 458 +++++++++++++++++++++ client/operations/get_images_responses.go | 182 ++++++++ client/operations/operations_client.go | 39 ++ example_test.go | 10 + models/image.go | 76 ++++ models/image_stats.go | 65 +++ models/images_response.go | 162 ++++++++ openapi.yaml | 120 +++++- 9 files changed, 1134 insertions(+), 1 deletion(-) create mode 100644 client/operations/get_images_parameters.go create mode 100644 client/operations/get_images_responses.go create mode 100644 models/image_stats.go create mode 100644 models/images_response.go diff --git a/README.md b/README.md index 5254ef6..fad6015 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,29 @@ See the [API reference](https://github.com/civitai/civitai/wiki/REST-API-Referen the details of parameters and responses. +### GetImages API +This example fetches 3 images and prints their usernames and URLs. + +```go +func ExampleGetImages() { + ctx := context.Background() + + res, err := client.Default.Operations.GetImages( + operations.NewGetImagesParamsWithContext(ctx).WithLimit(swag.Int64(3))) + if err != nil { + log.Fatal(err) + } + + for _, v := range res.Payload.Items { + log.Println(v.Username, v.URL) + } +} +``` + +See the [API reference](https://github.com/civitai/civitai/wiki/REST-API-Reference#get-apiv1images) to find +the details of parameters and responses. + + ### GetModels API This example fetches 3 models and prints their name, ID, and tags. diff --git a/client/operations/get_images_parameters.go b/client/operations/get_images_parameters.go new file mode 100644 index 0000000..63f4d3d --- /dev/null +++ b/client/operations/get_images_parameters.go @@ -0,0 +1,458 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetImagesParams creates a new GetImagesParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewGetImagesParams() *GetImagesParams { + return &GetImagesParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetImagesParamsWithTimeout creates a new GetImagesParams object +// with the ability to set a timeout on a request. +func NewGetImagesParamsWithTimeout(timeout time.Duration) *GetImagesParams { + return &GetImagesParams{ + timeout: timeout, + } +} + +// NewGetImagesParamsWithContext creates a new GetImagesParams object +// with the ability to set a context for a request. +func NewGetImagesParamsWithContext(ctx context.Context) *GetImagesParams { + return &GetImagesParams{ + Context: ctx, + } +} + +// NewGetImagesParamsWithHTTPClient creates a new GetImagesParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetImagesParamsWithHTTPClient(client *http.Client) *GetImagesParams { + return &GetImagesParams{ + HTTPClient: client, + } +} + +/* +GetImagesParams contains all the parameters to send to the API endpoint + + for the get images operation. + + Typically these are written to a http.Request. +*/ +type GetImagesParams struct { + + /* Limit. + + The number of results to be returned per page. + + Format: int64 + Default: 100 + */ + Limit *int64 + + /* ModelID. + + The ID of a model to get images from (model gallery). + + Format: int64 + */ + ModelID *int64 + + /* ModelVersionID. + + The ID of a model version to get images from (model gallery filtered to version). + + Format: int64 + */ + ModelVersionID *int64 + + /* Nsfw. + + Filter to images that contain mature content flags or not (undefined returns both). + */ + Nsfw *bool + + /* Page. + + The page from which to start fetching creators. + + Format: int64 + */ + Page *int64 + + /* Period. + + The time frame in which the images will be sorted. + */ + Period *string + + /* PostID. + + The ID of a post to get images from. + + Format: int64 + */ + PostID *int64 + + /* Sort. + + The order in which you wish to sort the results. + */ + Sort *string + + /* Username. + + Filter to images from a specific user. + */ + Username *string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get images params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetImagesParams) WithDefaults() *GetImagesParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get images params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetImagesParams) SetDefaults() { + var ( + limitDefault = int64(100) + ) + + val := GetImagesParams{ + Limit: &limitDefault, + } + + val.timeout = o.timeout + val.Context = o.Context + val.HTTPClient = o.HTTPClient + *o = val +} + +// WithTimeout adds the timeout to the get images params +func (o *GetImagesParams) WithTimeout(timeout time.Duration) *GetImagesParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get images params +func (o *GetImagesParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get images params +func (o *GetImagesParams) WithContext(ctx context.Context) *GetImagesParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get images params +func (o *GetImagesParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get images params +func (o *GetImagesParams) WithHTTPClient(client *http.Client) *GetImagesParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get images params +func (o *GetImagesParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithLimit adds the limit to the get images params +func (o *GetImagesParams) WithLimit(limit *int64) *GetImagesParams { + o.SetLimit(limit) + return o +} + +// SetLimit adds the limit to the get images params +func (o *GetImagesParams) SetLimit(limit *int64) { + o.Limit = limit +} + +// WithModelID adds the modelID to the get images params +func (o *GetImagesParams) WithModelID(modelID *int64) *GetImagesParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get images params +func (o *GetImagesParams) SetModelID(modelID *int64) { + o.ModelID = modelID +} + +// WithModelVersionID adds the modelVersionID to the get images params +func (o *GetImagesParams) WithModelVersionID(modelVersionID *int64) *GetImagesParams { + o.SetModelVersionID(modelVersionID) + return o +} + +// SetModelVersionID adds the modelVersionId to the get images params +func (o *GetImagesParams) SetModelVersionID(modelVersionID *int64) { + o.ModelVersionID = modelVersionID +} + +// WithNsfw adds the nsfw to the get images params +func (o *GetImagesParams) WithNsfw(nsfw *bool) *GetImagesParams { + o.SetNsfw(nsfw) + return o +} + +// SetNsfw adds the nsfw to the get images params +func (o *GetImagesParams) SetNsfw(nsfw *bool) { + o.Nsfw = nsfw +} + +// WithPage adds the page to the get images params +func (o *GetImagesParams) WithPage(page *int64) *GetImagesParams { + o.SetPage(page) + return o +} + +// SetPage adds the page to the get images params +func (o *GetImagesParams) SetPage(page *int64) { + o.Page = page +} + +// WithPeriod adds the period to the get images params +func (o *GetImagesParams) WithPeriod(period *string) *GetImagesParams { + o.SetPeriod(period) + return o +} + +// SetPeriod adds the period to the get images params +func (o *GetImagesParams) SetPeriod(period *string) { + o.Period = period +} + +// WithPostID adds the postID to the get images params +func (o *GetImagesParams) WithPostID(postID *int64) *GetImagesParams { + o.SetPostID(postID) + return o +} + +// SetPostID adds the postId to the get images params +func (o *GetImagesParams) SetPostID(postID *int64) { + o.PostID = postID +} + +// WithSort adds the sort to the get images params +func (o *GetImagesParams) WithSort(sort *string) *GetImagesParams { + o.SetSort(sort) + return o +} + +// SetSort adds the sort to the get images params +func (o *GetImagesParams) SetSort(sort *string) { + o.Sort = sort +} + +// WithUsername adds the username to the get images params +func (o *GetImagesParams) WithUsername(username *string) *GetImagesParams { + o.SetUsername(username) + return o +} + +// SetUsername adds the username to the get images params +func (o *GetImagesParams) SetUsername(username *string) { + o.Username = username +} + +// WriteToRequest writes these params to a swagger request +func (o *GetImagesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.Limit != nil { + + // query param limit + var qrLimit int64 + + if o.Limit != nil { + qrLimit = *o.Limit + } + qLimit := swag.FormatInt64(qrLimit) + if qLimit != "" { + + if err := r.SetQueryParam("limit", qLimit); err != nil { + return err + } + } + } + + if o.ModelID != nil { + + // query param modelId + var qrModelID int64 + + if o.ModelID != nil { + qrModelID = *o.ModelID + } + qModelID := swag.FormatInt64(qrModelID) + if qModelID != "" { + + if err := r.SetQueryParam("modelId", qModelID); err != nil { + return err + } + } + } + + if o.ModelVersionID != nil { + + // query param modelVersionId + var qrModelVersionID int64 + + if o.ModelVersionID != nil { + qrModelVersionID = *o.ModelVersionID + } + qModelVersionID := swag.FormatInt64(qrModelVersionID) + if qModelVersionID != "" { + + if err := r.SetQueryParam("modelVersionId", qModelVersionID); err != nil { + return err + } + } + } + + if o.Nsfw != nil { + + // query param nsfw + var qrNsfw bool + + if o.Nsfw != nil { + qrNsfw = *o.Nsfw + } + qNsfw := swag.FormatBool(qrNsfw) + if qNsfw != "" { + + if err := r.SetQueryParam("nsfw", qNsfw); err != nil { + return err + } + } + } + + if o.Page != nil { + + // query param page + var qrPage int64 + + if o.Page != nil { + qrPage = *o.Page + } + qPage := swag.FormatInt64(qrPage) + if qPage != "" { + + if err := r.SetQueryParam("page", qPage); err != nil { + return err + } + } + } + + if o.Period != nil { + + // query param period + var qrPeriod string + + if o.Period != nil { + qrPeriod = *o.Period + } + qPeriod := qrPeriod + if qPeriod != "" { + + if err := r.SetQueryParam("period", qPeriod); err != nil { + return err + } + } + } + + if o.PostID != nil { + + // query param postId + var qrPostID int64 + + if o.PostID != nil { + qrPostID = *o.PostID + } + qPostID := swag.FormatInt64(qrPostID) + if qPostID != "" { + + if err := r.SetQueryParam("postId", qPostID); err != nil { + return err + } + } + } + + if o.Sort != nil { + + // query param sort + var qrSort string + + if o.Sort != nil { + qrSort = *o.Sort + } + qSort := qrSort + if qSort != "" { + + if err := r.SetQueryParam("sort", qSort); err != nil { + return err + } + } + } + + if o.Username != nil { + + // query param username + var qrUsername string + + if o.Username != nil { + qrUsername = *o.Username + } + qUsername := qrUsername + if qUsername != "" { + + if err := r.SetQueryParam("username", qUsername); err != nil { + return err + } + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/operations/get_images_responses.go b/client/operations/get_images_responses.go new file mode 100644 index 0000000..56f2b88 --- /dev/null +++ b/client/operations/get_images_responses.go @@ -0,0 +1,182 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/jkawamoto/go-civitai/models" +) + +// GetImagesReader is a Reader for the GetImages structure. +type GetImagesReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetImagesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetImagesOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewGetImagesDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewGetImagesOK creates a GetImagesOK with default headers values +func NewGetImagesOK() *GetImagesOK { + return &GetImagesOK{} +} + +/* +GetImagesOK describes a response with status code 200, with default header values. + +A list of images. +*/ +type GetImagesOK struct { + Payload *models.ImagesResponse +} + +// IsSuccess returns true when this get images o k response has a 2xx status code +func (o *GetImagesOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get images o k response has a 3xx status code +func (o *GetImagesOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get images o k response has a 4xx status code +func (o *GetImagesOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get images o k response has a 5xx status code +func (o *GetImagesOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get images o k response a status code equal to that given +func (o *GetImagesOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the get images o k response +func (o *GetImagesOK) Code() int { + return 200 +} + +func (o *GetImagesOK) Error() string { + return fmt.Sprintf("[GET /images][%d] getImagesOK %+v", 200, o.Payload) +} + +func (o *GetImagesOK) String() string { + return fmt.Sprintf("[GET /images][%d] getImagesOK %+v", 200, o.Payload) +} + +func (o *GetImagesOK) GetPayload() *models.ImagesResponse { + return o.Payload +} + +func (o *GetImagesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.ImagesResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetImagesDefault creates a GetImagesDefault with default headers values +func NewGetImagesDefault(code int) *GetImagesDefault { + return &GetImagesDefault{ + _statusCode: code, + } +} + +/* +GetImagesDefault describes a response with status code -1, with default header values. + +Error Response +*/ +type GetImagesDefault struct { + _statusCode int + + Payload *models.StandardError +} + +// IsSuccess returns true when this get images default response has a 2xx status code +func (o *GetImagesDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this get images default response has a 3xx status code +func (o *GetImagesDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this get images default response has a 4xx status code +func (o *GetImagesDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this get images default response has a 5xx status code +func (o *GetImagesDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this get images default response a status code equal to that given +func (o *GetImagesDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the get images default response +func (o *GetImagesDefault) Code() int { + return o._statusCode +} + +func (o *GetImagesDefault) Error() string { + return fmt.Sprintf("[GET /images][%d] getImages default %+v", o._statusCode, o.Payload) +} + +func (o *GetImagesDefault) String() string { + return fmt.Sprintf("[GET /images][%d] getImages default %+v", o._statusCode, o.Payload) +} + +func (o *GetImagesDefault) GetPayload() *models.StandardError { + return o.Payload +} + +func (o *GetImagesDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.StandardError) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/client/operations/operations_client.go b/client/operations/operations_client.go index 18980fd..0b043a5 100644 --- a/client/operations/operations_client.go +++ b/client/operations/operations_client.go @@ -30,6 +30,8 @@ type ClientOption func(*runtime.ClientOperation) type ClientService interface { GetCreators(params *GetCreatorsParams, opts ...ClientOption) (*GetCreatorsOK, error) + GetImages(params *GetImagesParams, opts ...ClientOption) (*GetImagesOK, error) + GetModel(params *GetModelParams, opts ...ClientOption) (*GetModelOK, error) GetModelVersion(params *GetModelVersionParams, opts ...ClientOption) (*GetModelVersionOK, error) @@ -80,6 +82,43 @@ func (a *Client) GetCreators(params *GetCreatorsParams, opts ...ClientOption) (* return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +GetImages get images API +*/ +func (a *Client) GetImages(params *GetImagesParams, opts ...ClientOption) (*GetImagesOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetImagesParams() + } + op := &runtime.ClientOperation{ + ID: "getImages", + Method: "GET", + PathPattern: "/images", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetImagesReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*GetImagesOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*GetImagesDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* GetModel get model API */ diff --git a/example_test.go b/example_test.go index c2dbd22..4c0fd7b 100644 --- a/example_test.go +++ b/example_test.go @@ -30,6 +30,16 @@ func Example() { log.Println(v.Username, v.ModelCount) } + // List images + images, err := client.Default.Operations.GetImages( + operations.NewGetImagesParamsWithContext(ctx).WithLimit(swag.Int64(3))) + if err != nil { + log.Fatal(err) + } + for _, v := range images.Payload.Items { + log.Println(v.Username, v.URL) + } + // List models. models, err := client.Default.Operations.GetModels( operations.NewGetModelsParamsWithContext(ctx).WithLimit(swag.Int64(3))) diff --git a/models/image.go b/models/image.go index a2c30b1..8f2db4c 100644 --- a/models/image.go +++ b/models/image.go @@ -20,6 +20,11 @@ import ( // swagger:model Image type Image struct { + // The date the image was posted. + // Example: 2023-04-06T09:14:50.762Z + // Format: date-time + CreatedAt strfmt.DateTime `json:"createdAt,omitempty"` + // generation process GenerationProcess string `json:"generationProcess,omitempty"` @@ -29,6 +34,9 @@ type Image struct { // The original height of the image. Height int64 `json:"height,omitempty"` + // The id of the image. + ID int64 `json:"id,omitempty"` + // The generation params of the image. Meta *ImageMetadata `json:"meta,omitempty"` @@ -38,10 +46,16 @@ type Image struct { // Whether or not the image is NSFW (note: if the model is NSFW, treat all images on the model as NSFW). Nsfw bool `json:"nsfw,omitempty"` + // The ID of the post the image belongs to. + PostID int64 `json:"postId,omitempty"` + // scanned at // Format: date-time ScannedAt strfmt.DateTime `json:"scannedAt,omitempty"` + // stats + Stats *ImageStats `json:"stats,omitempty"` + // tags Tags []*ImageTag `json:"tags"` @@ -51,6 +65,9 @@ type Image struct { // user Id UserID int64 `json:"userId,omitempty"` + // The username of the creator. + Username string `json:"username,omitempty"` + // The original width of the image. Width int64 `json:"width,omitempty"` } @@ -59,6 +76,10 @@ type Image struct { func (m *Image) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateCreatedAt(formats); err != nil { + res = append(res, err) + } + if err := m.validateMeta(formats); err != nil { res = append(res, err) } @@ -67,6 +88,10 @@ func (m *Image) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateStats(formats); err != nil { + res = append(res, err) + } + if err := m.validateTags(formats); err != nil { res = append(res, err) } @@ -77,6 +102,18 @@ func (m *Image) Validate(formats strfmt.Registry) error { return nil } +func (m *Image) validateCreatedAt(formats strfmt.Registry) error { + if swag.IsZero(m.CreatedAt) { // not required + return nil + } + + if err := validate.FormatOf("createdAt", "body", "date-time", m.CreatedAt.String(), formats); err != nil { + return err + } + + return nil +} + func (m *Image) validateMeta(formats strfmt.Registry) error { if swag.IsZero(m.Meta) { // not required return nil @@ -108,6 +145,25 @@ func (m *Image) validateScannedAt(formats strfmt.Registry) error { return nil } +func (m *Image) validateStats(formats strfmt.Registry) error { + if swag.IsZero(m.Stats) { // not required + return nil + } + + if m.Stats != nil { + if err := m.Stats.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("stats") + } + return err + } + } + + return nil +} + func (m *Image) validateTags(formats strfmt.Registry) error { if swag.IsZero(m.Tags) { // not required return nil @@ -142,6 +198,10 @@ func (m *Image) ContextValidate(ctx context.Context, formats strfmt.Registry) er res = append(res, err) } + if err := m.contextValidateStats(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateTags(ctx, formats); err != nil { res = append(res, err) } @@ -168,6 +228,22 @@ func (m *Image) contextValidateMeta(ctx context.Context, formats strfmt.Registry return nil } +func (m *Image) contextValidateStats(ctx context.Context, formats strfmt.Registry) error { + + if m.Stats != nil { + if err := m.Stats.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("stats") + } + return err + } + } + + return nil +} + func (m *Image) contextValidateTags(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.Tags); i++ { diff --git a/models/image_stats.go b/models/image_stats.go new file mode 100644 index 0000000..81fe351 --- /dev/null +++ b/models/image_stats.go @@ -0,0 +1,65 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// ImageStats image stats +// +// swagger:model ImageStats +type ImageStats struct { + + // The number of comment reactions. + CommentCount int64 `json:"commentCount,omitempty"` + + // The number of cry reactions. + CryCount int64 `json:"cryCount,omitempty"` + + // dislike count + DislikeCount int64 `json:"dislikeCount,omitempty"` + + // The number of heart reactions. + HeartCount int64 `json:"heartCount,omitempty"` + + // The number of laugh reactions. + LaughCount int64 `json:"laughCount,omitempty"` + + // The number of like reactions. + LikeCount int64 `json:"likeCount,omitempty"` +} + +// Validate validates this image stats +func (m *ImageStats) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this image stats based on context it is used +func (m *ImageStats) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *ImageStats) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ImageStats) UnmarshalBinary(b []byte) error { + var res ImageStats + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/images_response.go b/models/images_response.go new file mode 100644 index 0000000..5f56a60 --- /dev/null +++ b/models/images_response.go @@ -0,0 +1,162 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// ImagesResponse images response +// +// swagger:model ImagesResponse +type ImagesResponse struct { + + // items + Items []*Image `json:"items"` + + // metadata + Metadata *Metadata `json:"metadata,omitempty"` +} + +// Validate validates this images response +func (m *ImagesResponse) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMetadata(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ImagesResponse) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *ImagesResponse) validateMetadata(formats strfmt.Registry) error { + if swag.IsZero(m.Metadata) { // not required + return nil + } + + if m.Metadata != nil { + if err := m.Metadata.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("metadata") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("metadata") + } + return err + } + } + + return nil +} + +// ContextValidate validate this images response based on the context it is used +func (m *ImagesResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMetadata(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ImagesResponse) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *ImagesResponse) contextValidateMetadata(ctx context.Context, formats strfmt.Registry) error { + + if m.Metadata != nil { + if err := m.Metadata.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("metadata") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("metadata") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *ImagesResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ImagesResponse) UnmarshalBinary(b []byte) error { + var res ImagesResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/openapi.yaml b/openapi.yaml index 61e8186..450f56c 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1,7 +1,7 @@ swagger: "2.0" info: title: Civitai API - version: v1 + version: "2023-04-14" host: civitai.com basePath: /api/v1 schemes: @@ -46,6 +46,73 @@ paths: description: Error Response schema: $ref: "#/definitions/StandardError" + /images: + get: + operationId: getImages + parameters: + - name: limit + type: integer + format: int64 + in: query + description: The number of results to be returned per page. + default: 100 + minimum: 0 + maximum: 200 + - name: postId + type: integer + format: int64 + in: query + description: The ID of a post to get images from. + - name: modelId + type: integer + format: int64 + in: query + description: The ID of a model to get images from (model gallery). + - name: modelVersionId + type: integer + format: int64 + in: query + description: The ID of a model version to get images from (model gallery filtered to version). + - name: username + type: string + in: query + description: Filter to images from a specific user. + - name: nsfw + type: boolean + in: query + description: Filter to images that contain mature content flags or not (undefined returns both). + - name: sort + type: string + enum: + - Most Reactions + - Most Comments + - Newest + in: query + description: The order in which you wish to sort the results. + - name: period + type: string + enum: + - AllTime + - Year + - Month + - Week + - Day + in: query + description: The time frame in which the images will be sorted. + - name: page + type: integer + format: int64 + in: query + description: The page from which to start fetching creators. + responses: + 200: + description: A list of images. + schema: + $ref: "#/definitions/ImagesResponse" + default: + description: Error Response + schema: + $ref: "#/definitions/StandardError" /models: get: operationId: getModels @@ -245,6 +312,14 @@ definitions: $ref: "#/definitions/Creator" metadata: $ref: "#/definitions/Metadata" + ImagesResponse: + properties: + items: + type: array + items: + $ref: "#/definitions/Image" + metadata: + $ref: "#/definitions/Metadata" ModelsResponse: properties: items: @@ -469,6 +544,10 @@ definitions: example: CC4CD6EA2B502C61B4BD86CA5C4B07AF269877877CEC7FB14EEAE846555CED1E Image: properties: + id: + type: integer + format: int64 + description: The id of the image. url: type: string description: The url for the image. @@ -487,9 +566,23 @@ definitions: hash: type: string description: The blurhash of the image. + createdAt: + type: string + format: date-time + description: The date the image was posted. + example: 2023-04-06T09:14:50.762Z + postId: + type: integer + format: int64 + description: The ID of the post the image belongs to. + stats: + $ref: "#/definitions/ImageStats" meta: $ref: "#/definitions/ImageMetadata" description: The generation params of the image. + username: + type: string + description: The username of the creator. userId: type: integer format: int64 @@ -541,6 +634,31 @@ definitions: type: boolean type: type: string + ImageStats: + properties: + cryCount: + type: integer + format: int64 + description: The number of cry reactions. + laughCount: + type: integer + format: int64 + description: The number of laugh reactions. + likeCount: + type: integer + format: int64 + description: The number of like reactions. + dislikeCount: + type: integer + format: int64 + heartCount: + type: integer + format: int64 + description: The number of heart reactions. + commentCount: + type: integer + format: int64 + description: The number of comment reactions. Tag: properties: name: