Skip to content

Commit

Permalink
Rename config API to file API
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Oct 19, 2024
1 parent cf1693e commit aa9f36e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions include/WebApi.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include "WebApi_config.h"
#include "WebApi_device.h"
#include "WebApi_devinfo.h"
#include "WebApi_dtu.h"
#include "WebApi_errors.h"
#include "WebApi_eventlog.h"
#include "WebApi_file.h"
#include "WebApi_firmware.h"
#include "WebApi_gridprofile.h"
#include "WebApi_inverter.h"
Expand Down Expand Up @@ -46,11 +46,11 @@ class WebApiClass {
private:
AsyncWebServer _server;

WebApiConfigClass _webApiConfig;
WebApiDeviceClass _webApiDevice;
WebApiDevInfoClass _webApiDevInfo;
WebApiDtuClass _webApiDtu;
WebApiEventlogClass _webApiEventlog;
WebApiFileClass _webApiFile;
WebApiFirmwareClass _webApiFirmware;
WebApiGridProfileClass _webApiGridprofile;
WebApiInverterClass _webApiInverter;
Expand Down
17 changes: 0 additions & 17 deletions include/WebApi_config.h

This file was deleted.

17 changes: 17 additions & 0 deletions include/WebApi_file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <ESPAsyncWebServer.h>
#include <TaskSchedulerDeclarations.h>

class WebApiFileClass {
public:
void init(AsyncWebServer& server, Scheduler& scheduler);

private:
void onFileGet(AsyncWebServerRequest* request);
void onFileDelete(AsyncWebServerRequest* request);
void onFileListGet(AsyncWebServerRequest* request);
void onFileUploadFinish(AsyncWebServerRequest* request);
void onFileUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final);
};
2 changes: 1 addition & 1 deletion src/WebApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ WebApiClass::WebApiClass()

void WebApiClass::init(Scheduler& scheduler)
{
_webApiConfig.init(_server, scheduler);
_webApiDevice.init(_server, scheduler);
_webApiDevInfo.init(_server, scheduler);
_webApiDtu.init(_server, scheduler);
_webApiEventlog.init(_server, scheduler);
_webApiFile.init(_server, scheduler);
_webApiFirmware.init(_server, scheduler);
_webApiGridprofile.init(_server, scheduler);
_webApiInverter.init(_server, scheduler);
Expand Down
26 changes: 13 additions & 13 deletions src/WebApi_config.cpp → src/WebApi_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Copyright (C) 2022-2024 Thomas Basler and others
*/
#include "WebApi_config.h"
#include "WebApi_file.h"
#include "Configuration.h"
#include "RestartHelper.h"
#include "Utils.h"
Expand All @@ -11,7 +11,7 @@
#include <AsyncJson.h>
#include <LittleFS.h>

void WebApiConfigClass::init(AsyncWebServer& server, Scheduler& scheduler)
void WebApiFileClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
using std::placeholders::_1;
using std::placeholders::_2;
Expand All @@ -20,15 +20,15 @@ void WebApiConfigClass::init(AsyncWebServer& server, Scheduler& scheduler)
using std::placeholders::_5;
using std::placeholders::_6;

server.on("/api/config/get", HTTP_GET, std::bind(&WebApiConfigClass::onConfigGet, this, _1));
server.on("/api/config/delete", HTTP_POST, std::bind(&WebApiConfigClass::onConfigDelete, this, _1));
server.on("/api/config/list", HTTP_GET, std::bind(&WebApiConfigClass::onConfigListGet, this, _1));
server.on("/api/config/upload", HTTP_POST,
std::bind(&WebApiConfigClass::onConfigUploadFinish, this, _1),
std::bind(&WebApiConfigClass::onConfigUpload, this, _1, _2, _3, _4, _5, _6));
server.on("/api/file/get", HTTP_GET, std::bind(&WebApiFileClass::onFileGet, this, _1));
server.on("/api/file/delete", HTTP_POST, std::bind(&WebApiFileClass::onFileDelete, this, _1));
server.on("/api/file/list", HTTP_GET, std::bind(&WebApiFileClass::onFileListGet, this, _1));
server.on("/api/file/upload", HTTP_POST,
std::bind(&WebApiFileClass::onFileUploadFinish, this, _1),
std::bind(&WebApiFileClass::onFileUpload, this, _1, _2, _3, _4, _5, _6));
}

void WebApiConfigClass::onConfigGet(AsyncWebServerRequest* request)
void WebApiFileClass::onFileGet(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
Expand All @@ -48,7 +48,7 @@ void WebApiConfigClass::onConfigGet(AsyncWebServerRequest* request)
request->send(LittleFS, requestFile, String(), true);
}

void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
void WebApiFileClass::onFileDelete(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
Expand Down Expand Up @@ -86,7 +86,7 @@ void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
RestartHelper.triggerRestart();
}

void WebApiConfigClass::onConfigListGet(AsyncWebServerRequest* request)
void WebApiFileClass::onFileListGet(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
Expand All @@ -112,7 +112,7 @@ void WebApiConfigClass::onConfigListGet(AsyncWebServerRequest* request)
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}

void WebApiConfigClass::onConfigUploadFinish(AsyncWebServerRequest* request)
void WebApiFileClass::onFileUploadFinish(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
Expand All @@ -128,7 +128,7 @@ void WebApiConfigClass::onConfigUploadFinish(AsyncWebServerRequest* request)
RestartHelper.triggerRestart();
}

void WebApiConfigClass::onConfigUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
void WebApiFileClass::onFileUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
{
if (!WebApi.checkCredentials(request)) {
return;
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/views/ConfigAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default defineComponent({
const formData = new FormData();
formData.append('data', JSON.stringify({ delete: true }));
fetch('/api/config/delete', {
fetch('/api/file/delete', {
method: 'POST',
headers: authHeader(),
body: formData,
Expand All @@ -178,7 +178,7 @@ export default defineComponent({
},
getFileList() {
this.loading = true;
fetch('/api/config/list', { headers: authHeader() })
fetch('/api/file/list', { headers: authHeader() })
.then((response) => handleResponse(response, this.$emitter, this.$router))
.then((data) => {
this.fileList = data;
Expand All @@ -189,7 +189,7 @@ export default defineComponent({
});
},
downloadConfig() {
fetch('/api/config/get?file=' + this.backupFileSelect, { headers: authHeader() })
fetch('/api/file/get?file=' + this.backupFileSelect, { headers: authHeader() })
.then((res) => res.blob())
.then((blob) => {
const file = window.URL.createObjectURL(blob);
Expand Down Expand Up @@ -233,7 +233,7 @@ export default defineComponent({
request.withCredentials = true;
formData.append('config', this.file, 'config');
request.open('post', '/api/config/upload?file=' + this.restoreFileSelect);
request.open('post', '/api/file/upload?file=' + this.restoreFileSelect);
authHeader().forEach((value, key) => {
request.setRequestHeader(key, value);
});
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/views/DeviceAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default defineComponent({
methods: {
getPinMappingList() {
this.pinMappingLoading = true;
fetch('/api/config/get?file=pin_mapping.json', { headers: authHeader() })
fetch('/api/file/get?file=pin_mapping.json', { headers: authHeader() })
.then((response) => handleResponse(response, this.$emitter, this.$router, true))
.then((data) => {
this.pinMappingList = data;
Expand Down

0 comments on commit aa9f36e

Please sign in to comment.