mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
The command-line 'note' also allows attachments.
This commit is contained in:
parent
c12acc0cc9
commit
15ac48280b
2
Makefile
2
Makefile
@ -44,7 +44,7 @@ http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
|
||||
snac.h
|
||||
httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
|
||||
xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h
|
||||
main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h
|
||||
main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
|
||||
mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
|
||||
xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
|
||||
snac.h
|
||||
|
@ -46,7 +46,7 @@ http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
|
||||
snac.h
|
||||
httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
|
||||
xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h
|
||||
main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h
|
||||
main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
|
||||
mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
|
||||
xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
|
||||
snac.h
|
||||
|
37
main.c
37
main.c
@ -5,6 +5,7 @@
|
||||
#include "xs_io.h"
|
||||
#include "xs_json.h"
|
||||
#include "xs_time.h"
|
||||
#include "xs_openssl.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
@ -450,7 +451,39 @@ int main(int argc, char *argv[])
|
||||
xs *content = NULL;
|
||||
xs *msg = NULL;
|
||||
xs *c_msg = NULL;
|
||||
char *in_reply_to = GET_ARGV();
|
||||
xs *attl = xs_list_new();
|
||||
char *fn = NULL;
|
||||
|
||||
/* iterate possible attachments */
|
||||
while ((fn = GET_ARGV())) {
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "rb")) != NULL) {
|
||||
/* get the file size and content */
|
||||
fseek(f, 0, SEEK_END);
|
||||
int sz = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
xs *atc = xs_readall(f);
|
||||
fclose(f);
|
||||
|
||||
char *ext = strrchr(fn, '.');
|
||||
xs *hash = xs_md5_hex(fn, strlen(fn));
|
||||
xs *id = xs_fmt("%s%s", hash, ext);
|
||||
xs *url = xs_fmt("%s/s/%s", snac.actor, id);
|
||||
|
||||
/* store */
|
||||
static_put(&snac, id, atc, sz);
|
||||
|
||||
xs *l = xs_list_new();
|
||||
|
||||
l = xs_list_append(l, url);
|
||||
l = xs_list_append(l, ""); /* alt text */
|
||||
|
||||
attl = xs_list_append(attl, l);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "Error opening '%s' as attachment\n", fn);
|
||||
}
|
||||
|
||||
if (strcmp(url, "-e") == 0) {
|
||||
/* get the content from an editor */
|
||||
@ -478,7 +511,7 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
content = xs_dup(url);
|
||||
|
||||
msg = msg_note(&snac, content, NULL, in_reply_to, NULL, 0);
|
||||
msg = msg_note(&snac, content, NULL, NULL, attl, 0);
|
||||
|
||||
c_msg = msg_create(&snac, msg);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user