This commit is contained in:
UnknownObject
2026-06-30 17:49:51 +08:00
commit 292c09619e
200 changed files with 23718 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
#include <random>
#ifndef _WIN32
#include "UOHash.h"
#else
#include "../UOHash/UOHash.h"
#endif
#include "WebFileInfo.h"
std::string WebFileInfo::GetRandomNumber()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(123456789, 987654321);
return std::to_string(dis(gen));
}
std::string WebFileInfo::GetExtension(std::string ofn)
{
size_t pos = ofn.rfind('.');
if (pos == -1)
return "";
else
return ofn.substr(pos);
}
std::string WebFileInfo::GenerateStorageName(std::string ofn)
{
uns::HashResult result = uns::UOHash::HashString(uns::HashID::CRC32C, ofn);
std::string timestr = UploadTime.Format("UPLOAD-%Y%m%d%H%M%S-");
uns::HashResult random = uns::UOHash::HashString(uns::HashID::CRC32C, GetRandomNumber());
return timestr + std::string(result) + "-" + std::string(random) + ".unsctmp";
}
WebFileInfo::WebFileInfo(std::string ofn, size_t size)
{
OriginalFileName = ofn;
FileSize = size;
UploadTime = DateTime::Now();
StorageFileName = GenerateStorageName(ofn);
ExtensionName = GetExtension(ofn);
}
WebFileInfo::WebFileInfo(std::string ofn, std::string sfn, std::string en, DateTime upt, size_t siz)
{
OriginalFileName = ofn;
StorageFileName = sfn;
ExtensionName = en;
UploadTime = upt;
FileSize = siz;
}
WebFileInfo::WebFileInfo(const WebFileInfo& obj)
{
OriginalFileName = obj.OriginalFileName;
StorageFileName = obj.StorageFileName;
ExtensionName = obj.ExtensionName;
UploadTime = obj.UploadTime;
FileSize = obj.FileSize;
}
std::string WebFileInfo::MakePath(std::string storage_dir) const
{
if (storage_dir[storage_dir.size() - 1] == '/')
return storage_dir + StorageFileName;
else
return storage_dir + "/" + StorageFileName;
}
std::string WebFileInfo::GetOriginalFileName() const
{
return OriginalFileName;
}
std::string WebFileInfo::GetStorageFileName() const
{
return StorageFileName;
}
std::string WebFileInfo::GetExtensionName() const
{
return ExtensionName;
}
DateTime WebFileInfo::GetUploadTime() const
{
return UploadTime;
}
size_t WebFileInfo::GetFileSize() const
{
return FileSize;
}