diff --git a/apps/cory/apps.json b/apps/cory/apps.json index 408747eb..fcb285d6 100644 --- a/apps/cory/apps.json +++ b/apps/cory/apps.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&OMzy1V2Z53ARpvUnFZ1BxsQr/Z8oQmFC678s/Hh6Gtc=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&qEJDfZ43KazIxiZl8OCKb2uaDOsPkxnIohEzQ1LLFpg=.sha256"}} \ No newline at end of file diff --git a/apps/cory/apps/app.js b/apps/cory/apps/app.js index 48e4a1c1..a9cf806f 100644 --- a/apps/cory/apps/app.js +++ b/apps/cory/apps/app.js @@ -21,7 +21,7 @@ async function main() { li.appendChild(a); } } - populate_apps('apps', '${core.user.credentials.session.name}', ${JSON.stringify(apps)}); + populate_apps('apps', '${core.user.credentials?.session?.name}', ${JSON.stringify(apps)}); populate_apps('core_apps', 'core', ${JSON.stringify(core_apps)}); ` diff --git a/core/core.js b/core/core.js index 3a4d8a29..12f35733 100644 --- a/core/core.js +++ b/core/core.js @@ -7,7 +7,7 @@ var gProcesses = {}; var gStatsTimer = false; var gGlobalSettings = { - index: "/~core/index", + index: "/~core/apps/", }; var kGlobalSettingsFile = "data/global/settings.json"; diff --git a/src/ssb.db.c b/src/ssb.db.c index 21976c91..c30ce94c 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -375,7 +375,7 @@ bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_ return result; } -bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* out_id, size_t out_id_size) +bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* out_id, size_t out_id_size, bool* out_new) { bool result = false; sqlite3* db = tf_ssb_get_db(ssb); @@ -411,7 +411,7 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* printf("prepare failed: %s\n", sqlite3_errmsg(db)); } - if (rows) + if (rows && !out_new) { printf("blob stored %s %zd => %d\n", id, size, result); } @@ -432,6 +432,10 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* { snprintf(out_id, out_id_size, "%s", id); } + if (out_new) + { + *out_new = rows != 0; + } return result; } diff --git a/src/ssb.db.h b/src/ssb.db.h index fa275038..c89c3fc2 100644 --- a/src/ssb.db.h +++ b/src/ssb.db.h @@ -9,7 +9,7 @@ void tf_ssb_db_init(tf_ssb_t* ssb); bool tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, JSValue val, const char* signature, bool sequence_before_author); bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size); bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size); -bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* out_id, size_t out_id_size); +bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* out_id, size_t out_id_size, bool* out_new); bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* author, int64_t sequence, char* out_message_id, size_t out_message_id_size, double* out_timestamp, char** out_content); bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, int64_t* out_sequence, char* out_message_id, size_t out_message_id_size); diff --git a/src/ssb.import.c b/src/ssb.import.c index 25b2dd1a..6167b4ef 100644 --- a/src/ssb.import.c +++ b/src/ssb.import.c @@ -78,9 +78,13 @@ static void _tf_ssb_import_file_read(uv_fs_t* req) char id[k_id_base64_len]; if (req->result >= 0) { - if (tf_ssb_db_blob_store(file->ssb, (const uint8_t*)file->data, req->result, id, sizeof(id))) + bool is_new = false; + if (tf_ssb_db_blob_store(file->ssb, (const uint8_t*)file->data, req->result, id, sizeof(id), &is_new)) { - printf("Stored %s/%s as %s.\n", file->parent, file->name, id); + if (is_new) + { + printf("Stored %s/%s as %s.\n", file->parent, file->name, id); + } if (strcasecmp(file->name + strlen(file->name) - strlen(".json"), ".json") == 0) { sqlite3_stmt* statement; @@ -92,7 +96,10 @@ static void _tf_ssb_import_file_read(uv_fs_t* req) sqlite3_bind_text(statement, 3, id, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_DONE) { - printf("Registered %s path:%s as %s.\n", file->user, file->name, id); + 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); diff --git a/src/ssb.js.c b/src/ssb.js.c index dffea0af..a62d1fad 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -178,7 +178,7 @@ static JSValue _tf_ssb_blobStore(JSContext* context, JSValueConst this_val, int if (JS_IsString(argv[0])) { const char* text = JS_ToCStringLen(context, &size, argv[0]); - if (tf_ssb_db_blob_store(ssb, (const uint8_t*)text, size, id, sizeof(id))) + if (tf_ssb_db_blob_store(ssb, (const uint8_t*)text, size, id, sizeof(id), NULL)) { result = JS_NewString(context, id); } @@ -186,7 +186,7 @@ static JSValue _tf_ssb_blobStore(JSContext* context, JSValueConst this_val, int } else if ((blob = tf_util_try_get_array_buffer(context, &size, argv[0])) != 0) { - if (tf_ssb_db_blob_store(ssb, blob, size, id, sizeof(id))) + if (tf_ssb_db_blob_store(ssb, blob, size, id, sizeof(id), NULL)) { result = JS_NewString(context, id); } @@ -201,7 +201,7 @@ static JSValue _tf_ssb_blobStore(JSContext* context, JSValueConst this_val, int blob = tf_util_try_get_array_buffer(context, &size, buffer); if (blob) { - if (tf_ssb_db_blob_store(ssb, blob, size, id, sizeof(id))) + if (tf_ssb_db_blob_store(ssb, blob, size, id, sizeof(id), NULL)) { result = JS_NewString(context, id); } diff --git a/src/ssb.tests.c b/src/ssb.tests.c index 37773351..de2a4e07 100644 --- a/src/ssb.tests.c +++ b/src/ssb.tests.c @@ -156,7 +156,7 @@ void tf_ssb_test_ssb(const tf_test_options_t* options) char blob_id[k_id_base64_len] = { 0 }; const char* k_blob = "Hello, blob!"; - b = tf_ssb_db_blob_store(ssb0, (const uint8_t*)k_blob, strlen(k_blob), blob_id, sizeof(blob_id)); + b = tf_ssb_db_blob_store(ssb0, (const uint8_t*)k_blob, strlen(k_blob), blob_id, sizeof(blob_id), NULL); assert(b); tf_ssb_append_post(ssb0, "Hello, world!");