mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-24 00:53:36 +05:00
feat: dynamic filenames for backup/debug (#207)
* feat: generate dynamic filenames for JSON file downloads (backup and debug) based on hostname and timestamp * fix: threadsafe getFilename
This commit is contained in:
@@ -241,7 +241,17 @@ protected:
|
|||||||
|
|
||||||
doc.shrinkToFit();
|
doc.shrinkToFit();
|
||||||
|
|
||||||
this->webServer->sendHeader(F("Content-Disposition"), F("attachment; filename=\"backup.json\""));
|
char filename[64];
|
||||||
|
getFilename(filename, sizeof(filename), "backup");
|
||||||
|
|
||||||
|
char contentDispositionHeaderValue[128];
|
||||||
|
snprintf_P(
|
||||||
|
contentDispositionHeaderValue,
|
||||||
|
sizeof(contentDispositionHeaderValue),
|
||||||
|
PSTR("attachment; filename=\"%s\""),
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
this->webServer->sendHeader(F("Content-Disposition"), contentDispositionHeaderValue);
|
||||||
this->bufferedWebServer->send(200, F("application/json"), doc);
|
this->bufferedWebServer->send(200, F("application/json"), doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -839,7 +849,18 @@ protected:
|
|||||||
|
|
||||||
doc.shrinkToFit();
|
doc.shrinkToFit();
|
||||||
|
|
||||||
this->webServer->sendHeader(F("Content-Disposition"), F("attachment; filename=\"debug.json\""));
|
char filename[64];
|
||||||
|
getFilename(filename, sizeof(filename), "debug");
|
||||||
|
|
||||||
|
char contentDispositionHeaderValue[128];
|
||||||
|
snprintf_P(
|
||||||
|
contentDispositionHeaderValue,
|
||||||
|
sizeof(contentDispositionHeaderValue),
|
||||||
|
PSTR("attachment; filename=\"%s\""),
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
|
||||||
|
this->webServer->sendHeader(F("Content-Disposition"), contentDispositionHeaderValue);
|
||||||
this->bufferedWebServer->send(200, F("application/json"), doc, true);
|
this->bufferedWebServer->send(200, F("application/json"), doc, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1046,4 +1067,12 @@ protected:
|
|||||||
this->dnsServer->stop();
|
this->dnsServer->stop();
|
||||||
this->dnsServerEnabled = false;
|
this->dnsServerEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getFilename(char* filename, size_t maxSizeFilename, const char* type) {
|
||||||
|
const time_t now = time(nullptr);
|
||||||
|
const tm* localNow = localtime(&now);
|
||||||
|
char localNowValue[20];
|
||||||
|
strftime(localNowValue, sizeof(localNowValue), PSTR("%Y-%m-%d-%H-%M-%S"), localNow);
|
||||||
|
snprintf_P(filename, maxSizeFilename, PSTR("%s_%s_%s.json"), networkSettings.hostname, localNowValue, type);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user