From f676cd937fbe5f52dd5cf6c2125e74f354258bbc Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 28 Dec 2021 17:48:21 +0000 Subject: [PATCH] Add a little app to list apps. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3712 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/apps.json | 1 + apps/cory/apps/app.js | 24 ++++++++++++++++++++++++ src/main.c | 1 + src/ssb.export.c | 13 +++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 apps/cory/apps.json create mode 100644 apps/cory/apps/app.js diff --git a/apps/cory/apps.json b/apps/cory/apps.json new file mode 100644 index 00000000..2e29215d --- /dev/null +++ b/apps/cory/apps.json @@ -0,0 +1 @@ +{"type":"tildefriends-app","files":{"app.js":"&8DbkWJq+bDlPNGZGVWrlVyMzo+weV5GBfcleQSjIPjI=.sha256"}} \ No newline at end of file diff --git a/apps/cory/apps/app.js b/apps/cory/apps/app.js new file mode 100644 index 00000000..4181e70f --- /dev/null +++ b/apps/cory/apps/app.js @@ -0,0 +1,24 @@ +async function main() { + var apps = await core.apps(); + var doc = ` + + +

Apps

+ + + +` + app.setDocument(doc); +} + +main(); \ No newline at end of file diff --git a/src/main.c b/src/main.c index da387fec..bae46cb0 100644 --- a/src/main.c +++ b/src/main.c @@ -273,6 +273,7 @@ static int _tf_command_export(const char* file, int argc, char* argv[]) else { const char* k_export[] = { + "/~cory/apps", "/~cory/index", "/~cory/docs", }; diff --git a/src/ssb.export.c b/src/ssb.export.c index b241b7d1..00305209 100644 --- a/src/ssb.export.c +++ b/src/ssb.export.c @@ -22,6 +22,14 @@ static void _write_file(const char* path, void* blob, size_t size) } } +static void _make_dir(const char* path) +{ + if (mkdir(path, 0755) && errno != EEXIST) + { + printf("Failed to create directory %s: %s.\n", path, strerror(errno)); + } +} + void tf_ssb_export(tf_ssb_t* ssb, const char* key) { char user[256] = { 0 }; @@ -66,6 +74,11 @@ void tf_ssb_export(tf_ssb_t* ssb, const char* key) return; } char file_path[1024]; + _make_dir("apps/"); + snprintf(file_path, sizeof(file_path), "apps/%s", user); + _make_dir(file_path); + snprintf(file_path, sizeof(file_path), "apps/%s/%s", user, path); + _make_dir(file_path); snprintf(file_path, sizeof(file_path), "apps/%s/%s.json", user, path); _write_file(file_path, blob, size); JSContext* context = tf_ssb_get_context(ssb);