rip out WIP images/ in favor of inline image data in a POI location publish

This commit is contained in:
Jan-Piet Mens
2024-12-14 11:03:11 +01:00
parent 59bc46fbe4
commit 6071384acd
4 changed files with 0 additions and 67 deletions

View File

@@ -11,6 +11,5 @@ As mentioned earlier, data is stored in files, and these files are relative to `
* `photos/` optional; contains the binary photos from a card.
* `rec/` the Recorder data proper. One subdirectory per user, one subdirectory therein per device. Data files are named `YYYY-MM.rec` (e.g. `2015-08.rec` for the data accumulated during the month of August 2015. The content is a time stamp obtained from `tst` (or _now_, i.e. `time(0)` if there is no `tst` in the payload) followed by record type and message payload.
* `waypoints/` contains a directory per user and device. Therein are individual files named by a timestamp with the JSON payload of published (i.e. shared) waypoints. The file names are timestamps because the `tst` of a waypoint is its key. If a user publishes all waypoints from a device (Publish Waypoints), the payload is stored in this directory as `username-device.otrw`. (Note, that this is the JSON [waypoints import format](http://owntracks.org/booklet/tech/json/#_typewaypoints).) You can use this `.otrw` file to restore the waypoints on your device by copying to the device and opening it in OwnTracks.
* `images/`, optional, contains a directory per user and device. Therein are individual files named by a timestamp with binary image data received with a `"_type":"image", and an adjacent file with a `.json` suffix which contains all other elements received along with that message. (We strip the base64-encoded `image` element from the publish as we already have the binary image data.)
You should definitely **not** modify or touch these files: they remain under the control of the Recorder. You can of course, remove old `.rec` files if they consume too much space.

View File

@@ -135,61 +135,6 @@ int do_info(void *userdata, UT_string *username, UT_string *device, JsonNode *js
return (rc);
}
/*
* Handle inline images: extract the base64-encoded image, decode and store in
* file. Remove the `image' element from the JSON (it's very large) and write
* the remaining elements into a .json file adjacent to the actual image file.
*/
int do_image(void *userdata, UT_string *username, UT_string *device, JsonNode *json)
{
struct udata *ud = (struct udata *)userdata;
JsonNode *j;
if ((j = json_find_member(json, "image")) != NULL) {
if (j->tag == JSON_STRING) {
char *b64 = j->string_;
size_t imglen = strlen(b64);
unsigned char *img;
FILE *fp;
time_t tics = time(0);
if ((img = base64_decode(b64, &imglen)) == NULL) {
olog(LOG_ERR, "Cannot decode image base64");
return false;
}
if ((fp = pathn("wb", "images", username, device, "jpg", tics)) != NULL) {
fwrite(img, sizeof(char), imglen, fp);
fclose(fp);
}
/* Delete image data element and write remaining as JSON */
if ((fp = pathn("wb", "images", username, device, "json", tics)) != NULL) {
if ((j = json_find_member(json, "image")) != NULL) {
json_delete(j);
char *js = json_stringify(json, " ");
if (js) {
fprintf(fp, "%s\n", js);
free(js);
}
fclose(fp);
}
}
}
}
if (ud->verbose) {
if ((j = json_find_member(json, "imageName")) != NULL) {
if (j->tag == JSON_STRING) {
printf("* IMAGE: %s-%s %s\n", UB(username), UB(device), j->string_);
}
}
}
return true;
}
#ifdef WITH_MQTT
void publish(struct udata *userdata, char *topic, char *payload)
{
@@ -936,7 +881,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
else if (!strcmp(j->string_, "beacon")) _type = T_BEACON;
else if (!strcmp(j->string_, "card")) _type = T_CARD;
else if (!strcmp(j->string_, "cmd")) _type = T_CMD;
else if (!strcmp(j->string_, "image")) _type = T_IMAGE;
else if (!strcmp(j->string_, "lwt")) _type = T_LWT;
else if (!strcmp(j->string_, "steps")) _type = T_STEPS;
else if (!strcmp(j->string_, "status")) _type = T_STATUS;
@@ -1005,12 +949,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
case T_CONFIG:
config_dump(ud, username, device, payload);
goto cleanup;
case T_IMAGE:
// ud->norec = true; /* FIXME */
do_image(ud, username, device, json);
// char *js = json_stringify(json, NULL);
// putrec(ud, now, reltopic, username, device, js);
goto cleanup;
case T_WAYPOINT:
case T_TRANSITION:
case T_LOCATION:

View File

@@ -41,7 +41,6 @@ typedef enum {
T_REQUEST,
#endif
T_STATUS,
T_IMAGE,
} payload_type;
JsonNode *lister(char *username, char *device, time_t s_lo, time_t s_hi, int reverse);

3
util.c
View File

@@ -531,9 +531,6 @@ FILE *pathn(char *mode, char *prefix, UT_string *user, UT_string *device, char *
if (strcmp(prefix, "rec") == 0) {
utstring_printf(path, "/%s.%s", yyyymm(epoch), suffix);
} else if (strcmp(prefix, "images") == 0) {
utstring_printf(path, "/%s-%s-%s-%ld.%s", UB(user), UB(device), yyyymm(epoch), epoch, suffix);
} else {
utstring_printf(path, "/%s-%s.%s", UB(user), UB(device), suffix);
}