Add code to refetch account activity pub data older than 3 days, pass mime-type thru to api Status results
parent
0f6e78ae89
commit
2c1ade6461
@ -0,0 +1,48 @@
|
||||
#include "fetch.h"
|
||||
|
||||
// Submodules
|
||||
#include "http/client/client.h"
|
||||
#include "util/format.h"
|
||||
|
||||
// Standard Library
|
||||
#include <stdio.h>
|
||||
|
||||
bool pull_remote_file( const char* filename, const char* uri )
|
||||
{
|
||||
printf( "* Fetching %s\n", uri );
|
||||
char tmp_filename[512];
|
||||
FILE* f = fopen(format(tmp_filename,512,"%s.tmp",filename),"w");
|
||||
|
||||
long status_code = -1;
|
||||
const void* request[] = {
|
||||
HTTP_REQ_URL, uri,
|
||||
HTTP_REQ_HEADER, "Accept: application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||
HTTP_REQ_OUTFILE, f,
|
||||
HTTP_REQ_RESULT_STATUS, &status_code,
|
||||
NULL,
|
||||
};
|
||||
if( !http_client_do( request ) ) {
|
||||
printf( "! Unable to fetch %s\n", uri );
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf( "status_code = %ld\n", status_code );
|
||||
if( status_code == 200 ) {
|
||||
// success
|
||||
fclose(f);
|
||||
rename(tmp_filename,filename);
|
||||
return true;
|
||||
} else if( status_code == 401 ) {
|
||||
// Not Authorized
|
||||
printf( "TODO: perform signed fetch\n" );
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Failure
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool pull_remote_file( const char* filename, const char* uri );
|
||||
|
Loading…
Reference in new issue