2022-12-04 15:13:39 -05:00
|
|
|
// This file is part of Motion Watch.
|
|
|
|
|
|
|
|
// Motion Watch is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Motion Watch is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
#include "web.h"
|
|
|
|
|
2022-12-11 10:25:22 -05:00
|
|
|
void genHTMLul(const string &outputDir, const string &title, shared_t *share)
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2022-12-11 10:25:22 -05:00
|
|
|
vector<string> logNames;
|
|
|
|
vector<string> regNames = lsFilesInDir(outputDir);
|
|
|
|
vector<string> dirNames = lsDirsInDir(outputDir);
|
2022-12-04 15:13:39 -05:00
|
|
|
|
|
|
|
string htmlText = "<!DOCTYPE html>\n";
|
|
|
|
|
|
|
|
htmlText += "<html>\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<head>\n";
|
2022-12-17 20:40:52 -05:00
|
|
|
htmlText += "<meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />\n";
|
|
|
|
htmlText += "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
|
|
|
|
htmlText += "<meta http-equiv=\"Expires\" content=\"0\" />\n";
|
2022-12-24 13:48:51 -05:00
|
|
|
htmlText += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
|
|
|
htmlText += "</head>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
htmlText += "<body>\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<h3>" + title + "</h3>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
|
2022-12-11 10:25:22 -05:00
|
|
|
if (!dirNames.empty())
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<ul>\n";
|
|
|
|
|
|
|
|
for (auto &&dirName : dirNames)
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2022-12-11 15:06:09 -05:00
|
|
|
htmlText += " <li><a href='" + dirName + "/index.html'>" + dirName + "</a></li>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "</ul>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-11 10:25:22 -05:00
|
|
|
for (auto &®Name : regNames)
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2022-12-11 10:25:22 -05:00
|
|
|
if (regName.ends_with("_log.html"))
|
|
|
|
{
|
|
|
|
logNames.push_back(regName);
|
|
|
|
}
|
2022-12-13 20:27:32 -05:00
|
|
|
else if (regName.ends_with(".html") &&
|
|
|
|
!regName.ends_with("index.html") &&
|
|
|
|
!regName.ends_with("rec_log_lines.html") &&
|
|
|
|
!regName.ends_with("det_log_lines.html"))
|
2022-12-11 10:25:22 -05:00
|
|
|
{
|
|
|
|
// regName.substr(0, regName.size() - 5) removes .html
|
|
|
|
auto name = regName.substr(0, regName.size() - 5);
|
|
|
|
|
2022-12-24 13:48:51 -05:00
|
|
|
htmlText += "<a href='" + regName + "'><img src='" + name + ".jpg" + "' style='width:25%;height:25%;'</a>\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
}
|
2022-12-04 15:13:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-11 10:25:22 -05:00
|
|
|
if (!logNames.empty())
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<h4>Logs</h4>\n";
|
|
|
|
htmlText += "<ul>\n";
|
|
|
|
|
|
|
|
for (auto &&name : logNames)
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2022-12-11 10:25:22 -05:00
|
|
|
// name.substr(0, name.size() - 9) removes _log.html
|
|
|
|
htmlText += " <li><a href='" + name + "'>" + name.substr(0, name.size() - 9) + "</a></li>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
}
|
2022-12-11 10:25:22 -05:00
|
|
|
|
|
|
|
htmlText += "</ul>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
htmlText += "</body>\n";
|
|
|
|
htmlText += "</html>";
|
|
|
|
|
|
|
|
ofstream file(string(cleanDir(outputDir) + "/index.html").c_str());
|
|
|
|
|
|
|
|
file << htmlText << endl;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void genHTMLvid(const string &outputVid, shared_t *share)
|
|
|
|
{
|
2022-12-11 12:33:56 -05:00
|
|
|
auto vidName = path(outputVid).filename().string();
|
2022-12-04 15:13:39 -05:00
|
|
|
auto filePath = path(outputVid).parent_path().string();
|
2022-12-11 12:33:56 -05:00
|
|
|
auto fileName = vidName.substr(0, vidName.size() - (share->vidExt.size() + 1));
|
2022-12-04 15:13:39 -05:00
|
|
|
string htmlText = "<!DOCTYPE html>\n";
|
|
|
|
|
|
|
|
htmlText += "<html>\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<head>\n";
|
2022-12-17 20:40:52 -05:00
|
|
|
htmlText += "<meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />\n";
|
|
|
|
htmlText += "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
|
|
|
|
htmlText += "<meta http-equiv=\"Expires\" content=\"0\" />\n";
|
2022-12-24 13:48:51 -05:00
|
|
|
htmlText += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
|
|
|
htmlText += "</head>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
htmlText += "<body>\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
htmlText += "<video width=100% height=100% controls autoplay>\n";
|
2022-12-11 12:33:56 -05:00
|
|
|
htmlText += " <source src='" + vidName + "' type='video/" + share->vidExt + "'>\n";
|
2022-12-04 15:13:39 -05:00
|
|
|
htmlText += "</video>\n";
|
|
|
|
htmlText += "</body>\n";
|
|
|
|
htmlText += "</html>";
|
|
|
|
|
2022-12-11 12:33:56 -05:00
|
|
|
ofstream file(string(filePath + "/" + fileName + ".html").c_str());
|
2022-12-04 15:13:39 -05:00
|
|
|
|
|
|
|
file << htmlText << endl;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|
2022-12-11 10:25:22 -05:00
|
|
|
|
|
|
|
void genCSS(shared_t *share)
|
|
|
|
{
|
|
|
|
string cssText = "body {\n";
|
|
|
|
|
|
|
|
cssText += " background-color: " + share->webBg + ";\n";
|
|
|
|
cssText += " color: " + share->webTxt + ";\n";
|
|
|
|
cssText += " font-family: " + share->webFont + ";\n";
|
2022-12-11 12:33:56 -05:00
|
|
|
cssText += "}\n";
|
|
|
|
cssText += "a {\n";
|
|
|
|
cssText += " color: " + share->webTxt + ";\n";
|
|
|
|
cssText += "}\n";
|
2022-12-11 10:25:22 -05:00
|
|
|
|
|
|
|
ofstream file(string(cleanDir(share->webRoot) + "/theme.css").c_str());
|
|
|
|
|
|
|
|
file << cssText << endl;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|