[DEV] update new etk Uri API
This commit is contained in:
parent
e02f711d66
commit
bfe15a00fa
@ -8,6 +8,8 @@ list_of_known_type = [
|
||||
["void", "void"],
|
||||
["bool", "bool"],
|
||||
["string", "etk::String"],
|
||||
["uri", "etk::Uri"],
|
||||
["path", "etk::Path"],
|
||||
["int8", "int8_t"],
|
||||
["int16", "int16_t"],
|
||||
["int32", "int32_t"],
|
||||
@ -439,6 +441,7 @@ class ServiceDefinition:
|
||||
out += "#include <etk/types.hpp>\n"
|
||||
out += "#include <eproperty/Value.hpp>\n"
|
||||
out += "#include <zeus/Raw.hpp>\n"
|
||||
out += "#include <etk/uri/uri.hpp>\n"
|
||||
out += "#include <etk/String.hpp>\n"
|
||||
out += "#include <etk/Vector.hpp>\n"
|
||||
out += "#include <ememory/memory.hpp>\n"
|
||||
@ -520,7 +523,7 @@ class ServiceDefinition:
|
||||
out += "#include <etk/stdTools.hpp>\n"
|
||||
out += "#include <zeus/AbstractFunction.hpp>\n"
|
||||
out += "#include <climits>\n"
|
||||
out += "#include <etk/os/FSNode.hpp>\n"
|
||||
out += "#include <etk/path/fileSystem.hpp>\n"
|
||||
out += "#include <zeus/WebServer.hpp>\n"
|
||||
out += "#include <zeus/Object.hpp>\n"
|
||||
out += "\n"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <elog/elog.hpp>
|
||||
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
elog::init(_argc, _argv);
|
||||
zeus::init(_argc, _argv);
|
||||
zeus::Client client1;
|
||||
etk::String fromUser = "test1";
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
@ -25,7 +24,7 @@
|
||||
#include <zeus/zeus-Media.impl.hpp>
|
||||
|
||||
static ethread::Mutex g_mutex;
|
||||
static etk::String g_basePath;
|
||||
static etk::Uri g_basePath;
|
||||
static etk::String g_baseDBName = etk::String(SERVICE_NAME) + "-database.json";
|
||||
|
||||
static etk::Vector<ememory::SharedPtr<zeus::MediaImpl>> m_listFile;
|
||||
@ -80,21 +79,21 @@ static void store_db() {
|
||||
ejson::Document database;
|
||||
ejson::Array listFilesArray;
|
||||
database.add("baseValue", ejson::String("plop"));
|
||||
bool retGenerate = database.storeSafe(g_basePath + g_baseDBName);
|
||||
APPL_INFO("Store database [STOP] : " << (g_basePath + g_baseDBName) << " ret = " << retGenerate);
|
||||
bool retGenerate = database.storeSafe(g_basePath / g_baseDBName);
|
||||
APPL_INFO("Store database [STOP] : " << (g_basePath / g_baseDBName) << " ret = " << retGenerate);
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
static void load_db() {
|
||||
ejson::Document database;
|
||||
bool ret = database.load(g_basePath + g_baseDBName);
|
||||
bool ret = database.load(g_basePath / g_baseDBName);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> LOAD error");
|
||||
}
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::String _basePath) {
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::Uri _basePath) {
|
||||
g_basePath = _basePath;
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
APPL_INFO("Load USER: " << g_basePath);
|
||||
|
@ -10,7 +10,9 @@
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
#include <etk/io/File.hpp>
|
||||
|
||||
#include <elog/elog.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
@ -52,13 +54,9 @@ bool progressCall(const etk::String& _value) {
|
||||
void progressCallback(const etk::String& _value) {
|
||||
APPL_PRINT("plop " << _value);
|
||||
}
|
||||
bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<etk::String,etk::String> _basicKey = etk::Map<etk::String,etk::String>()) {
|
||||
etk::String extention;
|
||||
if ( _path.rfind('.') != etk::String::npos
|
||||
&& _path.rfind('.') != 0) {
|
||||
extention = etk::toLower(etk::String(_path.begin()+_path.rfind('.')+1, _path.end()));
|
||||
}
|
||||
etk::String fileName = etk::split(_path, '/').back();
|
||||
bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::Path _path, etk::Map<etk::String,etk::String> _basicKey = etk::Map<etk::String,etk::String>()) {
|
||||
etk::String extention = _path.getExtention().toLower();
|
||||
etk::String fileName = _path.getFileName();
|
||||
// internal extention ...
|
||||
if (extention == "sha512") {
|
||||
return true;
|
||||
@ -92,16 +90,19 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
|
||||
if (_basicKey["saison"] != "") {
|
||||
groupName += ":" + _basicKey["saison"];
|
||||
}
|
||||
auto sending = _srv.setGroupCover(zeus::File::create(_path, ""), groupName);
|
||||
auto sending = _srv.setGroupCover(zeus::File::create(_path.getString(), ""), groupName);
|
||||
sending.onSignal(progressCallback);
|
||||
sending.waitFor(echrono::seconds(20000));
|
||||
return true;
|
||||
}
|
||||
etk::String storedSha512;
|
||||
if (etk::FSNodeExist(_path + ".sha512") == true) {
|
||||
uint64_t time_sha512 = etk::FSNodeGetTimeModified(_path + ".sha512");
|
||||
uint64_t time_elem = etk::FSNodeGetTimeModified(_path);
|
||||
etk::String storedSha512_file = etk::FSNodeReadAllData(_path + ".sha512");
|
||||
if (etk::path::exist(_path + ".sha512") == true) {
|
||||
uint64_t time_sha512 = etk::path::getModifyTime(_path + ".sha512");
|
||||
uint64_t time_elem = etk::path::getModifyTime(_path);
|
||||
etk::io::File file(_path + ".sha512");
|
||||
file.open(etk::io::OpenMode::Read);
|
||||
etk::String storedSha512_file = file.readAllString();
|
||||
file.close();
|
||||
if (time_elem > time_sha512) {
|
||||
// check the current sha512
|
||||
storedSha512 = algue::stringConvert(algue::sha512::encodeFromFile(_path));
|
||||
@ -117,14 +118,22 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
|
||||
}
|
||||
}
|
||||
// store new sha512 ==> this update tile too ...
|
||||
etk::FSNodeWriteAllData(_path + ".sha512", storedSha512);
|
||||
file.open(etk::io::OpenMode::Write);
|
||||
file.writeAll(storedSha512);
|
||||
file.close();
|
||||
} else {
|
||||
// store new sha512
|
||||
storedSha512 = etk::FSNodeReadAllData(_path + ".sha512");
|
||||
storedSha512 = file.readAllString();
|
||||
file.open(etk::io::OpenMode::Read);
|
||||
file.writeAll(storedSha512);
|
||||
file.close();
|
||||
}
|
||||
} else {
|
||||
storedSha512 = algue::stringConvert(algue::sha512::encodeFromFile(_path));
|
||||
etk::FSNodeWriteAllData(_path + ".sha512", storedSha512);
|
||||
etk::io::File file(_path + ".sha512");
|
||||
file.open(etk::io::OpenMode::Write);
|
||||
file.writeAll(storedSha512);
|
||||
file.close();
|
||||
}
|
||||
// push only if the file exist
|
||||
// TODO : Check the metadata updating ...
|
||||
@ -134,7 +143,7 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
|
||||
return true;
|
||||
}
|
||||
// TODO: Do it better ==> add the calback to know the push progression ...
|
||||
auto sending = _srv.add(zeus::File::create(_path, storedSha512));
|
||||
auto sending = _srv.add(zeus::File::create(_path.getString(), storedSha512));
|
||||
sending.onSignal(progressCallback);
|
||||
uint32_t mediaId = sending.waitFor(echrono::seconds(20000)).get();
|
||||
if (mediaId == 0) {
|
||||
@ -309,14 +318,13 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
|
||||
return true;
|
||||
}
|
||||
|
||||
void installVideoPath(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<etk::String,etk::String> _basicKey = etk::Map<etk::String,etk::String>()) {
|
||||
etk::FSNode node(_path);
|
||||
void installVideoPath(zeus::service::ProxyVideo& _srv, etk::Path _path, etk::Map<etk::String,etk::String> _basicKey = etk::Map<etk::String,etk::String>()) {
|
||||
APPL_INFO("Parse : '" << _path << "'");
|
||||
etk::Vector<etk::String> listSubPath = node.folderGetSub(true, false, "*");
|
||||
etk::Vector<etk::Path> listSubPath = etk::path::list(_path, etk::path::LIST_FOLDER);
|
||||
for (auto &itPath : listSubPath) {
|
||||
etk::Map<etk::String,etk::String> basicKeyTmp = _basicKey;
|
||||
APPL_INFO("Add Sub path: '" << itPath << "'");
|
||||
etk::String lastPathName = etk::split(itPath, '/').back();
|
||||
etk::String lastPathName = itPath.getFileName();
|
||||
if (basicKeyTmp.size() == 0) {
|
||||
APPL_INFO("find A '" << lastPathName << "' " << basicKeyTmp.size());
|
||||
if (lastPathName == "film") {
|
||||
@ -406,9 +414,8 @@ void installVideoPath(zeus::service::ProxyVideo& _srv, etk::String _path, etk::M
|
||||
installVideoPath(_srv, itPath, basicKeyTmp);
|
||||
}
|
||||
// Add files :
|
||||
etk::Vector<etk::String> listSubFile = node.folderGetSub(false, true, "*");
|
||||
etk::Vector<etk::Path> listSubFile = etk::path::list(_path, etk::path::LIST_FILE);
|
||||
for (auto &itFile : listSubFile) {
|
||||
|
||||
etk::Map<etk::String,etk::String> basicKeyTmp = _basicKey;
|
||||
pushVideoFile(_srv, itFile, _basicKey);
|
||||
|
||||
@ -417,7 +424,6 @@ void installVideoPath(zeus::service::ProxyVideo& _srv, etk::String _path, etk::M
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
elog::init(_argc, _argv);
|
||||
zeus::init(_argc, _argv);
|
||||
zeus::Client client1;
|
||||
etk::String login = "test1";
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <elog/elog.hpp>
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
@ -394,7 +393,6 @@ void installVideoPath(zeus::service::ProxyVideo& _srv, etk::String _path, etk::M
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
elog::init(_argc, _argv);
|
||||
zeus::init(_argc, _argv);
|
||||
zeus::Client client1;
|
||||
etk::String login = "test1";
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <appl/debug.hpp>
|
||||
#include <appl/GateWay.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <etk/Allocator.hpp>
|
||||
|
||||
@ -17,7 +18,6 @@
|
||||
|
||||
#ifdef GATEWAY_ENABLE_LAUNCHER
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -50,13 +50,13 @@ class PlugginAccess {
|
||||
m_SERVICE_IO_init(null),
|
||||
m_SERVICE_IO_uninit(null),
|
||||
m_SERVICE_IO_instanciate(null) {
|
||||
etk::String srv = etk::FSNodeGetApplicationPath() + "/../lib/lib" + m_fullName + "-impl.so";
|
||||
etk::Path srv = etk::path::getBinaryPath() / ".." / "lib" / "lib" / m_fullName + "-impl.so";
|
||||
APPL_PRINT("++++++++++++++++++++++++++++++++");
|
||||
APPL_PRINT("++ srv: '" << m_name << "' ");
|
||||
APPL_PRINT("++++++++++++++++++++++++++++++++");
|
||||
APPL_PRINT("At position: '" << srv << "'");
|
||||
APPL_PRINT("with full name=" << m_fullName);
|
||||
m_handle = dlopen(srv.c_str(), RTLD_LAZY);
|
||||
m_handle = dlopen(srv.getNative().c_str(), RTLD_LAZY);
|
||||
if (!m_handle) {
|
||||
APPL_ERROR("Can not load Lbrary:" << dlerror());
|
||||
return;
|
||||
@ -223,16 +223,19 @@ int main(int _argc, const char *_argv[]) {
|
||||
etk::Vector<etk::Pair<etk::String,etk::String>> listAvaillableServices;
|
||||
if (services.size() != 0) {
|
||||
// find all services:
|
||||
etk::FSNode dataPath(etk::FSNodeGetApplicationPath() + "/../share");
|
||||
etk::Vector<etk::String> listSubPath = dataPath.folderGetSub(true, false, ".*");
|
||||
APPL_DEBUG(" Base data path: " << dataPath.getName());
|
||||
etk::Path dataPath(etk::path::getBinaryPath() / ".." / "share");
|
||||
etk::Vector<etk::Path> listSubPath = etk::path::list(dataPath, etk::path::LIST_FOLDER);
|
||||
APPL_DEBUG(" Base data path: " << dataPath);
|
||||
APPL_DEBUG(" SubPath: " << listSubPath);
|
||||
for (auto &it: listSubPath) {
|
||||
if (etk::FSNodeExist(it + "/zeus/") == true) {
|
||||
etk::FSNode dataPath(it + "/zeus/");
|
||||
etk::Vector<etk::String> listServices = dataPath.folderGetSub(false, true, ".*\\.srv");
|
||||
if (etk::path::exist(it / "zeus") == true) {
|
||||
etk::Path dataPath(it / "zeus");
|
||||
etk::Vector<etk::Path> listServices = etk::path::list(dataPath, etk::path::LIST_FILE);
|
||||
for (auto &it2: listServices) {
|
||||
etk::String nameFileSrv = etk::FSNode(it2).getNameFile();
|
||||
if (it2.getExtention() != "srv") {
|
||||
continue;
|
||||
}
|
||||
etk::String nameFileSrv = it2.getFileName();
|
||||
etk::Vector<etk::String> spl = etk::String(nameFileSrv.begin(), nameFileSrv.end()-4).split("-service-");
|
||||
if (spl.size() != 2) {
|
||||
APPL_ERROR("reject service, wrong format ... '" << it2 << "' missing XXX-service-SERVICE-NAME.srv");
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -19,8 +18,10 @@
|
||||
#include <zeus/Object.hpp>
|
||||
#include <zeus/Client.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
|
||||
typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], etk::String _basePath);
|
||||
typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], etk::Uri _basePath);
|
||||
typedef bool (*SERVICE_IO_uninit_t)();
|
||||
typedef void (*SERVICE_IO_peridic_call_t)();
|
||||
typedef zeus::Object* (*SERVICE_IO_instanciate_t)(uint32_t, ememory::SharedPtr<zeus::WebServer>&, uint32_t);
|
||||
@ -41,9 +42,9 @@ class PlugginAccess {
|
||||
m_SERVICE_IO_uninit(null),
|
||||
m_SERVICE_IO_peridic_call(null),
|
||||
m_SERVICE_IO_instanciate(null) {
|
||||
etk::String srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + m_name + "-impl.so";
|
||||
etk::Path srv = etk::path::getBinaryPath() / ".." / "lib" / "libzeus-service-" + m_name + "-impl.so";
|
||||
APPL_PRINT("Try to open service with name: '" << m_name << "' at position: '" << srv << "'");
|
||||
m_handle = dlopen(srv.c_str(), RTLD_LAZY);
|
||||
m_handle = dlopen(srv.getNative().c_str(), RTLD_LAZY);
|
||||
if (!m_handle) {
|
||||
APPL_ERROR("Can not load Lbrary:" << dlerror());
|
||||
return;
|
||||
@ -77,16 +78,16 @@ class PlugginAccess {
|
||||
~PlugginAccess() {
|
||||
|
||||
}
|
||||
bool init(int _argc, const char *_argv[], etk::String _basePath) {
|
||||
bool init(int _argc, const char *_argv[], etk::Uri _basePath) {
|
||||
if (m_SERVICE_IO_init == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_basePath.size() == 0) {
|
||||
_basePath = "USERDATA:" + m_name + "/";
|
||||
if (_basePath.isEmpty() == true) {
|
||||
_basePath = "USER_DATA:///" + m_name + "/";
|
||||
APPL_PRINT("Use base path: " << _basePath);
|
||||
} else {
|
||||
_basePath += m_name + "/";
|
||||
_basePath.setPath(_basePath.getPath() / m_name);
|
||||
}
|
||||
return (*m_SERVICE_IO_init)(_argc, _argv, _basePath);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <appl/widget/Player.hpp>
|
||||
|
||||
|
||||
static etk::String g_baseDBName = "USERDATA:config.json";
|
||||
static etk::Uri g_baseDBName = "CONFIG:///config.json";
|
||||
|
||||
void appl::Windows::store_db() {
|
||||
APPL_DEBUG("Store database [START]");
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
#include <appl/Router.hpp>
|
||||
#include <appl/debug.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
#include <enet/TcpServer.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
static etk::String g_pathDBName = "USERDATA:router-database.json";
|
||||
static etk::Path g_pathDBName = "USER_DATA:///router-database.json";
|
||||
|
||||
class UserAvaillable {
|
||||
public:
|
||||
@ -224,17 +224,17 @@ ememory::SharedPtr<appl::GateWayInterface> appl::Router::get(const etk::String&
|
||||
} else {
|
||||
// We're in the child here.
|
||||
APPL_ERROR("Child Execution ...");
|
||||
etk::String binary = etk::FSNodeGetApplicationPath() + "/zeus-gateway";
|
||||
etk::Path binary = etk::path::getBinaryPath() / "zeus-gateway";
|
||||
etk::String userConf = "--user=" + it.m_name;
|
||||
etk::String basePath = "--base-path=" + it.m_basePath;
|
||||
etk::String logFile;
|
||||
if (*propertyStdOut == false) {
|
||||
logFile = it.m_basePath + "/log/gateway.log";
|
||||
if ( logFile.size() != 0
|
||||
&& logFile[0] == '~') {
|
||||
logFile = etk::FSNodeGetHomePath() + &logFile[1];
|
||||
etk::Path tmp = etk::Path(it.m_basePath) / "log" / "gateway.log";
|
||||
if ( tmp.isEmpty() == false
|
||||
&& tmp.getString()[0] == '~') {
|
||||
tmp = etk::path::getHomePath() / &logFile[1];
|
||||
}
|
||||
logFile = "--elog-file=" + logFile;
|
||||
logFile = "--elog-file=" + tmp.getString();
|
||||
//etk::String logFile = "--elog-file=/home/heero/.local/share/zeus-DATA/SDFGHTHBSDFGSQDHZSRDFGSDFGSDFGSDFG/log/gateway.log";
|
||||
//etk::String logFile = " ";
|
||||
APPL_INFO("New Child log in = " << logFile);
|
||||
@ -247,8 +247,8 @@ ememory::SharedPtr<appl::GateWayInterface> appl::Router::get(const etk::String&
|
||||
etk::String delay = "--router-delay=" + etk::toString(*propertyDelayToStop);
|
||||
//etk::String delay = "--router-delay=-1";
|
||||
APPL_INFO("execute: " << binary << " " << userConf << " --srv=all " << delay << " " << basePath << " " << logFile << " " << directAccess);
|
||||
int ret = execlp( binary.c_str(),
|
||||
binary.c_str(), // must repeate the binary name to have the name as first argument ...
|
||||
int ret = execlp( binary.getNative().c_str(),
|
||||
binary.getNative().c_str(), // must repeate the binary name to have the name as first argument ...
|
||||
userConf.c_str(),
|
||||
"--srv=all",
|
||||
"--service-extern=false",
|
||||
|
@ -8,12 +8,13 @@
|
||||
#include <zeus/Object.hpp>
|
||||
#include <zeus/File.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <echrono/Time.hpp>
|
||||
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
|
||||
@ -24,7 +25,7 @@
|
||||
#include <zeus/ProxyFile.hpp>
|
||||
|
||||
static ethread::Mutex g_mutex;
|
||||
static etk::String g_basePath;
|
||||
static etk::Uri g_basePath;
|
||||
static etk::String g_baseDBName = etk::String(SERVICE_NAME) + "-database.json";
|
||||
class FileProperty {
|
||||
public:
|
||||
@ -108,7 +109,9 @@ namespace appl {
|
||||
if (find == false) {
|
||||
throw etk::exception::InvalidArgument("Wrong file name ...");
|
||||
}
|
||||
return zeus::File::create(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType), "", property.m_mineType);
|
||||
etk::Uri tmpp = g_basePath;
|
||||
tmpp.setPath(g_basePath.getPath() / property.m_fileName + "." + zeus::getExtention(property.m_mineType));
|
||||
return zeus::File::create(tmpp.getString(), property.m_mineType);
|
||||
}
|
||||
uint32_t mediaAdd(zeus::ProxyFile _dataFile) override {
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
@ -117,8 +120,9 @@ namespace appl {
|
||||
|
||||
auto futType = _dataFile.getMineType();
|
||||
auto futName = _dataFile.getName();
|
||||
etk::String tmpFileName = g_basePath + "tmpImport_" + etk::toString(id);
|
||||
etk::String sha512String = zeus::storeInFile(_dataFile, tmpFileName);
|
||||
etk::Uri tmpFileName = g_basePath;
|
||||
tmpFileName.setPath(g_basePath.getPath() / "tmpImport_" + etk::toString(id));
|
||||
etk::String sha512String = zeus::storeInFile(_dataFile, tmpFileName.getString());
|
||||
futType.wait();
|
||||
futName.wait();
|
||||
// TODO : Get internal data of the file and remove all the meta-data ==> proper files ...
|
||||
@ -127,17 +131,19 @@ namespace appl {
|
||||
APPL_INFO("File already registered at " << it.m_creationData);
|
||||
// TODO : Check if data is identical ...
|
||||
// remove temporary file
|
||||
etk::FSNodeRemove(tmpFileName);
|
||||
etk::uri::remove(tmpFileName);
|
||||
return it.m_id;
|
||||
}
|
||||
}
|
||||
// move the file at the good position:
|
||||
APPL_DEBUG("move temporay file in : " << g_basePath << sha512String);
|
||||
if (etk::FSNodeGetSize(tmpFileName) == 0) {
|
||||
if (etk::uri::fileSize(tmpFileName) == 0) {
|
||||
APPL_ERROR("try to store an empty file");
|
||||
throw etk::exception::RuntimeError("file size == 0");
|
||||
}
|
||||
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
|
||||
etk::Uri tmpFileNameDest = g_basePath;
|
||||
tmpFileNameDest.setPath(g_basePath.getPath() / sha512String + "." + zeus::getExtention(futType.get()));
|
||||
etk::uri::move(tmpFileName, tmpFileNameDest);
|
||||
FileProperty property;
|
||||
property.m_id = id;
|
||||
property.m_fileName = sha512String;
|
||||
@ -183,7 +189,10 @@ namespace appl {
|
||||
}
|
||||
// Real Remove definitly the file
|
||||
// TODO : Set it in a trash ... For a while ...
|
||||
if (etk::FSNodeRemove(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType)) == false) {
|
||||
|
||||
etk::Uri tmpFileName = g_basePath;
|
||||
tmpFileName.setPath(g_basePath.getPath() / property.m_fileName + "." + zeus::getExtention(property.m_mineType));
|
||||
if (etk::uri::remove(tmpFileName) == false) {
|
||||
throw etk::exception::RuntimeError("Can not remove file ...");
|
||||
}
|
||||
}
|
||||
@ -429,14 +438,18 @@ static void store_db() {
|
||||
listMediaArray.add(ejson::Number(it2));
|
||||
}
|
||||
}
|
||||
bool retGenerate = database.storeSafe(g_basePath + g_baseDBName);
|
||||
APPL_ERROR("Store database [STOP] : " << (g_basePath + g_baseDBName) << " ret = " << retGenerate);
|
||||
etk::Uri dbFileName = g_basePath;
|
||||
dbFileName.setPath(g_basePath.getPath() / g_baseDBName);
|
||||
bool retGenerate = database.storeSafe(dbFileName);
|
||||
APPL_ERROR("Store database [STOP] : " << dbFileName << " ret = " << retGenerate);
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
static void load_db() {
|
||||
ejson::Document database;
|
||||
bool ret = database.load(g_basePath + g_baseDBName);
|
||||
etk::Uri dbFileName = g_basePath;
|
||||
dbFileName.setPath(g_basePath.getPath() / g_baseDBName);
|
||||
bool ret = database.load(dbFileName);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> LOAD error");
|
||||
}
|
||||
@ -485,7 +498,7 @@ static void load_db() {
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::String _basePath) {
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::Uri _basePath) {
|
||||
g_basePath = _basePath;
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
APPL_WARNING("Load USER: " << g_basePath);
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <zeus/ProxyClientProperty.hpp>
|
||||
|
||||
static ethread::Mutex g_mutex;
|
||||
static etk::String g_basePath;
|
||||
static etk::Uri g_basePath;
|
||||
static etk::String g_baseDBName = etk::String(SERVICE_NAME) + "-database.json";
|
||||
static ejson::Document g_database;
|
||||
|
||||
@ -135,11 +135,13 @@ namespace appl {
|
||||
};
|
||||
}
|
||||
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::String _basePath) {
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::Uri _basePath) {
|
||||
g_basePath = _basePath;
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
APPL_WARNING("Load USER: " << g_basePath);
|
||||
bool ret = g_database.load(g_basePath + g_baseDBName);
|
||||
etk::Uri db = g_basePath;
|
||||
db.setPath(g_basePath.getPath() / g_baseDBName);
|
||||
bool ret = g_database.load(db);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> LOAD error");
|
||||
}
|
||||
@ -149,7 +151,9 @@ ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::String
|
||||
ETK_EXPORT_API bool SERVICE_IO_uninit() {
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
APPL_DEBUG("Store User Info:");
|
||||
bool ret = g_database.storeSafe(g_basePath + g_baseDBName);
|
||||
etk::Uri db = g_basePath;
|
||||
db.setPath(g_basePath.getPath() / g_baseDBName);
|
||||
bool ret = g_database.storeSafe(db);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> Store error");
|
||||
return false;
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
@ -26,9 +25,10 @@
|
||||
#include <zeus/zeus-Media.impl.hpp>
|
||||
|
||||
static ethread::Mutex g_mutex;
|
||||
static etk::String g_basePath;
|
||||
static etk::String g_basePathCover;
|
||||
static etk::String g_basePathCoverGroup;
|
||||
static etk::Uri g_basePath;
|
||||
static etk::Uri g_basePathCover;
|
||||
static etk::Uri g_basePathCoverGroup;
|
||||
static etk::Uri g_basePathBDD;
|
||||
static etk::String g_baseDBName = etk::String(SERVICE_NAME) + "-database.json";
|
||||
|
||||
static etk::Vector<ememory::SharedPtr<zeus::MediaImpl>> m_listFile;
|
||||
@ -210,20 +210,20 @@ namespace appl {
|
||||
}
|
||||
}
|
||||
}
|
||||
etk::String tmpFileName = g_basePath + "tmpImport_" + etk::toString(importId);
|
||||
etk::Uri tmpFileName = g_basePath / ("tmpImport_" + etk::toString(importId));
|
||||
etk::String sha512String = zeus::storeInFile(_dataFile, tmpFileName);
|
||||
futType.wait();
|
||||
futName.wait();
|
||||
// move the file at the good position:
|
||||
APPL_DEBUG("move temporay file in : " << g_basePath << sha512String);
|
||||
if (etk::FSNodeGetSize(tmpFileName) == 0) {
|
||||
if (etk::uri::fileSize(tmpFileName) == 0) {
|
||||
APPL_ERROR("try to store an empty file");
|
||||
throw etk::exception::RuntimeError("file size == 0");
|
||||
}
|
||||
if (zeus::getExtention(futType.get()) != "") {
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
|
||||
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String + "." + zeus::getExtention(futType.get()), g_basePath);
|
||||
etk::uri::move(tmpFileName, g_basePath / (sha512String + "." + zeus::getExtention(futType.get())));
|
||||
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, g_basePath / sha512String + "." + zeus::getExtention(futType.get()));
|
||||
property->setMetadata("sha512", sha512String);
|
||||
property->setMetadata("mime-type", futType.get());
|
||||
property->setCallbackMetadataChange(&metadataChange);
|
||||
@ -231,8 +231,8 @@ namespace appl {
|
||||
g_needToStore = true;
|
||||
} else {
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
etk::FSNodeMove(tmpFileName, g_basePath + sha512String);
|
||||
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String, g_basePath);
|
||||
etk::uri::move(tmpFileName, g_basePath / sha512String);
|
||||
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, g_basePath / sha512String);
|
||||
property->setMetadata("sha512", sha512String);
|
||||
property->setCallbackMetadataChange(&metadataChange);
|
||||
m_listFile.pushBack(property);
|
||||
@ -403,42 +403,42 @@ namespace appl {
|
||||
return out;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::File> internalGetCover(const etk::String& _baseName, const etk::String& _mediaString, uint32_t _maxSize) {
|
||||
if (etk::FSNodeExist(_baseName + _mediaString + ".jpg") == true) {
|
||||
return zeus::File::create(_baseName + _mediaString + ".jpg");
|
||||
ememory::SharedPtr<zeus::File> internalGetCover(const etk::Uri& _baseName, const etk::String& _mediaString, uint32_t _maxSize) {
|
||||
if (etk::uri::exist(_baseName / (_mediaString + ".jpg")) == true) {
|
||||
return zeus::File::create(_baseName / (_mediaString + ".jpg"));
|
||||
}
|
||||
if (etk::FSNodeExist(_baseName + _mediaString + ".png") == true) {
|
||||
return zeus::File::create(_baseName + _mediaString + ".png");
|
||||
if (etk::uri::exist(_baseName / (_mediaString + ".png")) == true) {
|
||||
return zeus::File::create(_baseName / (_mediaString + ".png"));
|
||||
}
|
||||
throw etk::exception::RuntimeError("No cover availlable");
|
||||
}
|
||||
|
||||
void internalSetCover(const etk::String& _baseName, zeus::ActionNotification<etk::String>& _notifs, zeus::ProxyFile _cover, etk::String _mediaString) {
|
||||
void internalSetCover(const etk::Uri& _baseName, zeus::ActionNotification<etk::String>& _notifs, zeus::ProxyFile _cover, etk::String _mediaString) {
|
||||
uint64_t importId = 0;
|
||||
{
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
importId = createUniqueImportID();
|
||||
}
|
||||
auto futType = _cover.getMineType();
|
||||
etk::String tmpFileName = g_basePath + "tmpImport_" + etk::toString(importId);
|
||||
etk::Uri tmpFileName = g_basePath / ("tmpImport_" + etk::toString(importId));
|
||||
etk::String sha512String = zeus::storeInFile(_cover, tmpFileName);
|
||||
futType.wait();
|
||||
if (etk::FSNodeGetSize(tmpFileName) == 0) {
|
||||
if (etk::uri::fileSize(tmpFileName) == 0) {
|
||||
APPL_ERROR("try to store an empty file");
|
||||
throw etk::exception::RuntimeError("file size == 0");
|
||||
}
|
||||
if (etk::FSNodeGetSize(tmpFileName) > 1024*1024) {
|
||||
if (etk::uri::fileSize(tmpFileName) > 1024*1024) {
|
||||
APPL_ERROR("try to store a Bigger file");
|
||||
throw etk::exception::RuntimeError("file size > 1Mo");
|
||||
}
|
||||
if (futType.get() == "image/png") {
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
etk::FSNodeRemove(_baseName + _mediaString + ".jpg");
|
||||
etk::FSNodeMove(tmpFileName, _baseName + _mediaString + ".png");
|
||||
etk::uri::remove(_baseName / (_mediaString + ".jpg"));
|
||||
etk::uri::move(tmpFileName, _baseName / (_mediaString + ".png"));
|
||||
} else if (futType.get() == "image/jpeg") {
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
etk::FSNodeRemove(_baseName + _mediaString + ".png");
|
||||
etk::FSNodeMove(tmpFileName, _baseName + _mediaString + ".jpg");
|
||||
etk::uri::remove(_baseName / (_mediaString + ".png"));
|
||||
etk::uri::move(tmpFileName, _baseName / (_mediaString + ".jpg"));
|
||||
} else {
|
||||
APPL_ERROR("try to store a file with the wrong format");
|
||||
throw etk::exception::RuntimeError("wrong foramt :" + futType.get() + " support only image/jpeg, image/png");
|
||||
@ -475,14 +475,14 @@ static void store_db() {
|
||||
listFilesArray.add(it->getJson());
|
||||
}
|
||||
}
|
||||
bool retGenerate = database.storeSafe(g_basePath + g_baseDBName);
|
||||
APPL_ERROR("Store database [STOP] : " << (g_basePath + g_baseDBName) << " ret = " << retGenerate);
|
||||
bool retGenerate = database.storeSafe(g_basePathBDD);
|
||||
APPL_ERROR("Store database [STOP] : " << g_basePathBDD << " ret = " << retGenerate);
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
static void load_db() {
|
||||
ejson::Document database;
|
||||
bool ret = database.load(g_basePath + g_baseDBName);
|
||||
bool ret = database.load(g_basePathBDD);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> LOAD error");
|
||||
}
|
||||
@ -506,10 +506,11 @@ static void load_db() {
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::String _basePath) {
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], etk::Uri _basePath) {
|
||||
g_basePath = _basePath;
|
||||
g_basePathCover = _basePath + "/AAAASDGDFGQN4352SCVdfgBSXDFGFCVQDSGFQSfd_cover/";
|
||||
g_basePathCoverGroup = _basePath + "/AAAASDGDFGQN4352SCVdfgBSXDFGFCVQDSGFQSfd_cover_group/";
|
||||
g_basePathCover = g_basePath / "AAAASDGDFGQN4352SCVdfgBSXDFGFCVQDSGFQSfd_cover";
|
||||
g_basePathCoverGroup = g_basePath / "AAAASDGDFGQN4352SCVdfgBSXDFGFCVQDSGFQSfd_cover_group";
|
||||
g_basePathBDD = g_basePath / g_baseDBName;
|
||||
ethread::UniqueLock lock(g_mutex);
|
||||
APPL_WARNING("Load USER: " << g_basePath);
|
||||
load_db();
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
#include <zeus/AbstractFunction.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(zeus::AbstractFunction);
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <zeus/AbstractFunction.hpp>
|
||||
#include <climits>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <zeus/WebServer.hpp>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <zeus/ProxyFile.hpp>
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <algue/sha512.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
#include <etk/Exception.hpp>
|
||||
#include "debug.hpp"
|
||||
|
||||
@ -17,18 +17,18 @@
|
||||
ETK_DECLARE_TYPE(zeus::FileImpl);
|
||||
|
||||
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::String _fileNameReal) {
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::Uri _fileNameReal) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::String _fileNameReal, etk::String _sha512) {
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::Uri _fileNameReal, etk::String _sha512) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _sha512);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::String _fileNameReal, etk::String _fileNameShow, etk::String _mineType) {
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::Uri _fileNameReal, etk::String _fileNameShow, etk::String _mineType) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _fileNameShow, _mineType);
|
||||
}
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::String _fileNameReal, etk::String _fileNameShow, etk::String _mineType, etk::String _sha512) {
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(etk::Uri _fileNameReal, etk::String _fileNameShow, etk::String _mineType, etk::String _sha512) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _fileNameShow, _mineType, _sha512);
|
||||
}
|
||||
|
||||
@ -47,18 +47,14 @@ zeus::FileImpl::FileImpl(etk::Vector<uint8_t> _value, etk::String _virtualName,
|
||||
m_data = _value;
|
||||
m_size = m_data.size();
|
||||
}
|
||||
zeus::FileImpl::FileImpl(etk::String _fileNameReal, etk::String _sha512) :
|
||||
m_filename(_fileNameReal),
|
||||
m_node(_fileNameReal),
|
||||
zeus::FileImpl::FileImpl(etk::Uri _fileNameReal, etk::String _sha512) :
|
||||
m_filename(_fileNameReal.getPath().getFileName()),
|
||||
m_file(etk::uri::get(_fileNameReal)),
|
||||
m_gettedData(0),
|
||||
m_sha512(_sha512) {
|
||||
ZEUS_ERROR(" ==============>>>>>>>>>>>>>> CREATE FILE");
|
||||
m_size = m_node.fileSize();
|
||||
etk::String extention;
|
||||
if ( _fileNameReal.rfind('.') != etk::String::npos
|
||||
&& _fileNameReal.rfind('.') != 0) {
|
||||
extention = etk::String(_fileNameReal.begin()+_fileNameReal.rfind('.')+1, _fileNameReal.end());
|
||||
}
|
||||
m_size = m_file->size();
|
||||
etk::String extention = _fileNameReal.getPath().getExtention();
|
||||
m_mineType = zeus::getMineType(extention);
|
||||
if ( _sha512.size() > 0
|
||||
&& _sha512.size() != 128) {
|
||||
@ -69,14 +65,14 @@ zeus::FileImpl::FileImpl(etk::String _fileNameReal, etk::String _sha512) :
|
||||
|
||||
// sha 512 example: 6134b4a4b5b116cf1b1b757c5aa48bd8b3482b86c6d3fee389a0a3232f74e7331e5f8af6ad516d2ca92eda0a475f44e1291618562ce6f9e54634ba052650dcd7
|
||||
// 000000000100000000020000000003000000000400000000050000000006000000000700000000080000000009000000000A000000000B000000000C00000000
|
||||
zeus::FileImpl::FileImpl(etk::String _fileNameReal, etk::String _fileNameShow, etk::String _mineType, etk::String _sha512) :
|
||||
zeus::FileImpl::FileImpl(etk::Uri _fileNameReal, etk::String _fileNameShow, etk::String _mineType, etk::String _sha512) :
|
||||
m_filename(_fileNameShow),
|
||||
m_node(_fileNameReal),
|
||||
m_file(etk::uri::get(_fileNameReal)),
|
||||
m_gettedData(0),
|
||||
m_mineType(_mineType),
|
||||
m_sha512(_sha512) {
|
||||
ZEUS_ERROR(" ==============>>>>>>>>>>>>>> CREATE FILE");
|
||||
m_size = m_node.fileSize();
|
||||
m_size = m_file->size();
|
||||
if ( _sha512.size() > 0
|
||||
&& _sha512.size() != 128) {
|
||||
ZEUS_ERROR("Set a wrong sha512 file type");
|
||||
@ -86,8 +82,8 @@ zeus::FileImpl::FileImpl(etk::String _fileNameReal, etk::String _fileNameShow, e
|
||||
|
||||
zeus::FileImpl::~FileImpl() {
|
||||
ZEUS_ERROR(" <<<<<<<<<<<<<<============== DESTROY FILE");
|
||||
if (m_node.fileIsOpen() == true) {
|
||||
m_node.fileClose();
|
||||
if (m_file->isOpen() == true) {
|
||||
m_file->close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +99,7 @@ etk::String zeus::FileImpl::getSha512() {
|
||||
if (m_sha512 == "") {
|
||||
ZEUS_INFO("calculation of sha 512 (start)");
|
||||
if (m_dataRaw == false) {
|
||||
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_node.getFileSystemName()));
|
||||
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_file));
|
||||
} else {
|
||||
m_sha512 = algue::stringConvert(algue::sha512::encode(m_data));
|
||||
}
|
||||
@ -126,21 +122,21 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
|
||||
throw etk::exception::InvalidArgument("REQUEST start position out of file size" + etk::toString(_start) + " > " + etk::toString(m_size));
|
||||
}
|
||||
if (m_dataRaw == false) {
|
||||
if (m_node.fileIsOpen() == false) {
|
||||
m_node.fileOpenRead();
|
||||
if (m_file->isOpen() == false) {
|
||||
m_file->open(etk::io::OpenMode::Read);
|
||||
}
|
||||
m_gettedData += (_stop - _start);
|
||||
//ZEUS_PRINT("Reading file : " << m_gettedData << "/" << m_size << " ==> " << float(m_gettedData)/float(m_size)*100.0f << "%");
|
||||
printf("Reading file : %d/%d ==> %f \r", int(m_gettedData), int(m_size), float(m_gettedData)/float(m_size)*100.0f);
|
||||
zeus::Raw tmp(_stop - _start);
|
||||
if (m_node.fileSeek(_start, etk::seekNode_start) == false) {
|
||||
if (m_file->seek(_start, etk::io::SeekMode::Start) == false) {
|
||||
ZEUS_ERROR("REQUEST seek error ...");
|
||||
throw etk::exception::RuntimeError("Seek in the file error");
|
||||
return zeus::Raw();
|
||||
}
|
||||
int64_t sizeCopy = m_node.fileRead(tmp.writeData(), 1, _stop-_start);
|
||||
int64_t sizeCopy = m_file->read(tmp.writeData(), 1, _stop-_start);
|
||||
if (m_size <= _stop) {
|
||||
m_node.fileClose();
|
||||
m_file->close();
|
||||
}
|
||||
// TODO : Check if copy is correct ...
|
||||
return etk::move(tmp);
|
||||
@ -154,12 +150,12 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
|
||||
}
|
||||
}
|
||||
|
||||
etk::String zeus::storeInFile(zeus::ProxyFile _file, etk::String _filename) {
|
||||
etk::String zeus::storeInFile(zeus::ProxyFile _file, etk::Uri _uri) {
|
||||
zeus::ActionNotification<etk::String> tmp;
|
||||
return zeus::storeInFileNotify(_file, _filename, tmp);
|
||||
return zeus::storeInFileNotify(_file, _uri, tmp);
|
||||
}
|
||||
|
||||
etk::String zeus::storeInFileNotify(zeus::ProxyFile _file, etk::String _filename, zeus::ActionNotification<etk::String> _notification) {
|
||||
etk::String zeus::storeInFileNotify(zeus::ProxyFile _file, etk::Uri _uri, zeus::ActionNotification<etk::String> _notification) {
|
||||
auto futSize = _file.getSize();
|
||||
auto futSha = _file.getSha512();
|
||||
futSize.wait();
|
||||
@ -167,8 +163,8 @@ etk::String zeus::storeInFileNotify(zeus::ProxyFile _file, etk::String _filename
|
||||
int64_t offset = 0;
|
||||
|
||||
algue::Sha512 shaCtx;
|
||||
etk::FSNode nodeFile(_filename);
|
||||
nodeFile.fileOpenWrite();
|
||||
ememory::SharedPtr<etk::io::Interface> file = etk::uri::get(_uri);
|
||||
file->open(etk::io::OpenMode::Write);
|
||||
while (retSize > 0) {
|
||||
// get by batch of 1 MB
|
||||
int32_t nbElement = 1*1024*1024;
|
||||
@ -182,13 +178,13 @@ etk::String zeus::storeInFileNotify(zeus::ProxyFile _file, etk::String _filename
|
||||
}
|
||||
zeus::Raw buffer = futData.get();
|
||||
shaCtx.update(buffer.data(), buffer.size());
|
||||
nodeFile.fileWrite(buffer.data(), 1, buffer.size());
|
||||
file->write(buffer.data(), 1, buffer.size());
|
||||
offset += nbElement;
|
||||
retSize -= nbElement;
|
||||
ZEUS_VERBOSE("read: " << offset << "/" << futSize.get() << " " << buffer.size());
|
||||
_notification.notify("{\"pourcent\":" + etk::toString(float(offset)/float(buffer.size())) + ", \"comment\":\"download\"");
|
||||
}
|
||||
nodeFile.fileClose();
|
||||
file->close();
|
||||
// get the final sha512 of the file:
|
||||
etk::String sha512String = algue::stringConvert(shaCtx.finalize());
|
||||
futSha.wait();
|
||||
|
@ -6,13 +6,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <zeus/File.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
#include <etk/io/File.hpp>
|
||||
|
||||
namespace zeus {
|
||||
class FileImpl : public zeus::File {
|
||||
private:
|
||||
etk::String m_filename; //!< Name of the file
|
||||
etk::FSNode m_node; //!< File node access
|
||||
ememory::SharedPtr<etk::io::Interface> m_file; //!< File node access
|
||||
etk::Vector<uint8_t> m_data; //!< data of the file to transfer;
|
||||
bool m_dataRaw = false;
|
||||
size_t m_size; //!< Size of the file
|
||||
@ -20,8 +21,8 @@ namespace zeus {
|
||||
etk::String m_mineType; //!< Mine Type of the file
|
||||
etk::String m_sha512; //!< Global file sha-512
|
||||
public:
|
||||
FileImpl(etk::String _fileNameReal, etk::String _fileNameShow, etk::String _mineType, etk::String _sha512="");
|
||||
FileImpl(etk::String _fileNameReal, etk::String _sha512="");
|
||||
FileImpl(etk::Uri _fileNameReal, etk::String _fileNameShow, etk::String _mineType, etk::String _sha512="");
|
||||
FileImpl(etk::Uri _fileNameReal, etk::String _sha512="");
|
||||
FileImpl(etk::Vector<uint8_t> _value, etk::String _virtualName, etk::String _mineType);
|
||||
~FileImpl();
|
||||
uint64_t getSize() override;
|
||||
|
@ -9,24 +9,24 @@
|
||||
|
||||
#brief:Factory to create a local object.
|
||||
#param:fileName:Name of the local file to instanciate.
|
||||
[factory] create(string)
|
||||
[factory] create(uri)
|
||||
#brief:Factory to create a local object.
|
||||
#param:fileName:Name of the local file to instanciate.
|
||||
#param:sha512: Sha-512 string if the file
|
||||
[factory] create(string, string)
|
||||
[factory] create(uri, string)
|
||||
#brief:Factory to create a local object.
|
||||
#param:fileNameReal:Name of the local file to instanciate.
|
||||
#param:fileNameShow:Name of the file like the remote user will se it.
|
||||
#param:mineType:Mine-type of the file.
|
||||
[factory] create(string, string, string)
|
||||
[factory] create(uri, string, string)
|
||||
#brief:Factory to create a local object.
|
||||
#param:fileNameReal:Name of the local file to instanciate.
|
||||
#param:fileNameShow:Name of the file like the remote user will se it.
|
||||
#param:mineType:Mine-type of the file.
|
||||
#param:sha512: Sha-512 string if the file
|
||||
[factory] create(string, string, string, string)
|
||||
[factory] create(uri, string, string, string)
|
||||
#brief:Factory to create a local object with a buffer with data like a file.
|
||||
#param:buffer:Data bueffer of the data.
|
||||
#param:buffer:Data buffer of the data.
|
||||
#param:virtualName:Virtual name of the file.
|
||||
#param:mineType:Mine-type of the file.
|
||||
[factory] create(vector:uint8, string, string)
|
||||
@ -65,7 +65,7 @@ raw getPart(uint64, uint64)
|
||||
#param:file:Handle on the file.
|
||||
#param:filename:Local filename.
|
||||
#return:the sha512 of the file (calculated with the input stream.
|
||||
[tool-remote] string storeInFile(obj:zeus-File, string)
|
||||
[tool-remote] string storeInFile(obj:zeus-File, uri)
|
||||
|
||||
#brief:Store all the data in a specific vector of data.
|
||||
#param:file:Handle on the file.
|
||||
@ -77,5 +77,5 @@ raw getPart(uint64, uint64)
|
||||
#param:filename:Local filename.
|
||||
#param:notif:Local filename.
|
||||
#return:the sha512 of the file (calculated with the input stream.
|
||||
[tool-remote] string storeInFileNotify(obj:zeus-File, string, ActionNotif)
|
||||
[tool-remote] string storeInFileNotify(obj:zeus-File, uri, ActionNotif)
|
||||
|
||||
|
@ -8,17 +8,24 @@
|
||||
#include <zeus/ProxyFile.hpp>
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <algue/sha512.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
#include "debug.hpp"
|
||||
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(zeus::MediaImpl);
|
||||
|
||||
ememory::SharedPtr<zeus::Media> zeus::Media::create(etk::String _fileNameReal) {
|
||||
return ememory::makeShared<zeus::MediaImpl>(0, _fileNameReal);
|
||||
ememory::SharedPtr<zeus::Media> zeus::Media::create(etk::String _fileName) {
|
||||
return zeus::Media::create(etk::Uri("file:///" + _fileName));
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::Media> zeus::Media::create(etk::Path _path) {
|
||||
return zeus::Media::create(etk::Uri("file:///" + _path.getString()));
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::Media> zeus::Media::create(etk::Uri _uri) {
|
||||
return ememory::makeShared<zeus::MediaImpl>(0, _uri);
|
||||
}
|
||||
ejson::Object zeus::MediaImpl::getJson() {
|
||||
ejson::Object out;
|
||||
out.add("id", ejson::Number(m_id));
|
||||
@ -33,7 +40,7 @@ ejson::Object zeus::MediaImpl::getJson() {
|
||||
return out;
|
||||
}
|
||||
|
||||
zeus::MediaImpl::MediaImpl(const etk::String& _basePath, ejson::Object _property) :
|
||||
zeus::MediaImpl::MediaImpl(const etk::Uri& _basePath, ejson::Object _property) :
|
||||
m_basePath(_basePath) {
|
||||
ZEUS_ERROR(" ==============>>>>>>>>>>>>>> CREATE MEDIA");
|
||||
m_id = _property["id"].toNumber().getU64();
|
||||
@ -54,17 +61,13 @@ uint64_t zeus::MediaImpl::getUniqueId() {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
zeus::MediaImpl::MediaImpl(uint64_t _id, const etk::String& _fileNameReal, const etk::String& _basePath):
|
||||
zeus::MediaImpl::MediaImpl(uint64_t _id, const etk::Uri& _basePath, const etk::String& _fileNameReal):
|
||||
m_id(_id),
|
||||
m_basePath(_basePath),
|
||||
m_fileName(_fileNameReal) {
|
||||
ZEUS_ERROR(" ==============>>>>>>>>>>>>>> CREATE MEDIA");
|
||||
etk::String extention;
|
||||
if ( m_fileName.rfind('.') != etk::String::npos
|
||||
&& m_fileName.rfind('.') != 0) {
|
||||
extention = etk::toLower(etk::String(m_fileName.begin()+m_fileName.rfind('.')+1, m_fileName.end()));
|
||||
m_fileName = etk::String(m_fileName.begin(), m_fileName.begin()+m_fileName.rfind('.'));
|
||||
}
|
||||
etk::String extention = etk::toLower(m_basePath.getPath().getExtention());
|
||||
m_fileName = m_basePath.getPath().getFileName();
|
||||
if (extention != "") {
|
||||
setMetadata("mime-type", zeus::getMineType(extention));
|
||||
//m_creationData = echrono::Time::now();
|
||||
@ -73,7 +76,7 @@ zeus::MediaImpl::MediaImpl(uint64_t _id, const etk::String& _fileNameReal, const
|
||||
|
||||
zeus::MediaImpl::~MediaImpl() {
|
||||
ZEUS_ERROR(" <<<<<<<<<<<<<<============== DESTROY MEDIA");
|
||||
|
||||
|
||||
}
|
||||
|
||||
etk::String zeus::MediaImpl::getMineType() {
|
||||
@ -90,9 +93,9 @@ etk::String zeus::MediaImpl::getSha512() {
|
||||
etk::String sha512;
|
||||
auto it = m_metadata.find("mime-type");
|
||||
if (it != m_metadata.end()) {
|
||||
sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_basePath + m_fileName + "." + zeus::getExtention(it->second)));
|
||||
sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_basePath / (m_fileName + "." + zeus::getExtention(it->second))));
|
||||
} else {
|
||||
sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_basePath + m_fileName));
|
||||
sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_basePath / m_fileName));
|
||||
}
|
||||
setMetadata("sha512", sha512);
|
||||
return sha512;
|
||||
@ -123,10 +126,10 @@ etk::String zeus::MediaImpl::getDecoratedName() {
|
||||
ememory::SharedPtr<zeus::File> zeus::MediaImpl::getFile() {
|
||||
auto it = m_metadata.find("mime-type");
|
||||
if (it != m_metadata.end()) {
|
||||
return zeus::File::create(m_basePath + m_fileName + "." + zeus::getExtention(it->second), "", it->second, getSha512());
|
||||
return zeus::File::create(m_basePath / (m_fileName + "." + zeus::getExtention(it->second)), "", it->second, getSha512());
|
||||
}
|
||||
// no mimetype specify ... ==> theoric impossible case ...
|
||||
return zeus::File::create(m_basePath + m_fileName, "", "");
|
||||
return zeus::File::create(m_basePath / m_fileName, "", "");
|
||||
}
|
||||
|
||||
etk::Vector<etk::String> zeus::MediaImpl::getMetadataKeys() {
|
||||
@ -170,26 +173,26 @@ void zeus::MediaImpl::setMetadata(etk::String _key, etk::String _value) {
|
||||
bool zeus::MediaImpl::erase() {
|
||||
auto it = m_metadata.find("mime-type");
|
||||
if (it != m_metadata.end()) {
|
||||
return etk::FSNodeRemove(m_basePath + m_fileName + "." + zeus::getExtention(it->second));
|
||||
return etk::uri::remove(m_basePath / (m_fileName + "." + zeus::getExtention(it->second)));
|
||||
}
|
||||
return etk::FSNodeRemove(m_basePath + m_fileName);
|
||||
return etk::uri::remove(m_basePath / m_fileName);
|
||||
}
|
||||
|
||||
bool zeus::MediaImpl::move(const etk::String& _newOffsetFile) {
|
||||
ZEUS_INFO("move file : '" << m_basePath + m_fileName << "' ==> " << m_basePath + _newOffsetFile << "'");
|
||||
ZEUS_INFO("move file : '" << m_basePath / m_fileName << "' ==> " << m_basePath / _newOffsetFile << "'");
|
||||
if (_newOffsetFile == m_fileName) {
|
||||
// nothing to do ...
|
||||
return true;
|
||||
}
|
||||
auto it = m_metadata.find("mime-type");
|
||||
if (it != m_metadata.end()) {
|
||||
bool ret = etk::FSNodeMove(m_basePath + m_fileName + "." + zeus::getExtention(it->second), m_basePath + _newOffsetFile + "." + zeus::getExtention(it->second));
|
||||
bool ret = etk::uri::move(m_basePath / m_fileName + "." + zeus::getExtention(it->second), m_basePath / (_newOffsetFile + "." + zeus::getExtention(it->second)));
|
||||
if (ret == true) {
|
||||
m_fileName = _newOffsetFile;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
bool ret = etk::FSNodeMove(m_basePath + m_fileName, m_basePath + _newOffsetFile);
|
||||
bool ret = etk::uri::move(m_basePath / m_fileName, m_basePath / _newOffsetFile);
|
||||
if (ret == true) {
|
||||
m_fileName = _newOffsetFile;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <zeus/Media.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <echrono/Time.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
|
||||
@ -14,7 +13,7 @@ namespace zeus {
|
||||
class MediaImpl : public zeus::Media {
|
||||
private:
|
||||
uint64_t m_id; //!< use local reference ID to have faster access on the file ...
|
||||
etk::String m_basePath; //!< basic global path
|
||||
etk::Uri m_basePath; //!< basic global path
|
||||
etk::String m_fileName; //!< Name of the file
|
||||
etk::Map<etk::String, etk::String> m_metadata; //!< all extra property
|
||||
etk::Function<void(zeus::MediaImpl*, const etk::String& )> m_callback;
|
||||
@ -26,11 +25,11 @@ namespace zeus {
|
||||
/**
|
||||
* @brief Generic json constructor
|
||||
*/
|
||||
MediaImpl(const etk::String& _basePath, ejson::Object _property);
|
||||
MediaImpl(const etk::Uri& _basePath, ejson::Object _property);
|
||||
/**
|
||||
* @brief Generic file constructor
|
||||
*/
|
||||
MediaImpl(uint64_t _id, const etk::String& _fileNameReal, const etk::String& _basePath="");
|
||||
MediaImpl(uint64_t _id, const etk::Uri& _basePath, const etk::String& _fileNameReal = "");
|
||||
/**
|
||||
* @brief Generic destructor
|
||||
*/
|
||||
|
@ -13,6 +13,14 @@ import zeus-File
|
||||
#param:fileName:Name of the local file to instanciate.
|
||||
[factory] create(string)
|
||||
|
||||
#brief:Factory to create a local object.
|
||||
#param:path:Name of the file path to instanciate.
|
||||
[factory] create(path)
|
||||
|
||||
#brief:Factory to create a local object.
|
||||
#param:uri:Name of the file uri to instanciate.
|
||||
[factory] create(uri)
|
||||
|
||||
#brief:Get the book unique Id of the server+user
|
||||
#return:The UID requested
|
||||
uint64 getUniqueId()
|
||||
|
Loading…
x
Reference in New Issue
Block a user