Not working yet.
This commit is contained in:
@@ -6,7 +6,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Find required packages
|
||||
find_package(SQLite3 REQUIRED)
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
# Find all source files in src directory
|
||||
file(GLOB_RECURSE SOURCES
|
||||
@@ -30,7 +29,6 @@ add_executable(simple_object_storage ${SOURCES})
|
||||
# Link libraries
|
||||
target_link_libraries(simple_object_storage
|
||||
SQLite::SQLite3
|
||||
ZLIB::ZLIB
|
||||
)
|
||||
|
||||
# Install target
|
||||
|
@@ -21,7 +21,7 @@ Write access is controlled by tokens.
|
||||
- `curl http://localhost:8123/meta/squashkiwi:latest`
|
||||
- a simple welcome page is served at `/index.html` for those browsing to the site.
|
||||
- to upload a file (via http put)
|
||||
- `curl -T object_file http://dtr.jde.nz/WRITE_TOKEN/LABEL:TAG`
|
||||
- `curl -T object_file http://localhost:8123/WRITE_TOKEN/LABEL:TAG`
|
||||
- the object_file is uploaded, hashed, added to the registry (if that hash doesn't already exist), and {label:tag,hash} is added to the directory index.
|
||||
- the server is configured via a configuration file which allows setting:
|
||||
- the list of write access tokens
|
||||
|
@@ -14,42 +14,6 @@
|
||||
|
||||
namespace simple_object_storage {
|
||||
|
||||
std::string decompress_gzip(const std::string& file_path) {
|
||||
std::ifstream file(file_path, std::ios::binary);
|
||||
if (!file) return {};
|
||||
|
||||
std::vector<char> compressed((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
if (compressed.size() < 2) return {};
|
||||
|
||||
// Skip gzip header (10 bytes)
|
||||
size_t pos = 10;
|
||||
if (compressed.size() <= pos) return {};
|
||||
|
||||
// Prepare zlib stream
|
||||
z_stream strm = {};
|
||||
strm.next_in = reinterpret_cast<Bytef*>(compressed.data() + pos);
|
||||
strm.avail_in = compressed.size() - pos;
|
||||
|
||||
if (inflateInit2(&strm, 16 + MAX_WBITS) != Z_OK) return {};
|
||||
|
||||
std::string out;
|
||||
char buffer[4096];
|
||||
int ret;
|
||||
do {
|
||||
strm.next_out = reinterpret_cast<Bytef*>(buffer);
|
||||
strm.avail_out = sizeof(buffer);
|
||||
ret = inflate(&strm, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) {
|
||||
inflateEnd(&strm);
|
||||
return {};
|
||||
}
|
||||
out.append(buffer, sizeof(buffer) - strm.avail_out);
|
||||
} while (ret != Z_STREAM_END);
|
||||
|
||||
inflateEnd(&strm);
|
||||
return out;
|
||||
}
|
||||
|
||||
// if the file is a tgz file (we can't rely on the extension), then unpack on disk and has the contents
|
||||
// with hash_directory_recursive in hash.hpp
|
||||
uint64_t get_hash_from_tgz(const std::string &file_path)
|
||||
@@ -66,10 +30,8 @@ uint64_t get_hash_from_tgz(const std::string &file_path)
|
||||
TempDirectory temp_dir_manager("tgz_unpack_"); // Creates dir and schedules cleanup
|
||||
std::string temp_dir = temp_dir_manager.string(); // Get the path string to use
|
||||
|
||||
std::string decompressed = decompress_gzip(file_path);
|
||||
|
||||
// unpack the file on disk
|
||||
std::string command = "tar -xzf " + file_path + " -C " + temp_dir;
|
||||
std::string command = "tar -zxzf " + file_path + " -C " + temp_dir;
|
||||
int result = system(command.c_str()); // Basic tar extraction - requires 'tar' command
|
||||
if (result != 0) {
|
||||
std::cerr << "Error unpacking tgz file: " << file_path << std::endl;
|
||||
|
@@ -4,8 +4,6 @@
|
||||
|
||||
namespace simple_object_storage {
|
||||
|
||||
std::string decompress_gzip(const std::string& file_path);
|
||||
|
||||
uint64_t get_hash_from_tgz(const std::string& file_path);
|
||||
|
||||
} // namespace simple_object_storage
|
@@ -88,7 +88,6 @@ bool Server::start() {
|
||||
}
|
||||
setup_routes();
|
||||
|
||||
std::cout << "Server starting on " << config_.host << ":" << config_.port << std::endl;
|
||||
running_ = true;
|
||||
if (!server_.listen(config_.host.c_str(), config_.port)) {
|
||||
running_ = false;
|
||||
@@ -287,7 +286,7 @@ void Server::handle_put_object(const httplib::Request& req, httplib::Response& r
|
||||
dbEntry entry;
|
||||
entry.label_tag = label_tag;
|
||||
entry.hash = hash_str;
|
||||
entry.metadata = nlohmann::json::object(); // Empty metadata for now
|
||||
entry.metadata = metadata; // Empty metadata for now
|
||||
|
||||
if (!db_->insert(entry)) {
|
||||
res.status = 500;
|
||||
|
Reference in New Issue
Block a user