[DEV] better interface for file sha512
This commit is contained in:
parent
6e0d0e2ffc
commit
958060692c
@ -60,7 +60,7 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map<
|
||||
APPL_ERROR("Sot send file : " << _path << " Not manage extention...");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Do it better ==> add the calback to know the push progression ...
|
||||
uint32_t mediaId = _srv.add(zeus::File::create(_path)).waitFor(echrono::seconds(20000)).get();
|
||||
if (mediaId == 0) {
|
||||
APPL_ERROR("Get media ID = 0 With no error");
|
||||
|
@ -19,11 +19,15 @@ ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal) {
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _fileNameShow, _mineType);
|
||||
}
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType, std::string _sha512) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _fileNameShow, _mineType, _sha512);
|
||||
}
|
||||
|
||||
zeus::FileImpl::FileImpl(std::string _fileNameReal) :
|
||||
zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _sha512) :
|
||||
m_filename(_fileNameReal),
|
||||
m_node(_fileNameReal),
|
||||
m_gettedData(0) {
|
||||
m_gettedData(0),
|
||||
m_sha512(_sha512) {
|
||||
m_size = m_node.fileSize();
|
||||
m_node.fileOpenRead();
|
||||
std::string extention;
|
||||
@ -32,17 +36,28 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal) :
|
||||
extention = std::string(_fileNameReal.begin()+_fileNameReal.rfind('.')+1, _fileNameReal.end());
|
||||
}
|
||||
m_mineType = zeus::getMineType(extention);
|
||||
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(_fileNameReal));
|
||||
if ( _sha512.size() > 0
|
||||
&& _sha512.size() != 128) {
|
||||
ZEUS_ERROR("Set a wrong sha512 file type");
|
||||
_sha512.clear();
|
||||
}
|
||||
}
|
||||
|
||||
zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) :
|
||||
// sha 512 example: 6134b4a4b5b116cf1b1b757c5aa48bd8b3482b86c6d3fee389a0a3232f74e7331e5f8af6ad516d2ca92eda0a475f44e1291618562ce6f9e54634ba052650dcd7
|
||||
// 000000000100000000020000000003000000000400000000050000000006000000000700000000080000000009000000000A000000000B000000000C00000000
|
||||
zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType, std::string _sha512) :
|
||||
m_filename(_fileNameShow),
|
||||
m_node(_fileNameReal),
|
||||
m_gettedData(0),
|
||||
m_mineType(_mineType) {
|
||||
m_mineType(_mineType),
|
||||
m_sha512(_sha512) {
|
||||
m_size = m_node.fileSize();
|
||||
m_node.fileOpenRead();
|
||||
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(_fileNameReal));
|
||||
if ( _sha512.size() > 0
|
||||
&& _sha512.size() != 128) {
|
||||
ZEUS_ERROR("Set a wrong sha512 file type");
|
||||
_sha512.clear();
|
||||
}
|
||||
}
|
||||
|
||||
zeus::FileImpl::~FileImpl() {
|
||||
@ -58,6 +73,11 @@ std::string zeus::FileImpl::getName() {
|
||||
}
|
||||
|
||||
std::string zeus::FileImpl::getSha512() {
|
||||
if (m_sha512 == "") {
|
||||
ZEUS_INFO("calculation of sha 512 (start)");
|
||||
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(m_node.getFileSystemName()));
|
||||
ZEUS_INFO("calculation of sha 512 (stop)");
|
||||
}
|
||||
return m_sha512;
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ namespace zeus {
|
||||
std::string m_mineType; //!< Mine Type of the file
|
||||
std::string m_sha512; //!< Global file sha-512
|
||||
public:
|
||||
FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType);
|
||||
FileImpl(std::string _fileNameReal);
|
||||
FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType, std::string _sha512="");
|
||||
FileImpl(std::string _fileNameReal, std::string _sha512="");
|
||||
~FileImpl();
|
||||
uint64_t getSize() override;
|
||||
std::string getName() override;
|
||||
|
@ -15,6 +15,12 @@
|
||||
#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)
|
||||
#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)
|
||||
|
||||
// --------------------------
|
||||
// -- Members --
|
||||
|
Loading…
x
Reference in New Issue
Block a user