general cleanup

This commit is contained in:
2026-05-01 13:16:04 +01:00
parent 3163a1e7bd
commit a9be1e568d
5 changed files with 36 additions and 30 deletions
+5
View File
@@ -1,3 +1,6 @@
#ifndef CURL_UTILS_H
#define CURL_UtILS_H
#include "e621.h"
typedef struct {
@@ -7,3 +10,5 @@ typedef struct {
} curl_url_peram_t;
char *CurlGet(char *path, curl_url_peram_t *perams, int peram_count, e6_auth_t auth);
#endif
+21 -25
View File
@@ -1,11 +1,12 @@
#ifndef E621_HPP
#define E621_HPP
#ifndef E621_H
#define E621_H
// Includes
#include <stdbool.h>
// Defines
// Defines
#ifndef E621_HOST
#define E621_HOST "https://e621.net"
#endif
@@ -14,6 +15,7 @@
#define E621_URL_BUF_SIZE 2048
#endif
// Structs
typedef struct {
unsigned int width;
@@ -44,24 +46,8 @@ typedef struct {
} e6_score_t;
typedef struct {
char **general;
int general_count;
char **artist;
int artist_count;
char **contributor;
int contributor_count;
char **copyright;
int copyright_count;
char **character;
int character_count;
char **species;
int species_count;
char **invalid;
int invalid_count;
char **meta;
int meta_count;
char **lore;
int lore_count;
char **tags;
int tags_count;
} e6_tags_t;
typedef struct flags_t {
@@ -78,6 +64,7 @@ typedef struct {
bool has_children;
bool has_active_children;
int *children;
int children_count;
} e6_relationships_t;
typedef struct {
@@ -88,9 +75,16 @@ typedef struct {
e6_preview_t preview;
e6_sample_t sample;
e6_score_t score;
e6_tags_t tags;
char **locked_tags;
int locked_tags_count;
e6_tags_t general_tags;
e6_tags_t artist_tags;
e6_tags_t character_tags;
e6_tags_t species_tags;
e6_tags_t copyright_tags;
e6_tags_t contributor_tags;
e6_tags_t invalid_tags;
e6_tags_t meta_tags;
e6_tags_t lore_tags;
e6_tags_t locked_tags;
unsigned int change_seq;
e6_flags_t flags;
char *rating;
@@ -111,7 +105,9 @@ typedef struct {
float project_ver;
} e6_auth_t;
// Functions
e6_post_t *E6List(e6_auth_t auth, char **tags, int tags_count, unsigned int page, unsigned int limit);
e6_post_t *E6List(e6_auth_t auth, e6_tags_t tags, unsigned int page, unsigned int limit);
#endif
+3
View File
@@ -100,5 +100,8 @@ char *CurlGet(char *path, curl_url_peram_t *perams, int peram_count, e6_auth_t a
return NULL;
}
free(headers);
free(url);
curl_easy_cleanup(curl);
return buffer.data;
}
+3 -3
View File
@@ -8,7 +8,7 @@
#include "curl_utils.h"
e6_post_t *E6List(e6_auth_t auth, char **tags, int tags_count, unsigned int page, unsigned int limit) {
e6_post_t *E6List(e6_auth_t auth, e6_tags_t tags, unsigned int page, unsigned int limit) {
char *path = "/posts.json";
curl_url_peram_t perams[3];
@@ -23,8 +23,8 @@ e6_post_t *E6List(e6_auth_t auth, char **tags, int tags_count, unsigned int page
perams[1].count = 1;
perams[2].key = "tags";
perams[2].value = tags;
perams[2].count = tags_count;
perams[2].value = tags.tags;
perams[2].count = tags.tags_count;
char *data = CurlGet(path, perams, 3, auth);
printf("%s\n", data);
+3 -1
View File
@@ -1,9 +1,11 @@
#include "e621.h"
#include "creds.h" // provides the API key and username
int main(int argc, char *argv[]) {
e6_auth_t auth = { USERNAME, API_KEY, "c621", 0.1 };
e6_tags_t tags = {(char* []){ "rating:safe", "cat" }, 2};
E6List(auth, (char* []){ "order:score", "cat" }, 2, 1, 3);
E6List(auth, tags, 1, 1);
return 0;
}