Oops. Cleanup.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4165 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-02-02 02:48:07 +00:00
parent e04d137af5
commit 6d6c41bffa

View File

@ -81,101 +81,6 @@ static void _tf_ssb_import_add_app(tf_ssb_t* ssb, const char* user, const char*
JS_FreeValue(context, apps); JS_FreeValue(context, apps);
} }
/*
static void _tf_ssb_import_file_read(uv_fs_t* req)
{
tf_import_file_t* file = req->data;
char id[k_id_base64_len];
if (req->result >= 0)
{
bool is_new = false;
bool is_app_json = false;
if (strcasecmp(file->name + strlen(file->name) - strlen(".json"), ".json") == 0)
{
JSContext* context = tf_ssb_get_context(file->ssb);
JSValue object = JS_ParseJSON(context, file->data, req->result, NULL);
JSValue type = JS_GetPropertyStr(context, object, "type");
if (!JS_IsUndefined(type))
{
const char* type_string = JS_ToCString(context, type);
if (type_string && strcmp(type_string, "tf-application") == 0)
{
is_app_json = true;
sqlite3_stmt* statement;
if (sqlite3_prepare(tf_ssb_get_db(file->ssb), "INSERT OR REPLACE INTO properties (id, key, value) VALUES ($1, 'path:' || $2, $3)", -1, &statement, NULL) == SQLITE_OK)
{
((char*)file->name)[strlen(file->name) - strlen(".json")] = '\0';
if (sqlite3_bind_text(statement, 1, file->user, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 2, file->name, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 3, id, -1, NULL) == SQLITE_OK &&
sqlite3_step(statement) == SQLITE_DONE)
{
if (sqlite3_changes(tf_ssb_get_db(file->ssb)))
{
printf("Registered %s path:%s as %s.\n", file->user, file->name, id);
}
_tf_ssb_import_add_app(file->ssb, file->user, file->name);
}
sqlite3_finalize(statement);
}
}
JS_FreeCString(context, type_string);
}
JS_FreeValue(context, object);
}
if (!is_app_json &&
tf_ssb_db_blob_store(file->ssb, (const uint8_t*)file->data, req->result, id, sizeof(id), &is_new) &&
is_new)
{
printf("Stored %s/%s as %s.\n", file->parent, file->name, id);
}
}
uv_fs_req_cleanup(req);
uv_fs_close(tf_ssb_get_loop(file->ssb), req, file->file, _tf_ssb_import_file_close);
}
static void _tf_ssb_import_file_open(uv_fs_t* req)
{
tf_import_file_t* file = req->data;
file->file = req->result;
uv_fs_req_cleanup(req);
uv_fs_read(tf_ssb_get_loop(file->ssb), req, file->file, &(uv_buf_t) { .base = file->data, .len = k_ssb_blob_bytes_max }, 1, 0, _tf_ssb_import_file_read);
}
static void _tf_ssb_import_register_app(tf_ssb_t* ssb, const char* use, const char* app, const char* id)
{
sqlite3_stmt* statement;
if (sqlite3_prepare(tf_ssb_get_db(file->ssb), "INSERT OR REPLACE INTO properties (id, key, value) VALUES ($1, 'path:' || $2, $3)", -1, &statement, NULL) == SQLITE_OK)
{
((char*)file->name)[strlen(file->name) - strlen(".json")] = '\0';
if (sqlite3_bind_text(statement, 1, file->user, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 2, file->name, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 3, id, -1, NULL) == SQLITE_OK &&
sqlite3_step(statement) == SQLITE_DONE)
{
if (sqlite3_changes(tf_ssb_get_db(file->ssb)))
{
printf("Registered %s path:%s as %s.\n", file->user, file->name, id);
}
_tf_ssb_import_add_app(file->ssb, file->user, file->name);
}
sqlite3_finalize(statement);
}
}
*/
typedef struct _tf_import_t
{
tf_ssb_t* ssb;
const char* user;
const char* parent;
uv_fs_t req;
} tf_import_t;
static char* _tf_ssb_import_read_file(uv_loop_t* loop, const char* path, size_t* out_size) static char* _tf_ssb_import_read_file(uv_loop_t* loop, const char* path, size_t* out_size)
{ {
char* data = NULL; char* data = NULL;